feat: add hstrlen command for hash

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
rfyiamcool 2023-12-18 19:03:04 +08:00 committed by fengyun.rui
parent 73c879df57
commit 4935c434b1
2 changed files with 23 additions and 0 deletions

View File

@ -2414,6 +2414,22 @@ var _ = Describe("Commands", func() {
Equal([]redis.KeyValue{{Key: "key2", Value: "hello2"}}), Equal([]redis.KeyValue{{Key: "key2", Value: "hello2"}}),
)) ))
}) })
It("should HStrLen", func() {
hSet := client.HSet(ctx, "hash", "key", "hello")
Expect(hSet.Err()).NotTo(HaveOccurred())
hStrLen := client.HStrLen(ctx, "hash", "key")
Expect(hStrLen.Err()).NotTo(HaveOccurred())
Expect(hStrLen.Val()).NotTo(Equal(int64(len("hello"))))
nonHStrLen := client.HGet(ctx, "hash", "key1")
Expect(nonHStrLen.Val()).To(Equal(int64(0)))
hDel := client.HDel(ctx, "hash", "key")
Expect(hDel.Err()).NotTo(HaveOccurred())
Expect(hDel.Val()).To(Equal(int64(1)))
})
}) })
Describe("hyperloglog", func() { Describe("hyperloglog", func() {

View File

@ -6,6 +6,7 @@ type HashCmdable interface {
HDel(ctx context.Context, key string, fields ...string) *IntCmd HDel(ctx context.Context, key string, fields ...string) *IntCmd
HExists(ctx context.Context, key, field string) *BoolCmd HExists(ctx context.Context, key, field string) *BoolCmd
HGet(ctx context.Context, key, field string) *StringCmd HGet(ctx context.Context, key, field string) *StringCmd
HStrLen(ctx context.Context, key, field string) *IntCmd
HGetAll(ctx context.Context, key string) *MapStringStringCmd HGetAll(ctx context.Context, key string) *MapStringStringCmd
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd 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 {
return cmd return cmd
} }
func (c cmdable) HStrLen(ctx context.Context, key, field string) *IntCmd {
cmd := NewIntCmd(ctx, "hstrlen", key, field)
_ = c(ctx, cmd)
return cmd
}
func (c cmdable) HGetAll(ctx context.Context, key string) *MapStringStringCmd { func (c cmdable) HGetAll(ctx context.Context, key string) *MapStringStringCmd {
cmd := NewMapStringStringCmd(ctx, "hgetall", key) cmd := NewMapStringStringCmd(ctx, "hgetall", key)
_ = c(ctx, cmd) _ = c(ctx, cmd)