Other features of Redis Redis study notes -----

Foreword

In the understanding of publish-subscribe the Redis and transaction -related knowledge, we come to know today what his other characteristics -------- multiple databases, data out of policies and scripts.

A. Redis database

Under Redis, the database is an integer index identity, rather than a database name. By default, a client database connected to 0.
This is just entering our client (no later figures show that the database is marked 127.0.0.1:6379 0)

Here Insert Picture Description

1.redis configuration file using the following parameters to control the total number of database (we can modify its size):
 database 16  //(从0开始1 2 3 ....15)

Here Insert Picture Description

2. Related commands

Switches select the database // database
Here Insert Picture Description

Mobile data (the current key is moved to another library)

move key database name
Here Insert Picture Description

Empty database:

All flushdb // clear the current database of key
flushall // clear all the key throughout the Redis database
Here Insert Picture Description

Two. Redis data elimination strategy

1.Redis official to warn, when there is insufficient memory, Redis will be based out of some caching policy configuration Keys to success written guarantee. When no phase-out policy, or no suitable find out Key, Redis return directly out of memory error.
2. The maximum cache settings (make changes in redis.conf, search / maxmemory can find configuration)
in redis, run user and use the maximum memory size is 521g
3.Redis provides six data out of the policy

volatile-lru: 从已设置过期时间的数据集中挑选最近最少使用的数据淘汰
volatile-lfu: 从已设置过期时的Keys中,删除一段时间内使用次数最少的
volatile-ttl: 从已设置过期时间的数据集中挑选最近将要过期的数据淘汰
volatile-random: 从已设置过期时间的数据集中随机选择数据淘汰
allkeys-lru: 从数据集中挑选最近最少使用的数据淘汰
allkeys-lfu: 从所有keys中,删除一段时间内使用次数最少的
allkeys-random: 从数据集中随机选择数据淘汰
no-enviction(驱逐): 禁止驱逐数据(不采用任何淘汰策略,默认配置),针对写操作,返回错误信息  

Recommendation: Redis understand the strategy of elimination after use should usually try to take the initiative to set / update time key expire, the initiative to remove the old inactive data to help improve query performance.

Three .Redis script

1.Redis script uses the Lua interpreter to execute the script. Redis 2.6 version supported by the embedded Lua environment. Script to execute common commands EVAL .

2.Redis script commands

EVAL script numkeys key [key ...] arg [arg ...]        #执行 Lua 脚本
EVALSHA sha1 numkeys key [key ...] arg [arg ...]       #执行 Lua 脚本
SCRIPT EXISTS script [script ...]                      #查看指定的脚本是否已经被保存在缓存当中
SCRIPT FLUSH                                           #从脚本缓存中移除所有脚本
SCRIPT KILL                                            #杀死当前正在运行的 Lua 脚本
SCRIPT LOAD script                                    #将脚本 script 添加到脚本缓存中,但并不立即执行这个脚本

Examples
The following example demonstrates redis script work process:

127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second
1) "key1"
2) "key2"
3) "first"
4) "second"
Published 46 original articles · won praise 2 · Views 2840

Guess you like

Origin blog.csdn.net/TheWindOfSon/article/details/104334828