On redis

A, redis concept

Redis is a C-based language development nosql database.

Data stored in memory.

Data is stored in the form of key-value pairs.

Using the default encoding utf-8.

Second, commonly used type of data 5

1.String

2.hash

3.list

4.set

5.sortedSet

Third, the expiration policy

redis is based on memory, the memory is limited, if we add data to redis redis in memory beyond the scope of what will happen? Answer: Some data will be deleted.

redis most common elimination tactics, allkeys-lru: When the memory is not sufficient to accommodate the new data is written in the key space, remove the key the least recently used (this is the most common)

Fourth, the instructions: 1 Turn things: multi 2. commits the transaction: exec

The implementation of the principle: Open affairs multi, all commands executed will enter into the transaction queue, if the client is in a state of affairs, then when the exec command is executed, based on the client server stored transaction queue, first in first out (FIFO) way to execute a transaction queue commands: into the first team orders executed first, and the last team into the last command executed.

Fifth, the persistence mechanism

1.RDB (default): Redis will create a separate (fork) to a child process within the specified time interval the memory snapshot of a dataset written to disk.

Advantages: 1.RDB generates a plurality of data files, each data file is data representing a certain moment in the redis.

    2. The impact on the reader service provided by the external redis very small, allowing redis maintain high performance, because redis main process requires only fork a child process, so that the child process to perform disk IO operations to RDB persistence can be.

    3. AOF relative persistence mechanism, the direct-based RDB data files to restart and restore redis process more quickly.

Drawback: 1.RDB may result in the last persistence can not be completed, resulting in significant data loss.

AOF:. 1 in the form of log records each write operation, the redis executed all write commands recorded (read operations are not recorded) appendonly.aof written to the file, persistence time can be configured to always, everysec, no

Advantages: AOF can better protect the data is not lost, AOF will typically every one second, once performed by a background thread fsync (asynchronous) operation, data is lost most 1 seconds

Drawback: 1.AOF file will be larger and provide greater AOF document solutions, redis will automatically re-AOF file to generate a new minimum write operation based on the current data redis memory.

    2.AOF recovery slower than RDB.

Thread mode: multiplexed IO:. 1 "multiplex" refers to reuse the same thread. Multi-channel I / O multiplexing allows a single thread processing a plurality of connection requests efficiently (to minimize the time spent in the network IO)

      File event dispatcher: Depending on the client operating the associated transaction processor socket. Note: Because the file is single-threaded event dispatcher working, so it is single-threaded redis

 

Why redis single-threaded model can efficiently so high?

1. concise command expression.  

2. The memory-operation, the time complexity of O (1). 

3. The core is based on the non-blocking IO multiplexing mechanism.  

4. Instead, a single-threaded multi-threaded avoid the frequent context switching problem.  

Guess you like

Origin www.cnblogs.com/liweibin00/p/12114147.html