当前位置:网站首页>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 !
边栏推荐
- 钓鱼&文件名反转&office远程模板
- Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
- [ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
- Defense (greed), FBI tree (binary tree)
- 基于JEECG-BOOT制作“左树右表”交互页面
- Lesson 7 tensorflow realizes convolutional neural network
- CS certificate fingerprint modification
- LeetCode - 152 乘积最大子数组
- E-book CHM online CS
- 利用快捷方式-LNK-上线CS
猜你喜欢

钓鱼&文件名反转&office远程模板

Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes

Making interactive page of "left tree and right table" based on jeecg-boot

Changes in the number of words in English papers translated into Chinese

記一個基於JEECG-BOOT的比較複雜的增删改功能的實現

如何做好金融文献翻译?

Luogu p2089 roast chicken

How do programmers remember code and programming language?

翻译生物医学说明书,英译中怎样效果佳

Play video with Tencent video plug-in in uni app
随机推荐
Past and present lives of QR code and sorting out six test points
Delete external table source data
Data security -- 13 -- data security lifecycle management
MySQL5.72.msi安装失败
MFC dynamically creates dialog boxes and changes the size and position of controls
Oscp raven2 target penetration process
JDBC requset corresponding content and function introduction
Convert the array selected by El tree into an array object
CS-证书指纹修改
Defense (greed), FBI tree (binary tree)
SourceInsight Chinese garbled
Cobalt strike feature modification
The internationalization of domestic games is inseparable from professional translation companies
国产游戏国际化离不开专业的翻译公司
如何做好互联网金融的英语翻译
Cannot create poolableconnectionfactory (could not create connection to database server. error
SQL Server manager studio(SSMS)安装教程
My creation anniversary
MySQL is sorted alphabetically
org. activiti. bpmn. exceptions. XMLException: cvc-complex-type. 2.4. a: Invalid content beginning with element 'outgoing' was found