From c0b0c99ec5ebf3d86f93db4e4ab929dadf74667d Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 7 Aug 2015 17:02:17 +0300 Subject: [PATCH 1/2] Document zero expiration. Fixes #143. --- commands.go | 9 +++++++++ example_test.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/commands.go b/commands.go index 7f10a2f0..887fd737 100644 --- a/commands.go +++ b/commands.go @@ -526,6 +526,9 @@ func (c *commandable) MSetNX(pairs ...string) *BoolCmd { return cmd } +// Redis `SET key value [expiration]` command. +// +// Zero expiration means the key has no expiration time. func (c *commandable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd { args := make([]interface{}, 3, 5) args[0] = "SET" @@ -554,6 +557,9 @@ func (c *commandable) SetBit(key string, offset int64, value int) *IntCmd { return cmd } +// Redis `SET key value [expiration] NX` command. +// +// Zero expiration means the key has no expiration time. func (c *commandable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd { var cmd *BoolCmd if expiration == 0 { @@ -570,6 +576,9 @@ func (c *commandable) SetNX(key string, value interface{}, expiration time.Durat return cmd } +// Redis `SET key value [expiration] XX` command. +// +// Zero expiration means the key has no expiration time. func (c *Client) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd { var cmd *BoolCmd if usePrecise(expiration) { diff --git a/example_test.go b/example_test.go index 25869bea..de9f8da9 100644 --- a/example_test.go +++ b/example_test.go @@ -84,6 +84,21 @@ func ExampleClient() { // key2 does not exists } +func ExampleClient_Set() { + // Last argument is expiration. Zero means the key has no + // expiration time. + err := client.Set("key", "value", 0).Err() + if err != nil { + panic(err) + } + + // key2 will expire in an hour. + err = client.Set("key2", "value", time.Hour).Err() + if err != nil { + panic(err) + } +} + func ExampleClient_Incr() { if err := client.Incr("counter").Err(); err != nil { panic(err) From d522cd5ae5e5f936ba35efc880435c26daf762d8 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 7 Aug 2015 18:07:27 +0300 Subject: [PATCH 2/2] travis: use Redis 3.0.3 to fix the build. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d3763d61..1107e5fe 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ testdeps: .test/redis/src/redis-server .test/redis: mkdir -p $@ - wget -qO- https://github.com/antirez/redis/archive/3.0.tar.gz | tar xvz --strip-components=1 -C $@ + wget -qO- https://github.com/antirez/redis/archive/3.0.3.tar.gz | tar xvz --strip-components=1 -C $@ .test/redis/src/redis-server: .test/redis cd $< && make all