diff --git a/tair/taircommands.go b/tair/taircommands.go index b9a88c0..d2018d3 100644 --- a/tair/taircommands.go +++ b/tair/taircommands.go @@ -160,3 +160,17 @@ type TairCmdable interface { BfInsert(ctx context.Context, key string, bfInsertArgs *BfInsertArgs, items ...string) *redis.BoolSliceCmd BfDebug(ctx context.Context, key string) *redis.StringSliceCmd } + +func toMs(dur time.Duration) int64 { + if dur > 0 && dur < time.Millisecond { + return 1 + } + return int64(dur / time.Millisecond) +} + +func toSec(dur time.Duration) int64 { + if dur > 0 && dur < time.Second { + return 1 + } + return int64(dur / time.Second) +} diff --git a/tair/taircpc.go b/tair/taircpc.go index 48c974d..ee1c5f0 100644 --- a/tair/taircpc.go +++ b/tair/taircpc.go @@ -2,9 +2,10 @@ package tair import ( "context" - "github.com/go-redis/redis/v8" "strconv" "time" + + "github.com/go-redis/redis/v8" ) type CpcData struct { @@ -164,10 +165,10 @@ func (a *CpcUpdateArgs) GetArgs() []interface{} { args = append(args, PXAT, a.pxAt.Unix()) } if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[WIN]; ok { args = append(args, WIN, a.winSize) diff --git a/tair/tairhash.go b/tair/tairhash.go index f5a7fd9..4beb560 100644 --- a/tair/tairhash.go +++ b/tair/tairhash.go @@ -2,8 +2,9 @@ package tair import ( "context" - "github.com/go-redis/redis/v8" "time" + + "github.com/go-redis/redis/v8" ) type ExHSetArgs struct { @@ -79,10 +80,10 @@ func (a *ExHSetArgs) GetArgs() []interface{} { args = append(args, NX) } if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[EXAT]; ok { args = append(args, EXAT, a.exAt.Unix()) @@ -224,10 +225,10 @@ func (a *ExHIncrArgs) KeepTTL() *ExHIncrArgs { func (a ExHIncrArgs) GetArgs() []interface{} { args := make([]interface{}, 0) if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[EXAT]; ok { args = append(args, EXAT, a.exAt.Unix()) diff --git a/tair/tairstring.go b/tair/tairstring.go index baa07e8..a1b4319 100644 --- a/tair/tairstring.go +++ b/tair/tairstring.go @@ -2,8 +2,9 @@ package tair import ( "context" - "github.com/go-redis/redis/v8" "time" + + "github.com/go-redis/redis/v8" ) type ExSetArgs struct { @@ -96,10 +97,10 @@ func (a *ExSetArgs) GetArgs() []interface{} { args = append(args, NX) } if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[EXAT]; ok { args = append(args, EXAT, a.exAt.Unix()) @@ -176,10 +177,10 @@ func (a *CasArgs) GetArgs() []interface{} { args = append(args, PXAT, a.pxAt.Unix()) } if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[KEEPTTL]; ok { args = append(args, KEEPTTL) @@ -297,10 +298,10 @@ func (a ExIncrByArgs) GetArgs() []interface{} { args = append(args, NX) } if _, ok := a.Set[EX]; ok { - args = append(args, EX, a.ex) + args = append(args, EX, toSec(a.ex)) } if _, ok := a.Set[PX]; ok { - args = append(args, PX, a.px) + args = append(args, PX, toMs(a.px)) } if _, ok := a.Set[EXAT]; ok { args = append(args, EXAT, a.exAt.Unix())