mirror of
https://github.com/redis/go-redis.git
synced 2025-06-12 14:21:52 +03:00
Add SetEX command
This commit is contained in:
@ -1147,7 +1147,7 @@ var _ = Describe("Commands", func() {
|
||||
|
||||
It("should Set with keepttl", func() {
|
||||
// set with ttl
|
||||
set := client.Set(ctx, "key", "hello", 5 * time.Second)
|
||||
set := client.Set(ctx, "key", "hello", 5*time.Second)
|
||||
Expect(set.Err()).NotTo(HaveOccurred())
|
||||
Expect(set.Val()).To(Equal("OK"))
|
||||
|
||||
@ -1172,6 +1172,19 @@ var _ = Describe("Commands", func() {
|
||||
Expect(get.Val()).To(Equal("hello"))
|
||||
})
|
||||
|
||||
It("should SetEX", func() {
|
||||
err := client.SetEX(ctx, "key", "hello", 100*time.Millisecond).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
val, err := client.Get(ctx, "key").Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(val).To(Equal("hello"))
|
||||
|
||||
Eventually(func() error {
|
||||
return client.Get(ctx, "foo").Err()
|
||||
}, "1s", "100ms").Should(Equal(redis.Nil))
|
||||
})
|
||||
|
||||
It("should SetNX", func() {
|
||||
setNX := client.SetNX(ctx, "key", "hello", 0)
|
||||
Expect(setNX.Err()).NotTo(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user