GET

GET

Retrieves the value of a key; if the key does not exist, nil will be returned.

GET nokey
>>> (nil)

SET mykey 'myvalue'
>>> OK

GET mykey
>>> "myvalue"

GETDEL

Retrieves the value of a key and then deletes it immediately afterward.

SET mykey 'myvalue'
>>> OK

GETDEL mykey
>>> "myvalue"

GET mykey
>>> (nil)

GETEX

Retrieves the value of a key and sets its expiration time in seconds.

SET mykey 'myvalue'
>>> OK

GETEX mykey EX 60
>>> "myvalue"

The GET command above will retrieve the value of mykey and set it to expire after 60 seconds.

We can check how much time is left until expiration using the TTL command.

TTL mykey
>>> (integer) 54