Skip to content

Commit a9b4c5c

Browse files
authored
Support Hash-field expiration commands (#2991)
* Add HExpire command * Add HPExpire, HexpireAt, HPExpireAt, HTTL, HPTTL, HPersist,HExpireTime, HPExpireTIme, HGetF, HSetF commands * add docstring * add tests and fix commands * modify commands * api changes * fix tests * remove tests from RE
1 parent 2a3de7e commit a9b4c5c

File tree

2 files changed

+397
-1
lines changed

2 files changed

+397
-1
lines changed

commands_test.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,154 @@ var _ = Describe("Commands", func() {
24302430
Equal([]redis.KeyValue{{Key: "key2", Value: "hello2"}}),
24312431
))
24322432
})
2433+
2434+
It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
2435+
res, err := client.HExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
2436+
Expect(err).To(BeNil())
2437+
for i := 0; i < 100; i++ {
2438+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2439+
Expect(sadd.Err()).NotTo(HaveOccurred())
2440+
}
2441+
2442+
res, err = client.HExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
2443+
Expect(err).NotTo(HaveOccurred())
2444+
Expect(res).To(Equal([]int64{1, 1, -2}))
2445+
})
2446+
2447+
It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
2448+
_, err := client.HPExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
2449+
Expect(err).To(BeNil())
2450+
for i := 0; i < 100; i++ {
2451+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2452+
Expect(sadd.Err()).NotTo(HaveOccurred())
2453+
}
2454+
2455+
res, err := client.HPExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
2456+
Expect(err).NotTo(HaveOccurred())
2457+
Expect(res).To(Equal([]int64{1, 1, -2}))
2458+
})
2459+
2460+
It("should HExpireAt", Label("hash-expiration", "NonRedisEnterprise"), func() {
2461+
2462+
_, err := client.HExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
2463+
Expect(err).To(BeNil())
2464+
for i := 0; i < 100; i++ {
2465+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2466+
Expect(sadd.Err()).NotTo(HaveOccurred())
2467+
}
2468+
2469+
res, err := client.HExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
2470+
Expect(err).NotTo(HaveOccurred())
2471+
Expect(res).To(Equal([]int64{1, 1, -2}))
2472+
})
2473+
2474+
It("should HPExpireAt", Label("hash-expiration", "NonRedisEnterprise"), func() {
2475+
2476+
_, err := client.HPExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
2477+
Expect(err).To(BeNil())
2478+
for i := 0; i < 100; i++ {
2479+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2480+
Expect(sadd.Err()).NotTo(HaveOccurred())
2481+
}
2482+
2483+
res, err := client.HPExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
2484+
Expect(err).NotTo(HaveOccurred())
2485+
Expect(res).To(Equal([]int64{1, 1, -2}))
2486+
})
2487+
2488+
It("should HPersist", Label("hash-expiration", "NonRedisEnterprise"), func() {
2489+
2490+
_, err := client.HPersist(ctx, "no_such_key", "field1", "field2", "field3").Result()
2491+
Expect(err).To(BeNil())
2492+
for i := 0; i < 100; i++ {
2493+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2494+
Expect(sadd.Err()).NotTo(HaveOccurred())
2495+
}
2496+
2497+
res, err := client.HPersist(ctx, "myhash", "key1", "key2", "key200").Result()
2498+
Expect(err).NotTo(HaveOccurred())
2499+
Expect(res).To(Equal([]int64{-1, -1, -2}))
2500+
2501+
res, err = client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2502+
Expect(err).NotTo(HaveOccurred())
2503+
Expect(res).To(Equal([]int64{1, -2}))
2504+
2505+
res, err = client.HPersist(ctx, "myhash", "key1", "key2", "key200").Result()
2506+
Expect(err).NotTo(HaveOccurred())
2507+
Expect(res).To(Equal([]int64{1, -1, -2}))
2508+
})
2509+
2510+
It("should HExpireTime", Label("hash-expiration", "NonRedisEnterprise"), func() {
2511+
2512+
_, err := client.HExpireTime(ctx, "no_such_key", "field1", "field2", "field3").Result()
2513+
Expect(err).To(BeNil())
2514+
for i := 0; i < 100; i++ {
2515+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2516+
Expect(sadd.Err()).NotTo(HaveOccurred())
2517+
}
2518+
2519+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2520+
Expect(err).NotTo(HaveOccurred())
2521+
Expect(res).To(Equal([]int64{1, -2}))
2522+
2523+
res, err = client.HExpireTime(ctx, "myhash", "key1", "key2", "key200").Result()
2524+
Expect(err).NotTo(HaveOccurred())
2525+
Expect(res[0]).To(BeNumerically("~", time.Now().Add(10*time.Second).Unix(), 1))
2526+
})
2527+
2528+
It("should HPExpireTime", Label("hash-expiration", "NonRedisEnterprise"), func() {
2529+
2530+
_, err := client.HPExpireTime(ctx, "no_such_key", "field1", "field2", "field3").Result()
2531+
Expect(err).To(BeNil())
2532+
for i := 0; i < 100; i++ {
2533+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2534+
Expect(sadd.Err()).NotTo(HaveOccurred())
2535+
}
2536+
2537+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2538+
Expect(err).NotTo(HaveOccurred())
2539+
Expect(res).To(Equal([]int64{1, -2}))
2540+
2541+
res, err = client.HPExpireTime(ctx, "myhash", "key1", "key2", "key200").Result()
2542+
Expect(err).NotTo(HaveOccurred())
2543+
Expect(res).To(BeEquivalentTo([]int64{time.Now().Add(10 * time.Second).UnixMilli(), -1, -2}))
2544+
})
2545+
2546+
It("should HTTL", Label("hash-expiration", "NonRedisEnterprise"), func() {
2547+
2548+
_, err := client.HTTL(ctx, "no_such_key", "field1", "field2", "field3").Result()
2549+
Expect(err).To(BeNil())
2550+
for i := 0; i < 100; i++ {
2551+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2552+
Expect(sadd.Err()).NotTo(HaveOccurred())
2553+
}
2554+
2555+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2556+
Expect(err).NotTo(HaveOccurred())
2557+
Expect(res).To(Equal([]int64{1, -2}))
2558+
2559+
res, err = client.HTTL(ctx, "myhash", "key1", "key2", "key200").Result()
2560+
Expect(err).NotTo(HaveOccurred())
2561+
Expect(res).To(Equal([]int64{10, -1, -2}))
2562+
})
2563+
2564+
It("should HPTTL", Label("hash-expiration", "NonRedisEnterprise"), func() {
2565+
2566+
_, err := client.HPTTL(ctx, "no_such_key", "field1", "field2", "field3").Result()
2567+
Expect(err).To(BeNil())
2568+
for i := 0; i < 100; i++ {
2569+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
2570+
Expect(sadd.Err()).NotTo(HaveOccurred())
2571+
}
2572+
2573+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
2574+
Expect(err).NotTo(HaveOccurred())
2575+
Expect(res).To(Equal([]int64{1, -2}))
2576+
2577+
res, err = client.HPTTL(ctx, "myhash", "key1", "key2", "key200").Result()
2578+
Expect(err).NotTo(HaveOccurred())
2579+
Expect(res[0]).To(BeNumerically("~", 10*time.Second.Milliseconds(), 1))
2580+
})
24332581
})
24342582

24352583
Describe("hyperloglog", func() {

0 commit comments

Comments
 (0)