Skip to content

Commit cd55713

Browse files
rfyiamcoolndyakov
andauthored
feat: add hstrlen command for hash (#2843)
* feat: add hstrlen command for hash Signed-off-by: rfyiamcool <[email protected]> * feat: add hstrlen command for hash Signed-off-by: rfyiamcool <[email protected]> --------- Signed-off-by: rfyiamcool <[email protected]> Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent ebe11d0 commit cd55713

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

commands_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,23 @@ var _ = Describe("Commands", func() {
26262626
))
26272627
})
26282628

2629+
It("should HStrLen", func() {
2630+
hSet := client.HSet(ctx, "hash", "key", "hello")
2631+
Expect(hSet.Err()).NotTo(HaveOccurred())
2632+
2633+
hStrLen := client.HStrLen(ctx, "hash", "key")
2634+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2635+
Expect(hStrLen.Val()).To(Equal(int64(len("hello"))))
2636+
2637+
nonHStrLen := client.HStrLen(ctx, "hash", "keyNon")
2638+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2639+
Expect(nonHStrLen.Val()).To(Equal(int64(0)))
2640+
2641+
hDel := client.HDel(ctx, "hash", "key")
2642+
Expect(hDel.Err()).NotTo(HaveOccurred())
2643+
Expect(hDel.Val()).To(Equal(int64(1)))
2644+
})
2645+
26292646
It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
26302647
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images")
26312648
res, err := client.HExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()
@@ -2642,6 +2659,7 @@ var _ = Describe("Commands", func() {
26422659
Expect(res).To(Equal([]int64{1, 1, -2}))
26432660
})
26442661

2662+
26452663
It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
26462664
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images")
26472665
res, err := client.HPExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()

hash_commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type HashCmdable interface {
2323
HVals(ctx context.Context, key string) *StringSliceCmd
2424
HRandField(ctx context.Context, key string, count int) *StringSliceCmd
2525
HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd
26+
HStrLen(ctx context.Context, key, field string) *IntCmd
2627
HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
2728
HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
2829
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
190191
return cmd
191192
}
192193

194+
func (c cmdable) HStrLen(ctx context.Context, key, field string) *IntCmd {
195+
cmd := NewIntCmd(ctx, "hstrlen", key, field)
196+
_ = c(ctx, cmd)
197+
return cmd
198+
}
193199
func (c cmdable) HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd {
194200
args := []interface{}{"hscan", key, cursor}
195201
if match != "" {

0 commit comments

Comments
 (0)