repeat
pipeline
Traditional request / response protocol
- Client sends a query to the server, block waiting for the server response
- server processes the query and returns the result
pipeline
What is
Even if the client did not receive a response, you can still send a request, and finally deal with the old response
note
When a client sends a request to use a pipeline server, server requires some memory, sequentially storing the corresponding Response, if it needs to send a large number of command line, it is preferable to send them as a batch with a reasonable number of, for example, command 10k read the reply, then send 10k command again, and so on
advantage
- Reduce the RTT time
- Increasing the total amount of a given operation Redis server executable per second: socket I / O very costly, the system read and write operations reflection, to the core domain from the user domain, including a context switch is
- Processing speed 10 times
Contact scripting
Reduce network overhead. The multiple requests can be sent in the form of a script, to reduce network latency
Atomic operation. redis entire script as a whole will perform, will not be inserted into the middle of other commands. Therefore, in the process of writing the script without worrying about race conditions occur, without the use of a transaction.
Multiplexing. Footsteps sent by the client will be permanently present in redis, so that other clients can be multiplexed without using the script code that perform the same logic.
eval 用来直接执行 lua 脚本: EVAL script numkeys key [key ...] arg [arg ...] > eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second 1) "key1" 2) "key2" 3) "first" 4) "second"
redis Configuration
Redis can without using the built-in default configuration file to configure the boot, but this setting is recommended only for testing and development purposes.
The correct way is to provide a configuration Redis Redis configuration file, usually called redis.conf
.
Format:keyword argument1 argument2 ... argumentN
Pass the command line parameters
./redis-server --port 6380 --slaveof 127.0.0.1 6379
- The format of the command line parameters passed
redis.conf
exactly the same format parameters used in the document, but the prefix keyword is--
. - This generates a temporary profile in the internal memory (the user may connect the transfer profile (if any)), wherein the parameter is converted to a
redis.conf
format.
Passing parameters server runtime
config set
config get
You can set and query configuration information without stopping and restarting services- Run-time configuration changes will not affect the
redis.conf
contents of the file, next time you start the service still using the old configuration information config rewrite
You can updateredis.conf
the content, content, and configuration comments section not covered does not change
The redis configured to cache
The redis set to cache, each key will have a limit expired, would not have a separate set expire time
例如如下设置,当超过 2mb 的内存限制,便会过期 maxmemory 2mb maxmemory-policy allkeys-lru