Redis Generic command

UNLINK

UNLINK key [key ...]

#Example

redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> UNLINK key1 key2 key3
(integer) 2

Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking.

TYPE

TYPE key

#Example

redis> SET key1 "value"
"OK"
redis> LPUSH key2 "value"
(integer) 1
redis> SADD key3 "value"
(integer) 1
redis> TYPE key1
"string"
redis> TYPE key2
"list"
redis> TYPE key3
"set"

Determine the type stored at key

TTL

TTL key

#Example

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10

Get the time to live for a key

TOUCH

TOUCH key [key ...]

#Example

redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> TOUCH key1 key2
(integer) 2

Alters the last access time of a key(s). Returns the number of existing keys specified.

RENAMENX

RENAMENX key newkey

#Example

redis> SET mykey "Hello"
"OK"
redis> SET myotherkey "World"
"OK"
redis> RENAMENX mykey myotherkey
(integer) 0
redis> GET myotherkey
"World"

Rename a key, only if the new key does not exist

RENAME

RENAME key newkey

#Example

redis> SET mykey "Hello"
"OK"
redis> RENAME mykey myotherkey
"OK"
redis> GET myotherkey
"Hello"

Rename a key

PTTL

PTTL key

#Example

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 1
(integer) 1
redis> PTTL mykey
(integer) 1000

Get the time to live for a key in milliseconds

PEXPIREAT

PEXPIREAT key milliseconds-timestamp

#Example

redis> SET mykey "Hello"
"OK"
redis> PEXPIREAT mykey 1555555555005
(integer) 1
redis> TTL mykey
(integer) -2
redis> PTTL mykey
(integer) -2

Set the expiration for a key as a UNIX timestamp specified in milliseconds

PEXPIRE

PEXPIRE key milliseconds

#Example

redis> SET mykey "Hello"
"OK"
redis> PEXPIRE mykey 1500
(integer) 1
redis> TTL mykey
(integer) 1
redis> PTTL mykey
(integer) 1499

Set a key's time to live in milliseconds

PERSIST

PERSIST key

#Example

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> PERSIST mykey
(integer) 1
redis> TTL mykey
(integer) -1

Remove the expiration from a key

KEYS

KEYS pattern

#Example

redis> MSET firstname Jack lastname Stuntman age 35
"OK"
redis> KEYS \*name\*
1) "firstname"
2) "lastname"
redis> KEYS a??
1) "age"
redis> KEYS \*
1) "firstname"
2) "age"
3) "lastname"

Find all keys matching the given pattern

EXPIREAT

EXPIREAT key timestamp

#Example

redis> SET mykey "Hello"
"OK"
redis> EXISTS mykey
(integer) 1
redis> EXPIREAT mykey 1293840000
(integer) 1
redis> EXISTS mykey
(integer) 0

Set the expiration for a key as a UNIX timestamp

EXPIRE

EXPIRE key seconds

#Example

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> SET mykey "Hello World"
"OK"
redis> TTL mykey
(integer) -1

Set a key's time to live in seconds

EXISTS

EXISTS key [key ...]

#Example

redis> SET key1 "Hello"
"OK"
redis> EXISTS key1
(integer) 1
redis> EXISTS nosuchkey
(integer) 0
redis> SET key2 "World"
"OK"
redis> EXISTS key1 key2 nosuchkey
(integer) 2

Determine if a key exists

DUMP

DUMP key

#Example

redis> SET mykey 10
"OK"
redis> DUMP mykey
"\u0000\xC0\n\t\u0000\xBEm\u0006\x89Z(\u0000\n"

Return a serialized version of the value stored at the specified key.

DEL

DEL key [key ...]

#Example

redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> DEL key1 key2 key3
(integer) 2

Delete a key

Comments