Commands
CLI Operations
redis-cli # start a redis client

# exit
exit
            
Key Operations
# keys [pattern], list keys
keys * 

# return the number of keys in the currently-selected database
dbsize

#type [key], check the type of a key
type key1

# exists [key], if exist a key, 1, yes; otherwise, no
exists key
exists key1 key2

# rename [key_name] [new_key_name], rename a key
rename key1 key2

# randomkey, get a random key from Redis database
randomkey

# scan [cursor] match [pattern] count [num]
# cursor, the scan position
# pattern, search pattern
# num, the maxium search num, default is 10
scan 0 count 3 # return cursor 12 and three names
scan 12 # continue scan from cursor 12

# del [key], delete a key
del container

# remove all keys
flushall
            
Key Expiration
#expire [key] [seconds], setup expire time for a key
expire key1 5

# expireat [key] [timestamp]
# timestamp is a Unix timestamp, which is seconds since Jan 01, 1970 (UTC)
# convert time to timestamp, https://www.unixtimestamp.com/
expireat container 1637195373

# ttl [key], check expiration time
ttl container

# persist [key], remove the expiration from a key
persist key1

            
Server
# gets information and statistics about the server
info

# return the information and statistics about the client connections
client list

# listens for all the requests received by the server in real time
monitor

# get the maximum number of clients
config get maxclients

# list all Redis commands
command
            
Databases
# get the number of databases
config get databases

# select database by index
select index

# list the databases for which some keys are defined
info keyspace
            
Reference
  • Redis Commands
  • Redis Documentation