Skip to content

Commit 47591c8

Browse files
committed
feat: add hstrlen command for hash
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
1 parent 4935c43 commit 47591c8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

commands_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,9 +2421,10 @@ var _ = Describe("Commands", func() {
24212421

24222422
hStrLen := client.HStrLen(ctx, "hash", "key")
24232423
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2424-
Expect(hStrLen.Val()).NotTo(Equal(int64(len("hello"))))
2424+
Expect(hStrLen.Val()).To(Equal(int64(len("hello"))))
24252425

2426-
nonHStrLen := client.HGet(ctx, "hash", "key1")
2426+
nonHStrLen := client.HStrLen(ctx, "hash", "keyNon")
2427+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
24272428
Expect(nonHStrLen.Val()).To(Equal(int64(0)))
24282429

24292430
hDel := client.HDel(ctx, "hash", "key")

hash_commands.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ type HashCmdable interface {
66
HDel(ctx context.Context, key string, fields ...string) *IntCmd
77
HExists(ctx context.Context, key, field string) *BoolCmd
88
HGet(ctx context.Context, key, field string) *StringCmd
9-
HStrLen(ctx context.Context, key, field string) *IntCmd
109
HGetAll(ctx context.Context, key string) *MapStringStringCmd
1110
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
1211
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
@@ -20,6 +19,7 @@ type HashCmdable interface {
2019
HVals(ctx context.Context, key string) *StringSliceCmd
2120
HRandField(ctx context.Context, key string, count int) *StringSliceCmd
2221
HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd
22+
HStrLen(ctx context.Context, key, field string) *IntCmd
2323
}
2424

2525
func (c cmdable) HDel(ctx context.Context, key string, fields ...string) *IntCmd {
@@ -46,12 +46,6 @@ func (c cmdable) HGet(ctx context.Context, key, field string) *StringCmd {
4646
return cmd
4747
}
4848

49-
func (c cmdable) HStrLen(ctx context.Context, key, field string) *IntCmd {
50-
cmd := NewIntCmd(ctx, "hstrlen", key, field)
51-
_ = c(ctx, cmd)
52-
return cmd
53-
}
54-
5549
func (c cmdable) HGetAll(ctx context.Context, key string) *MapStringStringCmd {
5650
cmd := NewMapStringStringCmd(ctx, "hgetall", key)
5751
_ = c(ctx, cmd)
@@ -179,3 +173,9 @@ func (c cmdable) HScan(ctx context.Context, key string, cursor uint64, match str
179173
_ = c(ctx, cmd)
180174
return cmd
181175
}
176+
177+
func (c cmdable) HStrLen(ctx context.Context, key, field string) *IntCmd {
178+
cmd := NewIntCmd(ctx, "hstrlen", key, field)
179+
_ = c(ctx, cmd)
180+
return cmd
181+
}

0 commit comments

Comments
 (0)