From f36093a0beb024b782b47584b63aa87e1e01e6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D0=BE=D0=B2=D1=81=D0=BA=D0=B8=D0=B9?= Date: Mon, 20 Sep 2021 16:37:40 -0400 Subject: [PATCH] Add support for BLMove command --- commands.go | 8 ++++++++ commands_test.go | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/commands.go b/commands.go index 80b2bab9..c1514d4a 100644 --- a/commands.go +++ b/commands.go @@ -195,6 +195,7 @@ type Cmdable interface { RPush(ctx context.Context, key string, values ...interface{}) *IntCmd RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd + BLMove(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration) *StringCmd SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd SCard(ctx context.Context, key string) *IntCmd @@ -1494,6 +1495,13 @@ func (c cmdable) LMove(ctx context.Context, source, destination, srcpos, destpos return cmd } +func (c cmdable) BLMove(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration) *StringCmd { + cmd := NewStringCmd(ctx, "blmove", source, destination, srcpos, destpos, formatSec(ctx, timeout)) + cmd.setReadTimeout(timeout) + _ = c(ctx, cmd) + return cmd +} + //------------------------------------------------------------------------------ func (c cmdable) SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd { diff --git a/commands_test.go b/commands_test.go index 985744cb..fc8c15ca 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2372,6 +2372,27 @@ var _ = Describe("Commands", func() { Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{"san"})) }) + It("should BLMove", func() { + rPush := client.RPush(ctx, "blmove1", "ichi") + Expect(rPush.Err()).NotTo(HaveOccurred()) + Expect(rPush.Val()).To(Equal(int64(1))) + + rPush = client.RPush(ctx, "blmove1", "ni") + Expect(rPush.Err()).NotTo(HaveOccurred()) + Expect(rPush.Val()).To(Equal(int64(2))) + + rPush = client.RPush(ctx, "blmove1", "san") + Expect(rPush.Err()).NotTo(HaveOccurred()) + Expect(rPush.Val()).To(Equal(int64(3))) + + blMove := client.BLMove(ctx, "blmove1", "lmove2", "RIGHT", "LEFT", time.Second) + Expect(blMove.Err()).NotTo(HaveOccurred()) + Expect(blMove.Val()).To(Equal("san")) + + lRange := client.LRange(ctx, "blmove2", 0, -1) + Expect(lRange.Err()).NotTo(HaveOccurred()) + Expect(lRange.Val()).To(Equal([]string{"san"})) + }) }) Describe("sets", func() {