1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-17 20:17:02 +03:00

feat: add hstrlen command for hash (#2843)

* feat: add hstrlen command for hash

Signed-off-by: rfyiamcool <rfyiamcool@163.com>

* feat: add hstrlen command for hash

Signed-off-by: rfyiamcool <rfyiamcool@163.com>

---------

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
This commit is contained in:
fengyun.rui 2025-03-04 19:31:45 +08:00 committed by GitHub
parent ebe11d06ca
commit cd55713972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -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() { It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images") 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() 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})) Expect(res).To(Equal([]int64{1, 1, -2}))
}) })
It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() { It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images") 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() res, err := client.HPExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()

View File

@ -23,6 +23,7 @@ type HashCmdable interface {
HVals(ctx context.Context, key string) *StringSliceCmd HVals(ctx context.Context, key string) *StringSliceCmd
HRandField(ctx context.Context, key string, count int) *StringSliceCmd HRandField(ctx context.Context, key string, count int) *StringSliceCmd
HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd 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 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 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 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 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 { func (c cmdable) HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd {
args := []interface{}{"hscan", key, cursor} args := []interface{}{"hscan", key, cursor}
if match != "" { if match != "" {