Global command

Keys * displays all key values and is normally disabled

Dbsize displays the total number of keys in the current database

When the dbsize command calculates the total number of keys, it does not traverse all keys, but directly obtains the total number of keys built in Redis. The time complexity of dbsize command is O(1). The keys command traverses all keys in O(n) time. When Redis stores a large number of keys, the online environment is disabled

Exists Key Checks whether the key exists. The value is 1 if it exists and 0 if it does not exist

del key [key …] Generic command that supports any data type

Expire Key seconds The key expires

TTL key Remaining expiration time of the return key

  • Greater than or equal to 0: indicates the remaining expiration time of the key

  • -1: the expiration time is not set

  • -2: The key does not exist

Type Key Returns the data structure type of the key, or None if the key does not exist

Data structure and internal encoding

Object Encoding Key Queries the internal encoding

Why a single thread can be faster
  1. Pure memory access, Redis puts all the data in memory, and the memory response time is about 100 nanoseconds, which is an important foundation for Redis to achieve 10,000 per second level
  2. Non-blocking I/O, Redis uses Epoll as I/O multiplexing technology to achieve, Redis own event processing model to epoll connection, read and write, closed events, do not waste too many events on network I/O
  3. Single threading avoids the cost of thread switching and races

Problems with single threads

The execution time of each command is required. If one command is executed too long, it will cause other commands to block, which is fatal for a high performance service like Redis, which is geared toward fast execution scenario databases.