Skip to content

Commit

Permalink
feat: add hstrlen command for hash (#2843)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
rfyiamcool and ndyakov authored Mar 4, 2025
1 parent ebe11d0 commit cd55713
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit cd55713

Please sign in to comment.