From 5c3de7537ac2a6080a0ebe4e02bede39876c9d60 Mon Sep 17 00:00:00 2001 From: sjindal995 Date: Thu, 18 Jul 2019 16:48:09 +0530 Subject: [PATCH 1/2] Making LpushX and RpushX variadic --- commands.go | 22 ++++++++++++++++------ commands_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index 872c35c5..d2de8cb3 100644 --- a/commands.go +++ b/commands.go @@ -140,7 +140,7 @@ type Cmdable interface { LLen(key string) *IntCmd LPop(key string) *StringCmd LPush(key string, values ...interface{}) *IntCmd - LPushX(key string, value interface{}) *IntCmd + LPushX(key string, value interface{}, values ...interface{}) *IntCmd LRange(key string, start, stop int64) *StringSliceCmd LRem(key string, count int64, value interface{}) *IntCmd LSet(key string, index int64, value interface{}) *StatusCmd @@ -148,7 +148,7 @@ type Cmdable interface { RPop(key string) *StringCmd RPopLPush(source, destination string) *StringCmd RPush(key string, values ...interface{}) *IntCmd - RPushX(key string, value interface{}) *IntCmd + RPushX(key string, value interface{}, values ...interface{}) *IntCmd SAdd(key string, members ...interface{}) *IntCmd SCard(key string) *IntCmd SDiff(keys ...string) *StringSliceCmd @@ -1087,8 +1087,13 @@ func (c cmdable) LPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) LPushX(key string, value interface{}) *IntCmd { - cmd := NewIntCmd("lpushx", key, value) +func (c cmdable) LPushX(key string, value interface{}, values ...interface{}) *IntCmd { + args := make([]interface{}, 3, 3+len(values)) + args[0] = "lpushx" + args[1] = key + args[2] = value + args = appendArgs(args, values) + cmd := NewIntCmd(args...) c(cmd) return cmd } @@ -1149,8 +1154,13 @@ func (c cmdable) RPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) RPushX(key string, value interface{}) *IntCmd { - cmd := NewIntCmd("rpushx", key, value) +func (c cmdable) RPushX(key string, value interface{}, values ...interface{}) *IntCmd { + args := make([]interface{}, 3, 3+len(values)) + args[0] = "rpushx" + args[1] = key + args[2] = value + args = appendArgs(args, values) + cmd := NewIntCmd(args...) c(cmd) return cmd } diff --git a/commands_test.go b/commands_test.go index 13c636bf..7fa9b732 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1652,6 +1652,14 @@ var _ = Describe("Commands", func() { Expect(lPushX.Err()).NotTo(HaveOccurred()) Expect(lPushX.Val()).To(Equal(int64(2))) + lPush = client.LPush("list1", "three") + Expect(lPush.Err()).NotTo(HaveOccurred()) + Expect(lPush.Val()).To(Equal(int64(1))) + + lPushX = client.LPushX("list1", "two", "one") + Expect(lPushX.Err()).NotTo(HaveOccurred()) + Expect(lPushX.Val()).To(Equal(int64(3))) + lPushX = client.LPushX("list2", "Hello") Expect(lPushX.Err()).NotTo(HaveOccurred()) Expect(lPushX.Val()).To(Equal(int64(0))) @@ -1660,6 +1668,10 @@ var _ = Describe("Commands", func() { Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{"Hello", "World"})) + lRange = client.LRange("list1", 0, -1) + Expect(lRange.Err()).NotTo(HaveOccurred()) + Expect(lRange.Val()).To(Equal([]string{"one", "two", "three"})) + lRange = client.LRange("list2", 0, -1) Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{})) @@ -1808,6 +1820,14 @@ var _ = Describe("Commands", func() { Expect(rPushX.Err()).NotTo(HaveOccurred()) Expect(rPushX.Val()).To(Equal(int64(2))) + rPush = client.RPush("list1", "one") + Expect(rPush.Err()).NotTo(HaveOccurred()) + Expect(rPush.Val()).To(Equal(int64(1))) + + rPushX = client.RPushX("list1", "two", "three") + Expect(rPushX.Err()).NotTo(HaveOccurred()) + Expect(rPushX.Val()).To(Equal(int64(3))) + rPushX = client.RPushX("list2", "World") Expect(rPushX.Err()).NotTo(HaveOccurred()) Expect(rPushX.Val()).To(Equal(int64(0))) @@ -1816,6 +1836,10 @@ var _ = Describe("Commands", func() { Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{"Hello", "World"})) + lRange = client.LRange("list1", 0, -1) + Expect(lRange.Err()).NotTo(HaveOccurred()) + Expect(lRange.Val()).To(Equal([]string{"one", "two", "three"})) + lRange = client.LRange("list2", 0, -1) Expect(lRange.Err()).NotTo(HaveOccurred()) Expect(lRange.Val()).To(Equal([]string{})) From 87ea8a4220dda703c8dfa3193fcb8a9004bcd04b Mon Sep 17 00:00:00 2001 From: sjindal995 Date: Thu, 18 Jul 2019 17:23:05 +0530 Subject: [PATCH 2/2] remove mandatory arg value in lpushx and rpushx --- commands.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index d2de8cb3..710aef2b 100644 --- a/commands.go +++ b/commands.go @@ -140,7 +140,7 @@ type Cmdable interface { LLen(key string) *IntCmd LPop(key string) *StringCmd LPush(key string, values ...interface{}) *IntCmd - LPushX(key string, value interface{}, values ...interface{}) *IntCmd + LPushX(key string, values ...interface{}) *IntCmd LRange(key string, start, stop int64) *StringSliceCmd LRem(key string, count int64, value interface{}) *IntCmd LSet(key string, index int64, value interface{}) *StatusCmd @@ -148,7 +148,7 @@ type Cmdable interface { RPop(key string) *StringCmd RPopLPush(source, destination string) *StringCmd RPush(key string, values ...interface{}) *IntCmd - RPushX(key string, value interface{}, values ...interface{}) *IntCmd + RPushX(key string, values ...interface{}) *IntCmd SAdd(key string, members ...interface{}) *IntCmd SCard(key string) *IntCmd SDiff(keys ...string) *StringSliceCmd @@ -1087,11 +1087,10 @@ func (c cmdable) LPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) LPushX(key string, value interface{}, values ...interface{}) *IntCmd { - args := make([]interface{}, 3, 3+len(values)) +func (c cmdable) LPushX(key string, values ...interface{}) *IntCmd { + args := make([]interface{}, 2, 2+len(values)) args[0] = "lpushx" args[1] = key - args[2] = value args = appendArgs(args, values) cmd := NewIntCmd(args...) c(cmd) @@ -1154,11 +1153,10 @@ func (c cmdable) RPush(key string, values ...interface{}) *IntCmd { return cmd } -func (c cmdable) RPushX(key string, value interface{}, values ...interface{}) *IntCmd { - args := make([]interface{}, 3, 3+len(values)) +func (c cmdable) RPushX(key string, values ...interface{}) *IntCmd { + args := make([]interface{}, 2, 2+len(values)) args[0] = "rpushx" args[1] = key - args[2] = value args = appendArgs(args, values) cmd := NewIntCmd(args...) c(cmd)