1. Redis transaction definition
The Redis transaction is a separate isolation operation. All commands in the transaction will be serialized and executed in sequence. During the execution of the transaction, the transaction will not be interrupted by command requests sent by other clients.
The main role of Redis transactions is to connect multiple commands to prevent other commands from jumping in line
2. Basic knowledge of Redis
(1) Redis is a single process to handle client requests. The response to events such as reading and writing is done by wrapping epoll functions. The actual processing speed of Redis depends entirely on the execution efficiency of the main process
Epoll is an epoll that the Linux kernel has improved to handle large batches of file descriptors. It is an enhanced version of multiplexed IO interface select / poll under Linux . System CPU utilization
(2) Redis defaults to 16 databases , similar to the array index starting from 0, the initial default is to use library 0
# 在配置文件中可以修改
databases 16
# select语句切换数据库
select 2
(3) Common commands
# 当前数据库的数据条数
DBSIZE
# 查询全部
keys *
# 查询条件的查询 ?占一位 等等条件
keys a?
# 清空当前库
FLUSHDB
# 清空所有库
FLUSHALL
(4) Why the default port 6379
The number corresponding to MERZ on the phone button, and MERZ is taken from the name of Italian singer Alessia Merz
3. The five data types of Redis
String
string is the most basic type of redis, a key corresponds to a value, a string value can be up to 512M
The string type is binary safe, meaning that the redis string can contain any data, such as jpg pictures or serialized objects
Set
Redis's Set is an unordered collection of string type, which is realized through HashTable
ZSet (ordered set)
Like set, redis zset is also a collection of string type elements, and does not allow duplicate members.
The difference is that each element is associated with a double type score.
Redis uses the score to sort the members in the set from small to large. The members of zset are unique, but the score can be repeated
hash (hash, similar to Map in java)
redis hash is a collection of key-value pairs
redis hash is a mapping table of field and value of type string, hash is particularly suitable for storing objects
List
The Redis list is a simple linked list of strings, and its bottom layer is actually a linked list
Four. Redis commonly used instructions
Encyclopedia of redis commands : http://doc.redisfans.com/
exists key #判断某个key是否存在
move key db # 把key指定的数据移动到db指定的数据库
expire key 秒钟 #为指定的key设置过期的时间
ttl key #查看还有多少秒过期 ,-1表示永不过期,-2表示已过期
type key #查看你的key是什么类型