当前位置:网站首页>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 !
边栏推荐
- 基于购买行为数据对超市顾客进行市场细分(RFM模型)
- 论文翻译英译中,怎样做翻译效果好?
- Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot
- [Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
- My daily learning records / learning methods
- Phishing & filename inversion & Office remote template
- Data security -- 13 -- data security lifecycle management
- Today's summer solstice
- mysql的基础命令
- PHP uses redis to implement distributed locks
猜你喜欢
Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
国产游戏国际化离不开专业的翻译公司
How to convert flv file to MP4 file? A simple solution
Past and present lives of QR code and sorting out six test points
Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks
翻译影视剧字幕,这些特点务必要了解
我的创作纪念日
Today's summer solstice
端午节快乐Wish Dragon Boat Festival is happy
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
随机推荐
How to do a good job in financial literature translation?
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
Lecture 8: 1602 LCD (Guo Tianxiang)
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
CS certificate fingerprint modification
如何做好互联网金融的英语翻译
LeetCode 1200. Minimum absolute difference
基于购买行为数据对超市顾客进行市场细分(RFM模型)
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot
Past and present lives of QR code and sorting out six test points
Simulation volume leetcode [general] 1314 Matrix area and
Office-DOC加载宏-上线CS
LeetCode 732. My schedule III
SQL Server manager studio(SSMS)安装教程
[ 英語 ] 語法重塑 之 動詞分類 —— 英語兔學習筆記(2)
How do programmers remember code and programming language?
Convert the array selected by El tree into an array object
ECS accessKey key disclosure and utilization
Leetcode daily question (971. flip binary tree to match preorder traversal)