1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

Refactor Set, SetNX and SetXX with expiration.

This commit is contained in:
Vladimir Mihailenco
2015-01-31 11:08:56 +02:00
parent d363cc72c5
commit 2dc61d458a
10 changed files with 182 additions and 89 deletions

View File

@ -109,7 +109,7 @@ var _ = Describe("Client", func() {
defer db1.Close()
Expect(db1.Get("key").Err()).To(Equal(redis.Nil))
Expect(db1.Set("key", "value").Err()).NotTo(HaveOccurred())
Expect(db1.Set("key", "value", 0).Err()).NotTo(HaveOccurred())
Expect(client.Get("key").Err()).To(Equal(redis.Nil))
Expect(db1.Get("key").Val()).To(Equal("value"))
@ -253,7 +253,7 @@ func BenchmarkRedisSet(b *testing.B) {
b.StartTimer()
for i := 0; i < b.N; i++ {
if err := client.Set("key", "hello").Err(); err != nil {
if err := client.Set("key", "hello", 0).Err(); err != nil {
panic(err)
}
}
@ -281,7 +281,7 @@ func BenchmarkRedisGet(b *testing.B) {
client := redis.NewTCPClient(&redis.Options{
Addr: redisAddr,
})
if err := client.Set("key", "hello").Err(); err != nil {
if err := client.Set("key", "hello", 0).Err(); err != nil {
b.Fatal(err)
}
b.StartTimer()
@ -318,7 +318,7 @@ func BenchmarkSetExpire(b *testing.B) {
b.StartTimer()
for i := 0; i < b.N; i++ {
if err := client.Set("key", "hello").Err(); err != nil {
if err := client.Set("key", "hello", 0).Err(); err != nil {
b.Fatal(err)
}
if err := client.Expire("key", time.Second).Err(); err != nil {
@ -336,7 +336,7 @@ func BenchmarkPipeline(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := client.Pipelined(func(pipe *redis.Pipeline) error {
pipe.Set("key", "hello")
pipe.Set("key", "hello", 0)
pipe.Expire("key", time.Second)
return nil
})