redis general command

Redis five data types, String, hash, list, set, ordered set

The following commands are common to these five data types (6 common commands)

  • keys pattern : Get all keys matching pattern. * means any one or more characters; ? represents a character

For example: now there is

key        value

name zhaowei 

list1      [a b c d]

set1      [e m n d]

username zhaowei 

Requirement 1: Find all keys that contain name 

Command: keys *name*

Requirement 2: Find the four-character key

Command: keys ????

 Requirement 3: Query all keys

Command: keys *


  • del key1 key2.....  delete key

Requirement: delete username and name

Command: del username name



  • The exists key judges whether a key exists, 1 means exists, 0 means does not exist

    Requirement: determine whether list1 exists

 Command: exists list1



  • rename key newkey  renames the current key (this is rarely used in development, but you need to know)
  • type key Gets the type of the specified key. The command will return in string format. The returned string is String, hash, list, set, zset, if the key does not exist, return none

Set the validity period of the key

  • expire key time (in seconds) : set the lifetime of the key
  • ttl key  : Get the remaining time to live for the key
For example, set an expiration time of 30 seconds for list2 (if not set, all keys are permanently valid by default)


You can see that when list2 expires, it returns -2, and redis will delete the expired key

The ttl permanent key value is -1, which means it can live forever


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324650024&siteId=291194637