Skip to content

Commit 6fc4787

Browse files
Unify CacheCompat to use value receivers. (#120)
* fix: #111 valkeycompat JSONGet is incompatible with go-redis #112 The functions TxPipeline, TxPipelined, Pipeline, Pipelined, valkeycompay are incompatible with Go-Redis Signed-off-by: piyongcai <piyongcai@163.com> * fix: Codecov Report suggest Signed-off-by: piyongcai <piyongcai@163.com> * add testing for #111 #112 Signed-off-by: piyongcai <piyongcai@163.com> * fixed testing code. Signed-off-by: piyongcai <piyongcai@163.com> * change JSONSet -> JSONGet for fix #116 testing code. Signed-off-by: piyongcai <piyongcai@163.com> * Refer to the modification suggestions and simplify the error handling code. Signed-off-by: piyongcai <piyongcai@163.com> * Restrict tests to resp3 mode to avoid failures. Signed-off-by: piyongcai <piyongcai@163.com> * Unify CacheCompat to use pointer receivers. Signed-off-by: piyongcai <piyongcai@163.com> * Apply suggestions from code review Signed-off-by: Rueian <rueiancsie@gmail.com> * unify to use value receivers. Signed-off-by: piyongcai <piyongcai@163.com> --------- Signed-off-by: piyongcai <piyongcai@163.com> Signed-off-by: Rueian <rueiancsie@gmail.com> Co-authored-by: Rueian <rueiancsie@gmail.com> Signed-off-by: Rueian <rueiancsie@gmail.com>
1 parent 9969554 commit 6fc4787

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

rueidiscompat/adapter.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ func (c *Compat) ExpireAt(ctx context.Context, key string, timestamp time.Time)
770770
resp := c.client.Do(ctx, cmd)
771771
return newBoolCmd(resp)
772772
}
773+
773774
func (c *Compat) ExpireTime(ctx context.Context, key string) *DurationCmd {
774775
cmd := c.client.B().Expiretime().Key(key).Build()
775776
resp := c.client.Do(ctx, cmd)
@@ -844,6 +845,7 @@ func (c *Compat) ObjectIdleTime(ctx context.Context, key string) *DurationCmd {
844845
resp := c.client.Do(ctx, cmd)
845846
return newDurationCmd(resp, time.Second)
846847
}
848+
847849
func (c *Compat) Persist(ctx context.Context, key string) *BoolCmd {
848850
cmd := c.client.B().Persist().Key(key).Build()
849851
resp := c.client.Do(ctx, cmd)
@@ -2233,7 +2235,8 @@ func (c *Compat) XAutoClaimJustID(ctx context.Context, a XAutoClaimArgs) *XAutoC
22332235
//
22342236
// The redis-server version is lower than 6.2, please set the limit to 0.
22352237
func (c *Compat) xTrim(ctx context.Context, key, strategy string,
2236-
approx bool, threshold string, limit int64) *IntCmd {
2238+
approx bool, threshold string, limit int64,
2239+
) *IntCmd {
22372240
cmd := c.client.B().Arbitrary("XTRIM").Keys(key).Args(strategy)
22382241
if approx {
22392242
cmd = cmd.Args("~")
@@ -2620,6 +2623,7 @@ func (c *Compat) ZRemRangeByRank(ctx context.Context, key string, start, stop in
26202623
resp := c.client.Do(ctx, cmd)
26212624
return newIntCmd(resp)
26222625
}
2626+
26232627
func (c *Compat) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd {
26242628
cmd := c.client.B().Zremrangebyscore().Key(key).Min(min).Max(max).Build()
26252629
resp := c.client.Do(ctx, cmd)
@@ -3747,6 +3751,7 @@ func (c *Compat) CFAdd(ctx context.Context, key string, element interface{}) *Bo
37473751
cmd := c.client.B().CfAdd().Key(key).Item(str(element)).Build()
37483752
return newBoolCmd(c.client.Do(ctx, cmd))
37493753
}
3754+
37503755
func (c *Compat) CFAddNX(ctx context.Context, key string, element interface{}) *BoolCmd {
37513756
cmd := c.client.B().CfAddnx().Key(key).Item(str(element)).Build()
37523757
return newBoolCmd(c.client.Do(ctx, cmd))
@@ -4020,8 +4025,8 @@ func (c *Compat) TDigestCDF(ctx context.Context, key string, elements ...float64
40204025
func (c *Compat) TDigestCreate(ctx context.Context, key string) *StatusCmd {
40214026
cmd := c.client.B().TdigestCreate().Key(key).Build()
40224027
return newStatusCmd(c.client.Do(ctx, cmd))
4023-
40244028
}
4029+
40254030
func (c *Compat) TDigestCreateWithCompression(ctx context.Context, key string, compression int64) *StatusCmd {
40264031
cmd := c.client.B().TdigestCreate().Key(key).Compression(compression).Build()
40274032
return newStatusCmd(c.client.Do(ctx, cmd))
@@ -6468,27 +6473,27 @@ func (c CacheCompat) BFInfoExpansion(ctx context.Context, key string) *BFInfoCmd
64686473
return newBFInfoCmd(resp)
64696474
}
64706475

6471-
func (c *CacheCompat) CFCount(ctx context.Context, key string, element interface{}) *IntCmd {
6476+
func (c CacheCompat) CFCount(ctx context.Context, key string, element interface{}) *IntCmd {
64726477
cmd := c.client.B().CfCount().Key(key).Item(str(element)).Cache()
64736478
return newIntCmd(c.client.DoCache(ctx, cmd, c.ttl))
64746479
}
64756480

6476-
func (c *CacheCompat) CFExists(ctx context.Context, key string, element interface{}) *BoolCmd {
6481+
func (c CacheCompat) CFExists(ctx context.Context, key string, element interface{}) *BoolCmd {
64776482
cmd := c.client.B().CfExists().Key(key).Item(str(element)).Cache()
64786483
return newBoolCmd(c.client.DoCache(ctx, cmd, c.ttl))
64796484
}
64806485

6481-
func (c *CacheCompat) CFInfo(ctx context.Context, key string) *CFInfoCmd {
6486+
func (c CacheCompat) CFInfo(ctx context.Context, key string) *CFInfoCmd {
64826487
cmd := c.client.B().CfInfo().Key(key).Cache()
64836488
return newCFInfoCmd(c.client.DoCache(ctx, cmd, c.ttl))
64846489
}
64856490

6486-
func (c *CacheCompat) CMSInfo(ctx context.Context, key string) *CMSInfoCmd {
6491+
func (c CacheCompat) CMSInfo(ctx context.Context, key string) *CMSInfoCmd {
64876492
cmd := c.client.B().CmsInfo().Key(key).Cache()
64886493
return newCMSInfoCmd(c.client.DoCache(ctx, cmd, c.ttl))
64896494
}
64906495

6491-
func (c *CacheCompat) CMSQuery(ctx context.Context, key string, elements ...interface{}) *IntSliceCmd {
6496+
func (c CacheCompat) CMSQuery(ctx context.Context, key string, elements ...interface{}) *IntSliceCmd {
64926497
_cmd := c.client.B().CmsQuery().Key(key)
64936498
for _, e := range elements {
64946499
_cmd.Item(str(e))
@@ -6497,17 +6502,17 @@ func (c *CacheCompat) CMSQuery(ctx context.Context, key string, elements ...inte
64976502
return newIntSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
64986503
}
64996504

6500-
func (c *CacheCompat) TopKInfo(ctx context.Context, key string) *TopKInfoCmd {
6505+
func (c CacheCompat) TopKInfo(ctx context.Context, key string) *TopKInfoCmd {
65016506
cmd := c.client.B().TopkInfo().Key(key).Cache()
65026507
return newTopKInfoCmd(c.client.DoCache(ctx, cmd, c.ttl))
65036508
}
65046509

6505-
func (c *CacheCompat) TopKList(ctx context.Context, key string) *StringSliceCmd {
6510+
func (c CacheCompat) TopKList(ctx context.Context, key string) *StringSliceCmd {
65066511
cmd := c.client.B().TopkList().Key(key).Cache()
65076512
return newStringSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65086513
}
65096514

6510-
func (c *CacheCompat) TopKQuery(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd {
6515+
func (c CacheCompat) TopKQuery(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd {
65116516
_cmd := c.client.B().TopkQuery().Key(key)
65126517
for _, e := range elements {
65136518
_cmd.Item(str(e))
@@ -6516,7 +6521,7 @@ func (c *CacheCompat) TopKQuery(ctx context.Context, key string, elements ...int
65166521
return newBoolSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65176522
}
65186523

6519-
func (c *CacheCompat) JSONArrIndex(ctx context.Context, key, path string, value ...interface{}) *IntSliceCmd {
6524+
func (c CacheCompat) JSONArrIndex(ctx context.Context, key, path string, value ...interface{}) *IntSliceCmd {
65206525
_cmd := c.client.B().JsonArrindex().Key(key).Path(path)
65216526
switch len(value) {
65226527
case 1:
@@ -6535,37 +6540,37 @@ func (c *CacheCompat) JSONArrIndex(ctx context.Context, key, path string, value
65356540
return newIntSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65366541
}
65376542

6538-
func (c *CacheCompat) JSONArrLen(ctx context.Context, key, path string) *IntSliceCmd {
6543+
func (c CacheCompat) JSONArrLen(ctx context.Context, key, path string) *IntSliceCmd {
65396544
cmd := c.client.B().JsonArrlen().Key(key).Path(path).Cache()
65406545
return newIntSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65416546
}
65426547

6543-
func (c *CacheCompat) JSONGet(ctx context.Context, key string, paths ...string) *JSONCmd {
6548+
func (c CacheCompat) JSONGet(ctx context.Context, key string, paths ...string) *JSONCmd {
65446549
cmd := c.client.B().JsonGet().Key(key).Path(paths...).Cache()
65456550
return newJSONCmd(c.client.DoCache(ctx, cmd, c.ttl))
65466551
}
65476552

6548-
func (c *CacheCompat) JSONMGet(ctx context.Context, path string, keys ...string) *JSONSliceCmd {
6553+
func (c CacheCompat) JSONMGet(ctx context.Context, path string, keys ...string) *JSONSliceCmd {
65496554
cmd := c.client.B().JsonMget().Key(keys...).Path(path).Cache()
65506555
return newJSONSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65516556
}
65526557

6553-
func (c *CacheCompat) JSONObjKeys(ctx context.Context, key, path string) *SliceCmd {
6558+
func (c CacheCompat) JSONObjKeys(ctx context.Context, key, path string) *SliceCmd {
65546559
cmd := c.client.B().JsonObjkeys().Key(key).Path(path).Cache()
65556560
return newSliceCmd(c.client.DoCache(ctx, cmd, c.ttl), true)
65566561
}
65576562

6558-
func (c *CacheCompat) JSONObjLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
6563+
func (c CacheCompat) JSONObjLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
65596564
cmd := c.client.B().JsonObjlen().Key(key).Path(path).Cache()
65606565
return newIntPointerSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65616566
}
65626567

6563-
func (c *CacheCompat) JSONStrLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
6568+
func (c CacheCompat) JSONStrLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
65646569
cmd := c.client.B().JsonStrlen().Key(key).Path(path).Cache()
65656570
return newIntPointerSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65666571
}
65676572

6568-
func (c *CacheCompat) JSONType(ctx context.Context, key, path string) *JSONSliceCmd {
6573+
func (c CacheCompat) JSONType(ctx context.Context, key, path string) *JSONSliceCmd {
65696574
cmd := c.client.B().JsonType().Key(key).Path(path).Cache()
65706575
return newJSONSliceCmd(c.client.DoCache(ctx, cmd, c.ttl))
65716576
}

0 commit comments

Comments
 (0)