GETEX
Syntax
GETEX key [EX | PX | EXAT | PXAT | PERSIST]
Module
genericCategories
fast writeDescription
Get the value of key and optionally set its expiration. GETEX is similar to [GET], but is a write command with additional options.
Options
EX
- Set the specified expire time, in seconds.PX
- Set the specified expire time, in milliseconds.EXAT
- Set the specified Unix time at which the key will expire, in seconds.PXAT
- Set the specified Unix time at which the key will expire, in milliseconds.PERSIST
- Remove the time to live associated with the key.
Examples
- Go (Embedded)
- CLI
The embedded API utilizes the GetExOption interface, which acts as a wrapper for the various expiry options of the GETEX command.
GetExOption includes the following constants:
EX
- Set the specified expire time, in seconds.PX
- Set the specified expire time, in milliseconds.EXAT
- Set the specified Unix time at which the key will expire, in seconds.PXAT
- Set the specified Unix time at which the key will expire, in milliseconds.PERSIST
- Remove the time to live associated with the key.
Get the value at the specified key:
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
value, err := db.GetEx("key", nil, 0)
// optionally set expiry
value, err = db.GetEx("key", sugardb.EX, 10)
Get the value at the specified key and set the expiry:
> GETEX key EX 10