Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.
Josh Baker edited this page Oct 11, 2016 · 8 revisions

GETSET key value

Atomically sets key to value and returns the old value stored at key.

Design pattern

GETSET can be used together with INCR for counting with atomic reset. For example: a process may call INCR against the key mycounter every time some event occurs, but from time to time we need to get the value of the counter and reset it to zero atomically. This can be done using GETSET mycounter "0":

Examples

> INCR mycounter
(integer) 1
> GETSET mycounter "0"
"1"
> GET mycounter
"0"

Related Commands

APPEND, BITCOUNT, BITOP, BITPOS, DBSIZE, DECR, DECRBY, DEL, EXISTS, EXPIRE, EXPIREAT, FLUSHDB, GET, GETBIT, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, KEYS, MGET, MSET, MSETNX, PDEL, PERSIST, PEXPIRE, PEXPIREAT, PTTL, RENAME, RENAMENX, SET, SETBIT, SETRANGE, STRLEN, TTL

Clone this wiki locally