当前位置:网站首页>Redis Foundation
Redis Foundation
2022-07-06 06:38:00 【Protogram Technology】
One 、Redis brief introduction
Redis Is a high-performance key-value database
Two 、Redis Characteristics
Support data persistence
Rich data types
3、 ... and 、redis data type
string( character string ),hash( Hash ),list( list ),set( aggregate ) And zset(sorted set: Ordered set )
1、string( character string )
# Set up
SET runoob " Novice tutorial "
# obtain
GET runoob
2、Hash( Hash )
# Set up
HMSET runoob field1 "Hello" field2 "World"
# obtain
HGET runoob field1
HGET runoob field2
3、List( list )
# Set up
lpush runoob redis
lpush runoob mongodb
lpush runoob rabbitmq
# obtain
redis 127.0.0.1:6379> lrange runoob 0 10
1) "rabbitmq"
2) "mongodb"
3) "redis"
4、Set( aggregate )
# grammar
sadd key member
# Set up
sadd runoob redis
sadd runoob mongodb
sadd runoob rabbitmq
sadd runoob rabbitmq
# obtain
redis 127.0.0.1:6379> smembers runoob
1) "redis"
2) "rabbitmq"
3) "mongodb"
5、zset(sorted set: Ordered set )
# grammar
zadd key score member
# Set up
zadd runoob 0 redis
zadd runoob 0 mongodb
zadd runoob 0 rabbitmq
zadd runoob 0 rabbitmq
# obtain
redis 127.0.0.1:6379> ZRANGEBYSCORE runoob 0 1000
1) "mongodb"
2) "rabbitmq"
3) "redis"
notes : Delete use DEL key
Four 、Redis Publish subscribe
Redis Publish subscribe (pub/sub) It's a message communication mode : sender (pub) Send a message , subscriber (sub) receive messages .
5、 ... and 、Redis Business
1、 A transaction goes through the following three stages from the beginning to the execution :
Start business .
Order to join the team .
Perform transactions .
2、 example
Start with MULTI Start a transaction , Then queue multiple commands into the transaction , Finally by EXEC Command triggers transaction , Execute all the commands in the transaction
redis 127.0.0.1:6379> MULTI
OK
redis 127.0.0.1:6379> SET book-name "Mastering C++ in 21 days"
QUEUED
redis 127.0.0.1:6379> GET book-name
QUEUED
redis 127.0.0.1:6379> SADD tag "C++" "Programming" "Mastering Series"
QUEUED
redis 127.0.0.1:6379> SMEMBERS tag
QUEUED
redis 127.0.0.1:6379> EXEC
1) OK
2) "Mastering C++ in 21 days"
3) (integer) 3
4) 1) "Mastering Series"
2) "C++"
3) "Programming"
6、 ... and 、Redis Stream
Redis Stream It is mainly used for message queuing (MQ,Message Queue),Redis There is one in itself Redis Publish subscribe (pub/sub) To realize the function of message queuing , But it has a drawback that messages are not persistent , If there is a network disconnect 、Redis Downtime, etc , The message will be discarded .
Simply put, publish subscribe (pub/sub) You can distribute messages , But we can't record historical information .
and Redis Stream It provides message persistence and primary / secondary replication functions , Any client can access data at any time , And remember the location of each client's access , It also ensures that the message is not lost .
Message queuing related commands :
XADD - Add the message to the end
XTRIM - Pruning the convection , Limit length
XDEL - removal message
XLEN - Gets the number of elements contained in the stream , The message length
XRANGE - Get message list , Will automatically filter deleted messages
XREVRANGE - Get the message list in reverse ,ID From big to small
XREAD - Get a list of messages in a blocking or non blocking way
Consumer group related orders :
XGROUP CREATE - Create consumer groups
XREADGROUP GROUP - Read messages from consumer groups
XACK - Mark the message as " Disposed of "
XGROUP SETID - Set up a new last delivery message for the consumer group ID
XGROUP DELCONSUMER - Delete consumer
XGROUP DESTROY - Delete consumer group
XPENDING - Displays information about the message to be processed
XCLAIM - Transfer ownership of messages
XINFO - View information about streams and consumer groups ;
XINFO GROUPS - Print information about consumer groups ;
XINFO STREAM - Print stream information
7、 ... and 、Redis Data backup and recovery
1、 Backup
Redis SAVE Command to create a backup of the current database
example :
redis 127.0.0.1:6379> SAVE
OK
The order will be in redis Create... In the installation directory dump.rdb file .
2、 recovery
If you need to recover data , Just back up the files (dump.rdb) Move to redis Install the directory and start the service . obtain redis The directory can be used CONFIG command , As shown below :
redis 127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/usr/local/redis/bin"
The above order CONFIG GET dir Output redis Installation directory is /usr/local/redis/bin.
8、 ... and 、Redis Security
1、 example
We can check whether password verification is set through the following command :
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) ""
By default requirepass Parameter is empty , This means that you can connect to... Without password verification redis service .
You can modify this parameter with the following command :
127.0.0.1:6379> CONFIG set requirepass "runoob"
OK
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) "runoob"
After setting the password , Client connection redis The service needs password verification , Otherwise, the command cannot be executed .
grammar
AUTH The basic syntax of the command is as follows :
127.0.0.1:6379> AUTH password
example
127.0.0.1:6379> AUTH "runoob"
OK
127.0.0.1:6379> SET mykey "Test value"
OK
127.0.0.1:6379> GET mykey
"Test value"
Nine 、Redis Pipeline technology
Redis It's a client based - Server model and request / In response to the protocol TCP service . This means that normally a request follows these steps :
The client sends a query request to the server , And monitor Socket return , Usually in blocking mode , Waiting for the server to respond .
The server handles commands , And return the result to the client .
Redis Pipeline technology can be used when the server is not responding , The client can continue to send requests to the server , And finally read all the server's responses at once .
Advantages of Pipeline Technology : The most significant advantage of pipeline technology is the improvement of redis Service performance .
Ten 、Redis Partition
Partitioning is dividing data into multiple Redis The process of the instance , So each instance only saves key A subset of .
11、 ... and 、 other
Redis Queue real-time and non real-time : Real time and non real time are mainly aimed at consumers , Message producers produce messages after ,Redis These messages are stored in the queue , When to consume is our concern , Non real time means , At the back end, there is a rotation service to get messages from the queue regularly , This has a certain delay ; Real time means building on the consumer side Tcp A long connection , When the queue has data, consume it immediately , When there is no data, the thread is in a suspended waiting state !
边栏推荐
- 红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)
- Introduction and underlying analysis of regular expressions
- Day 248/300 关于毕业生如何找工作的思考
- 字幕翻译中翻英一分钟多少钱?
- Private cloud disk deployment
- Esp32 esp-idf watchdog twdt
- MFC dynamically creates dialog boxes and changes the size and position of controls
- 自动化测试环境配置
- LeetCode 731. My schedule II
- 论文翻译英译中,怎样做翻译效果好?
猜你喜欢

Office doc add in - Online CS

E-book CHM online CS

电子书-CHM-上线CS

Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException

Convert the array selected by El tree into an array object

ECS accessKey key disclosure and utilization

Cobalt Strike特征修改

SQL Server manager studio(SSMS)安装教程

Suspended else

Lecture 8: 1602 LCD (Guo Tianxiang)
随机推荐
Day 246/300 ssh连接提示“REMOTE HOST IDENTIFICATION HAS CHANGED! ”
Difference between backtracking and recursion
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
Data security -- 13 -- data security lifecycle management
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
My creation anniversary
Simulation volume leetcode [general] 1314 Matrix area and
Set the print page style by modifying style
Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
利用快捷方式-LNK-上线CS
E-book CHM online CS
生物医学本地化翻译服务
LeetCode 729. My schedule I
How do programmers remember code and programming language?
Leetcode daily question (971. flip binary tree to match preorder traversal)
Simulation volume leetcode [general] 1405 Longest happy string
It is necessary to understand these characteristics in translating subtitles of film and television dramas
Office doc add in - Online CS
How much is the price for the seal of the certificate
基于JEECG-BOOT的list页面的地址栏参数传递