Skip to content

Commit d2c53bd

Browse files
authored
refactor: change ListElementCmd to KeyValuesCmd. (#2443)
* refactor: change ListElementCmd to KeyValuesCmd Signed-off-by: monkey92t <[email protected]> * KeyValuesCmd.val are modified to pointers Signed-off-by: monkey92t <[email protected]> * recover KeyValuesCmd API Signed-off-by: monkey92t <[email protected]> --------- Signed-off-by: monkey92t <[email protected]>
1 parent 3532f2a commit d2c53bd

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

command.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,42 +3693,42 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
36933693

36943694
//------------------------------------------------------------------------------
36953695

3696-
type ListElementCmd struct {
3696+
type KeyValuesCmd struct {
36973697
baseCmd
36983698

36993699
key string
37003700
val []string
37013701
}
37023702

3703-
var _ Cmder = (*ListElementCmd)(nil)
3703+
var _ Cmder = (*KeyValuesCmd)(nil)
37043704

3705-
func NewListElementCmd(ctx context.Context, args ...interface{}) *ListElementCmd {
3706-
return &ListElementCmd{
3705+
func NewKeyValuesCmd(ctx context.Context, args ...interface{}) *KeyValuesCmd {
3706+
return &KeyValuesCmd{
37073707
baseCmd: baseCmd{
37083708
ctx: ctx,
37093709
args: args,
37103710
},
37113711
}
37123712
}
37133713

3714-
func (cmd *ListElementCmd) SetVal(key string, val []string) {
3714+
func (cmd *KeyValuesCmd) SetVal(key string, val []string) {
37153715
cmd.key = key
37163716
cmd.val = val
37173717
}
37183718

3719-
func (cmd *ListElementCmd) Val() (string, []string) {
3719+
func (cmd *KeyValuesCmd) Val() (string, []string) {
37203720
return cmd.key, cmd.val
37213721
}
37223722

3723-
func (cmd *ListElementCmd) Result() (string, []string, error) {
3723+
func (cmd *KeyValuesCmd) Result() (string, []string, error) {
37243724
return cmd.key, cmd.val, cmd.err
37253725
}
37263726

3727-
func (cmd *ListElementCmd) String() string {
3727+
func (cmd *KeyValuesCmd) String() string {
37283728
return cmdString(cmd, cmd.val)
37293729
}
37303730

3731-
func (cmd *ListElementCmd) readReply(rd *proto.Reader) (err error) {
3731+
func (cmd *KeyValuesCmd) readReply(rd *proto.Reader) (err error) {
37323732
if err = rd.ReadFixedArrayLen(2); err != nil {
37333733
return err
37343734
}

commands.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ type Cmdable interface {
225225
LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd
226226
LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
227227
LLen(ctx context.Context, key string) *IntCmd
228-
LMPop(ctx context.Context, direction string, count int64, keys ...string) *ListElementCmd
228+
LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd
229229
LPop(ctx context.Context, key string) *StringCmd
230230
LPopCount(ctx context.Context, key string, count int) *StringSliceCmd
231231
LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
@@ -1467,15 +1467,15 @@ func (c cmdable) LIndex(ctx context.Context, key string, index int64) *StringCmd
14671467
// LMPop Pops one or more elements from the first non-empty list key from the list of provided key names.
14681468
// direction: left or right, count: > 0
14691469
// example: client.LMPop(ctx, "left", 3, "key1", "key2")
1470-
func (c cmdable) LMPop(ctx context.Context, direction string, count int64, keys ...string) *ListElementCmd {
1470+
func (c cmdable) LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd {
14711471
args := make([]interface{}, 2+len(keys), 5+len(keys))
14721472
args[0] = "lmpop"
14731473
args[1] = len(keys)
14741474
for i, key := range keys {
14751475
args[2+i] = key
14761476
}
14771477
args = append(args, strings.ToLower(direction), "count", count)
1478-
cmd := NewListElementCmd(ctx, args...)
1478+
cmd := NewKeyValuesCmd(ctx, args...)
14791479
_ = c(ctx, cmd)
14801480
return cmd
14811481
}

commands_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,25 +2279,25 @@ var _ = Describe("Commands", func() {
22792279
err = client.LPush(ctx, "list2", "a", "b", "c", "d", "e").Err()
22802280
Expect(err).NotTo(HaveOccurred())
22812281

2282-
key, elems, err := client.LMPop(ctx, "left", 3, "list1", "list2").Result()
2282+
key, val, err := client.LMPop(ctx, "left", 3, "list1", "list2").Result()
22832283
Expect(err).NotTo(HaveOccurred())
22842284
Expect(key).To(Equal("list1"))
2285-
Expect(elems).To(Equal([]string{"five", "four", "three"}))
2285+
Expect(val).To(Equal([]string{"five", "four", "three"}))
22862286

2287-
key, elems, err = client.LMPop(ctx, "right", 3, "list1", "list2").Result()
2287+
key, val, err = client.LMPop(ctx, "right", 3, "list1", "list2").Result()
22882288
Expect(err).NotTo(HaveOccurred())
22892289
Expect(key).To(Equal("list1"))
2290-
Expect(elems).To(Equal([]string{"one", "two"}))
2290+
Expect(val).To(Equal([]string{"one", "two"}))
22912291

2292-
key, elems, err = client.LMPop(ctx, "left", 1, "list1", "list2").Result()
2292+
key, val, err = client.LMPop(ctx, "left", 1, "list1", "list2").Result()
22932293
Expect(err).NotTo(HaveOccurred())
22942294
Expect(key).To(Equal("list2"))
2295-
Expect(elems).To(Equal([]string{"e"}))
2295+
Expect(val).To(Equal([]string{"e"}))
22962296

2297-
key, elems, err = client.LMPop(ctx, "right", 10, "list1", "list2").Result()
2297+
key, val, err = client.LMPop(ctx, "right", 10, "list1", "list2").Result()
22982298
Expect(err).NotTo(HaveOccurred())
22992299
Expect(key).To(Equal("list2"))
2300-
Expect(elems).To(Equal([]string{"a", "b", "c", "d"}))
2300+
Expect(val).To(Equal([]string{"a", "b", "c", "d"}))
23012301

23022302
err = client.LMPop(ctx, "left", 10, "list1", "list2").Err()
23032303
Expect(err).To(Equal(redis.Nil))

0 commit comments

Comments
 (0)