Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rueidiscompat/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6038,6 +6038,12 @@ func (c CacheCompat) Get(ctx context.Context, key string) *StringCmd {
return newStringCmd(resp)
}

func (c CacheCompat) MGet(ctx context.Context, keys ...string) *SliceCmd {
cmd := c.client.B().Mget().Key(keys...).Cache()
resp := c.client.DoCache(ctx, cmd, c.ttl)
return newSliceCmd(resp, false, keys...)
}

func (c CacheCompat) GetBit(ctx context.Context, key string, offset int64) *IntCmd {
cmd := c.client.B().Getbit().Key(key).Offset(offset).Cache()
resp := c.client.DoCache(ctx, cmd, c.ttl)
Expand Down
24 changes: 23 additions & 1 deletion rueidiscompat/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func testAdapter(resp3 bool) {
// if too much time (>1s) is used during command execution, it may also cause the test to fail.
// so the ObjectIdleTime result should be <=now-start+1s
// link: https://github.com/redis/redis/blob/5b48d900498c85bbf4772c1d466c214439888115/src/object.c#L1265-L1272
Expect(idleTime.Val()).To(BeNumerically("<=", time.Now().Sub(start)+time.Second))
Expect(idleTime.Val()).To(BeNumerically("<=", time.Since(start)+time.Second))
})

It("should Persist", func() {
Expand Down Expand Up @@ -7906,6 +7906,28 @@ func testAdapterCache(resp3 bool) {
Expect(get.Val()).To(Equal("hello"))
})

It("should MGet", func() {
mGet := adapter.Cache(time.Hour).MGet(ctx, "_", "key2")
Expect(mGet.Err()).NotTo(HaveOccurred())
Expect(mGet.Val()).To(Equal([]any{nil, nil}))

set := adapter.Set(ctx, "key1", "hello1", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))

set = adapter.Set(ctx, "key2", "hello2", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))

mGet = adapter.Cache(time.Hour).MGet(ctx, "key1", "key2", "_")
Expect(mGet.Err()).NotTo(HaveOccurred())
Expect(mGet.Val()).To(Equal([]any{"hello1", "hello2", nil}))

mGet = adapter.Cache(time.Hour).MGet(ctx, "key1", "_", "key2")
Expect(mGet.Err()).NotTo(HaveOccurred())
Expect(mGet.Val()).To(Equal([]any{"hello1", nil, "hello2"}))
})

It("should GetBit", func() {
setBit := adapter.SetBit(ctx, "key", 7, 1)
Expect(setBit.Err()).NotTo(HaveOccurred())
Expand Down
Loading