Commands
CLI Operations
  1. redis-cli # start a redis client
  2.  
  3. # exit
  4. exit
Key Operations
  1. # keys [pattern], list keys
  2. keys *
  3.  
  4. # return the number of keys in the currently-selected database
  5. dbsize
  6.  
  7. #type [key], check the type of a key
  8. type key1
  9.  
  10. # exists [key], if exist a key, 1, yes; otherwise, no
  11. exists key
  12. exists key1 key2
  13.  
  14. # rename [key_name] [new_key_name], rename a key
  15. rename key1 key2
  16.  
  17. # randomkey, get a random key from Redis database
  18. randomkey
  19.  
  20. # scan [cursor] match [pattern] count [num]
  21. # cursor, the scan position
  22. # pattern, search pattern
  23. # num, the maxium search num, default is 10
  24. scan 0 count 3 # return cursor 12 and three names
  25. scan 12 # continue scan from cursor 12
  26.  
  27. # del [key], delete a key
  28. del container
  29.  
  30. # remove all keys
  31. flushall
Key Expiration
  1. #expire [key] [seconds], setup expire time for a key
  2. expire key1 5
  3.  
  4. # expireat [key] [timestamp]
  5. # timestamp is a Unix timestamp, which is seconds since Jan 01, 1970 (UTC)
  6. # convert time to timestamp, https://www.unixtimestamp.com/
  7. expireat container 1637195373
  8.  
  9. # ttl [key], check expiration time
  10. ttl container
  11.  
  12. # persist [key], remove the expiration from a key
  13. persist key1
  14.  
Server
  1. # gets information and statistics about the server
  2. info
  3.  
  4. # return the information and statistics about the client connections
  5. client list
  6.  
  7. # listens for all the requests received by the server in real time
  8. monitor
  9.  
  10. # get the maximum number of clients
  11. config get maxclients
  12.  
  13. # list all Redis commands
  14. command
Databases
  1. # get the number of databases
  2. config get databases
  3.  
  4. # select database by index
  5. select index
  6.  
  7. # list the databases for which some keys are defined
  8. info keyspace
Reference
  • Redis Commands
  • Redis Documentation