diff --git a/commands_test.go b/commands_test.go index 0bbc3688..681fe470 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2626,6 +2626,23 @@ var _ = Describe("Commands", func() { )) }) + 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))) + }) + It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() { SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images") res, err := client.HExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result() @@ -2642,6 +2659,7 @@ var _ = Describe("Commands", func() { Expect(res).To(Equal([]int64{1, 1, -2})) }) + It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() { SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images") res, err := client.HPExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result() diff --git a/hash_commands.go b/hash_commands.go index 6596c6f5..039d8e07 100644 --- a/hash_commands.go +++ b/hash_commands.go @@ -23,6 +23,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 HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd @@ -190,6 +191,11 @@ func (c cmdable) HScan(ctx context.Context, key string, cursor uint64, match str 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) HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd { args := []interface{}{"hscan", key, cursor} if match != "" {