Skip to content

Commit 4935c43

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

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

commands_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,22 @@ var _ = Describe("Commands", func() {
24142414
Equal([]redis.KeyValue{{Key: "key2", Value: "hello2"}}),
24152415
))
24162416
})
2417+
2418+
It("should HStrLen", func() {
2419+
hSet := client.HSet(ctx, "hash", "key", "hello")
2420+
Expect(hSet.Err()).NotTo(HaveOccurred())
2421+
2422+
hStrLen := client.HStrLen(ctx, "hash", "key")
2423+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2424+
Expect(hStrLen.Val()).NotTo(Equal(int64(len("hello"))))
2425+
2426+
nonHStrLen := client.HGet(ctx, "hash", "key1")
2427+
Expect(nonHStrLen.Val()).To(Equal(int64(0)))
2428+
2429+
hDel := client.HDel(ctx, "hash", "key")
2430+
Expect(hDel.Err()).NotTo(HaveOccurred())
2431+
Expect(hDel.Val()).To(Equal(int64(1)))
2432+
})
24172433
})
24182434

24192435
Describe("hyperloglog", func() {

hash_commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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
910
HGetAll(ctx context.Context, key string) *MapStringStringCmd
1011
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
1112
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
@@ -45,6 +46,12 @@ func (c cmdable) HGet(ctx context.Context, key, field string) *StringCmd {
4546
return cmd
4647
}
4748

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+
4855
func (c cmdable) HGetAll(ctx context.Context, key string) *MapStringStringCmd {
4956
cmd := NewMapStringStringCmd(ctx, "hgetall", key)
5057
_ = c(ctx, cmd)

0 commit comments

Comments
 (0)