What is Redis?

Redis is an open source, BSD-compliant, memory-based data store that is often used as database caching messaging middleware. Redis data is stored in memory, fast read and write, breakpoints disappear immediately, mechanism: persistence mechanism Memory data is periodically written to disk Summary: Redis is an in-memory database, which can be used as cache message middleware, etc

The characteristics of Redis

  • Redis is a high performance key/value in-memory database
  • Redis supports rich data types (String list set zset Hash)
  • Redis supports persistence
  • Redis single threading ensures thread-safety issues

Redis database related instructions

Database operation instruction

By default, there are 16 library numbers ranging from 0 to 15. You can use the select library number to select a redis library. The data between libraries is isolated from each other

Flushes the current library FLUSHDB

FLUSHALL the libraries in FLUSHALL

The redis client displays./redis-cli -p 7000 –raw

Operation key related commands

1.DEL command syntax: DEL key [key....] Available version: >= 1.0.0 Returned value: number of deleted keys 2.EXISTS instruction syntax: EXISTS key Function: checks whether an available version of a given key EXISTS: >= 1.0.0 Returned value: EXPIRE syntax: EXPIRE key seconds Function: set lifetime for a given key. When a key expires (lifetime = 0), it will be automatically deleted. Key * match all KEYS in the database. H? Llo matches Hello Hallo hxllo and keys H * Llo matches hlLO and Heeeeeeeello and heys H [AE] LLO matches Hello and Hallo but does not match Hillo. Special symbols separate available versions with "\" : >= 1.0.0 Return value: key list that matches the given schema 5.MOVE syntax: MOVE key DB Function: MOVE the current database key to the given database db available version: >= 1.0.0 Return value: 1 return value: 0 return value: PEXPIRE key milliseconds function: This command works similarly to the EXPIRE command, but it sets the lifetime of the key in milliseconds rather than seconds like the EXPIRE command. Available versions: >= 2.6.0 Time complexity: O(1) : PEXPIREAT: PEXPIREAT key milliseconds-timestamp This command is similar to the EXPIREAT command, but it sets the expired Unix timestamp of the key in milliseconds, rather than seconds like EXPIREAT. Available version: >=2.6.0 Returned value: 1 is returned if the key is set successfully, 0 is returned if the key does not exist or the key fails to be set 8.TTL syntax: TTL key Function: The TTL key is used in seconds. Available version: >= 1.0.0 Returned value: Return -1 if the key does not exist and the remaining lifetime is not set. Otherwise, return the remaining lifetime of the key in seconds. Note: Before Redis2.8, all commands returned -1 if the key did not exist or the remaining lifetime of the key was not set. PTTL key Function: This command is similar to the TTL command, but it returns the remaining lifetime of the key in milliseconds, rather than seconds like the TTL command. Available version: >= 2.6.0 Returned value: -2 is returned if the key does not exist. If the key exists but the remaining lifetime is not set, -1 is returned. Otherwise, the remaining lifetime of the key is returned, in milliseconds. Note: Prior to Redis 2.8, commands returned -1 when the key did not exist or had no remaining lifetime set for the key. Return value: returns a key if the database is not empty, or nil if the database is empty. RENAME key newkey Function: RENAME a key to newkey. If the key is the same as the newkey or the key does not exist, an error is displayed. When newkey already exists, the RENAME command overwrites the old value. TYPE Syntax: TYPE KEY Function: Returns the TYPE of the value stored in the KEY. Available version: >= 1.0.0 Returned value: None (key does not exist) String list set zset hashCopy the code