Skip to content

Commit 060f24e

Browse files
Add MGet method to cachecompat
1 parent 5696be8 commit 060f24e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

rueidiscompat/adapter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6038,6 +6038,12 @@ func (c CacheCompat) Get(ctx context.Context, key string) *StringCmd {
60386038
return newStringCmd(resp)
60396039
}
60406040

6041+
func (c CacheCompat) MGet(ctx context.Context, keys ...string) *SliceCmd {
6042+
cmd := c.client.B().Mget().Key(keys...).Cache()
6043+
resp := c.client.DoCache(ctx, cmd, c.ttl)
6044+
return newSliceCmd(resp, false, keys...)
6045+
}
6046+
60416047
func (c CacheCompat) GetBit(ctx context.Context, key string, offset int64) *IntCmd {
60426048
cmd := c.client.B().Getbit().Key(key).Offset(offset).Cache()
60436049
resp := c.client.DoCache(ctx, cmd, c.ttl)

rueidiscompat/adapter_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ func testAdapter(resp3 bool) {
716716
// if too much time (>1s) is used during command execution, it may also cause the test to fail.
717717
// so the ObjectIdleTime result should be <=now-start+1s
718718
// link: https://github.com/redis/redis/blob/5b48d900498c85bbf4772c1d466c214439888115/src/object.c#L1265-L1272
719-
Expect(idleTime.Val()).To(BeNumerically("<=", time.Now().Sub(start)+time.Second))
719+
Expect(idleTime.Val()).To(BeNumerically("<=", time.Since(start)+time.Second))
720720
})
721721

722722
It("should Persist", func() {
@@ -7906,6 +7906,28 @@ func testAdapterCache(resp3 bool) {
79067906
Expect(get.Val()).To(Equal("hello"))
79077907
})
79087908

7909+
It("should MGet", func() {
7910+
mGet := adapter.Cache(time.Hour).MGet(ctx, "_", "key2")
7911+
Expect(mGet.Err()).NotTo(HaveOccurred())
7912+
Expect(mGet.Val()).To(Equal([]any{nil, nil}))
7913+
7914+
set := adapter.Set(ctx, "key1", "hello1", 0)
7915+
Expect(set.Err()).NotTo(HaveOccurred())
7916+
Expect(set.Val()).To(Equal("OK"))
7917+
7918+
set = adapter.Set(ctx, "key2", "hello2", 0)
7919+
Expect(set.Err()).NotTo(HaveOccurred())
7920+
Expect(set.Val()).To(Equal("OK"))
7921+
7922+
mGet = adapter.Cache(time.Hour).MGet(ctx, "key1", "key2", "_")
7923+
Expect(mGet.Err()).NotTo(HaveOccurred())
7924+
Expect(mGet.Val()).To(Equal([]any{"hello1", "hello2", nil}))
7925+
7926+
mGet = adapter.Cache(time.Hour).MGet(ctx, "key1", "_", "key2")
7927+
Expect(mGet.Err()).NotTo(HaveOccurred())
7928+
Expect(mGet.Val()).To(Equal([]any{"hello1", nil, "hello2"}))
7929+
})
7930+
79097931
It("should GetBit", func() {
79107932
setBit := adapter.SetBit(ctx, "key", 7, 1)
79117933
Expect(setBit.Err()).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)