From 060f24e7c51c589db445ca0988f50ebb6a7dd44b Mon Sep 17 00:00:00 2001 From: Akshay Khairmode Date: Fri, 6 Feb 2026 12:01:12 +0530 Subject: [PATCH] Add MGet method to cachecompat --- rueidiscompat/adapter.go | 6 ++++++ rueidiscompat/adapter_test.go | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/rueidiscompat/adapter.go b/rueidiscompat/adapter.go index 6c32f43f..3b3cff55 100644 --- a/rueidiscompat/adapter.go +++ b/rueidiscompat/adapter.go @@ -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) diff --git a/rueidiscompat/adapter_test.go b/rueidiscompat/adapter_test.go index 16d2f73f..74d3d7a5 100644 --- a/rueidiscompat/adapter_test.go +++ b/rueidiscompat/adapter_test.go @@ -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() { @@ -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())