Skip to content

Commit 7539858

Browse files
tzongwofekshenawamonkey92t
authored
Support Hash-field expiration commands in Pipeline & Fix HExpire HExpireWithArgs expiration (#3038)
* Support Hash-field expiration commands in Pipeline * Fix HExpire & HExpireWithArgs expiration * Fix HExpire & HPExpire Testcase * Update commands_test.go --------- Co-authored-by: ofekshenawa <[email protected]> Co-authored-by: Monkey <[email protected]>
1 parent 6a584c1 commit 7539858

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

commands_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -2486,31 +2486,31 @@ var _ = Describe("Commands", func() {
24862486
})
24872487

24882488
It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
2489-
resEmpty, err := client.HExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
2489+
res, err := client.HExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()
24902490
Expect(err).To(BeNil())
2491-
Expect(resEmpty).To(BeEquivalentTo([]int64{-2, -2, -2}))
2491+
Expect(res).To(BeEquivalentTo([]int64{-2, -2, -2}))
24922492

24932493
for i := 0; i < 100; i++ {
24942494
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
24952495
Expect(sadd.Err()).NotTo(HaveOccurred())
24962496
}
24972497

2498-
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
2498+
res, err = client.HExpire(ctx, "myhash", 10*time.Second, "key1", "key2", "key200").Result()
24992499
Expect(err).NotTo(HaveOccurred())
25002500
Expect(res).To(Equal([]int64{1, 1, -2}))
25012501
})
25022502

25032503
It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
2504-
resEmpty, err := client.HPExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
2504+
res, err := client.HPExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()
25052505
Expect(err).To(BeNil())
2506-
Expect(resEmpty).To(BeEquivalentTo([]int64{-2, -2, -2}))
2506+
Expect(res).To(BeEquivalentTo([]int64{-2, -2, -2}))
25072507

25082508
for i := 0; i < 100; i++ {
25092509
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
25102510
Expect(sadd.Err()).NotTo(HaveOccurred())
25112511
}
25122512

2513-
res, err := client.HPExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
2513+
res, err = client.HPExpire(ctx, "myhash", 10*time.Second, "key1", "key2", "key200").Result()
25142514
Expect(err).NotTo(HaveOccurred())
25152515
Expect(res).To(Equal([]int64{1, 1, -2}))
25162516
})
@@ -2559,7 +2559,7 @@ var _ = Describe("Commands", func() {
25592559
Expect(err).NotTo(HaveOccurred())
25602560
Expect(res).To(Equal([]int64{-1, -1, -2}))
25612561

2562-
res, err = client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2562+
res, err = client.HExpire(ctx, "myhash", 10*time.Second, "key1", "key200").Result()
25632563
Expect(err).NotTo(HaveOccurred())
25642564
Expect(res).To(Equal([]int64{1, -2}))
25652565

@@ -2578,7 +2578,7 @@ var _ = Describe("Commands", func() {
25782578
Expect(sadd.Err()).NotTo(HaveOccurred())
25792579
}
25802580

2581-
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2581+
res, err := client.HExpire(ctx, "myhash", 10*time.Second, "key1", "key200").Result()
25822582
Expect(err).NotTo(HaveOccurred())
25832583
Expect(res).To(Equal([]int64{1, -2}))
25842584

@@ -2617,7 +2617,7 @@ var _ = Describe("Commands", func() {
26172617
Expect(sadd.Err()).NotTo(HaveOccurred())
26182618
}
26192619

2620-
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2620+
res, err := client.HExpire(ctx, "myhash", 10*time.Second, "key1", "key200").Result()
26212621
Expect(err).NotTo(HaveOccurred())
26222622
Expect(res).To(Equal([]int64{1, -2}))
26232623

@@ -2636,7 +2636,7 @@ var _ = Describe("Commands", func() {
26362636
Expect(sadd.Err()).NotTo(HaveOccurred())
26372637
}
26382638

2639-
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2639+
res, err := client.HExpire(ctx, "myhash", 10*time.Second, "key1", "key200").Result()
26402640
Expect(err).NotTo(HaveOccurred())
26412641
Expect(res).To(Equal([]int64{1, -2}))
26422642

hash_commands.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ 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+
HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
27+
HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
28+
HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
29+
HPExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
30+
HExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
31+
HExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
32+
HPExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
33+
HPExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
34+
HPersist(ctx context.Context, key string, fields ...string) *IntSliceCmd
35+
HExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
36+
HPExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
37+
HTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
38+
HPTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
2639
}
2740

2841
func (c cmdable) HDel(ctx context.Context, key string, fields ...string) *IntCmd {
@@ -202,7 +215,7 @@ type HExpireArgs struct {
202215
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
203216
// For more information - https://redis.io/commands/hexpire/
204217
func (c cmdable) HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd {
205-
args := []interface{}{"HEXPIRE", key, expiration, "FIELDS", len(fields)}
218+
args := []interface{}{"HEXPIRE", key, formatSec(ctx, expiration), "FIELDS", len(fields)}
206219

207220
for _, field := range fields {
208221
args = append(args, field)
@@ -217,7 +230,7 @@ func (c cmdable) HExpire(ctx context.Context, key string, expiration time.Durati
217230
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
218231
// For more information - https://redis.io/commands/hexpire/
219232
func (c cmdable) HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd {
220-
args := []interface{}{"HEXPIRE", key, expiration}
233+
args := []interface{}{"HEXPIRE", key, formatSec(ctx, expiration)}
221234

222235
// only if one argument is true, we can add it to the args
223236
// if more than one argument is true, it will cause an error

0 commit comments

Comments
 (0)