1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

v2: use time package primitives where possible.

This commit is contained in:
Vladimir Mihailenco
2013-10-15 16:47:12 +03:00
parent 054c21e571
commit eaf97f5a30
4 changed files with 83 additions and 45 deletions

View File

@ -156,6 +156,39 @@ func (cmd *IntCmd) Val() int64 {
//------------------------------------------------------------------------------
type DurationCmd struct {
*baseCmd
precision time.Duration
}
func NewDurationCmd(precision time.Duration, args ...string) *DurationCmd {
return &DurationCmd{
baseCmd: newBaseCmd(args...),
precision: precision,
}
}
func (cmd *DurationCmd) parseReply(rd reader) (interface{}, error) {
v, err := parseReply(rd)
if err != nil {
return 0, err
}
vv := time.Duration(v.(int64))
if vv == -1 {
return vv, nil
}
return vv * cmd.precision, nil
}
func (cmd *DurationCmd) Val() time.Duration {
if cmd.val == nil {
return 0
}
return cmd.val.(time.Duration)
}
//------------------------------------------------------------------------------
type BoolCmd struct {
*baseCmd
}