1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-10 11:03:00 +03:00

Add TimeCmd.

This commit is contained in:
Vladimir Mihailenco
2016-10-14 14:39:02 +03:00
parent 6f8957c5b7
commit dcdf129dd5
4 changed files with 79 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"strconv"
"time"
"gopkg.in/redis.v5/internal/proto"
)
@@ -364,6 +365,7 @@ func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {
return &cmd, nil
}
// Implements proto.MultiBulkParse
func commandInfoSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
m := make(map[string]*CommandInfo, n)
for i := int64(0); i < n; i++ {
@@ -377,3 +379,32 @@ func commandInfoSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
}
return m, nil
}
// Implements proto.MultiBulkParse
func timeParser(rd *proto.Reader, n int64) (interface{}, error) {
if n != 2 {
fmt.Errorf("got %d elements, expected 2", n)
}
secStr, err := rd.ReadStringReply()
if err != nil {
return nil, err
}
microsecStr, err := rd.ReadStringReply()
if err != nil {
return nil, err
}
sec, err := strconv.ParseInt(secStr, 10, 64)
if err != nil {
return nil, err
}
microsec, err := strconv.ParseInt(microsecStr, 10, 64)
if err != nil {
return nil, err
}
return time.Unix(sec, microsec*100), nil
}