diff --git a/commands_test.go b/commands_test.go index 309ba1eb0..56956c6e9 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2414,6 +2414,23 @@ var _ = Describe("Commands", func() { 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()).To(Equal(int64(len("hello")))) + + nonHStrLen := client.HStrLen(ctx, "hash", "keyNon") + Expect(hStrLen.Err()).NotTo(HaveOccurred()) + 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() { diff --git a/hash_commands.go b/hash_commands.go index 2c62a75ad..f8ca64d34 100644 --- a/hash_commands.go +++ b/hash_commands.go @@ -19,6 +19,7 @@ type HashCmdable interface { HVals(ctx context.Context, key string) *StringSliceCmd HRandField(ctx context.Context, key string, count int) *StringSliceCmd HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd + HStrLen(ctx context.Context, key, field string) *IntCmd } func (c cmdable) HDel(ctx context.Context, key string, fields ...string) *IntCmd { @@ -172,3 +173,9 @@ func (c cmdable) HScan(ctx context.Context, key string, cursor uint64, match str _ = c(ctx, 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 +}