Document zero expiration. Fixes #143.

This commit is contained in:
Vladimir Mihailenco 2015-08-07 17:02:17 +03:00
parent 0e6443b1ac
commit c0b0c99ec5
2 changed files with 24 additions and 0 deletions

View File

@ -526,6 +526,9 @@ func (c *commandable) MSetNX(pairs ...string) *BoolCmd {
return cmd 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 { func (c *commandable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
args := make([]interface{}, 3, 5) args := make([]interface{}, 3, 5)
args[0] = "SET" args[0] = "SET"
@ -554,6 +557,9 @@ func (c *commandable) SetBit(key string, offset int64, value int) *IntCmd {
return cmd 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 { func (c *commandable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd {
var cmd *BoolCmd var cmd *BoolCmd
if expiration == 0 { if expiration == 0 {
@ -570,6 +576,9 @@ func (c *commandable) SetNX(key string, value interface{}, expiration time.Durat
return cmd 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 { func (c *Client) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
var cmd *BoolCmd var cmd *BoolCmd
if usePrecise(expiration) { if usePrecise(expiration) {

View File

@ -84,6 +84,21 @@ func ExampleClient() {
// key2 does not exists // 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() { func ExampleClient_Incr() {
if err := client.Incr("counter").Err(); err != nil { if err := client.Incr("counter").Err(); err != nil {
panic(err) panic(err)