当前位置:网站首页>Redis learning
Redis learning
2022-07-31 00:23:00 【What Makes Perfect - LWP】
Origin of Redis
Antirez created a website in 2007
Antirez 2009 C language memory database Purpose: Solve my performance problems
1. Features:
1. Fast: Basic memory operation, so my operation does not need to interact with the disk, and the single execution will be very fast
2. The command execution is single-threaded because of the memory-based operation, the single execution time is longer than your thread switching timeFast
3. Redis itself is a k-v structure similar to hashMap, all query performance is close to O(1)
4. The underlying data structure such as skip table, sds (space for time)
5. NetworkModel IO multiplexingSecond, high availability
1. Perfect memory management mechanism Expiration, elimination, persistence
2. Master-slave, sentinel, cluster clusterThree, operation
1. Start the command ./reids-cli Default local
2. Flushall does not do persistence is equivalent to deleting the library and running away4. Data types and usage scenarios
1. String
a. Basic instructions set key value incr key Increase incrby key Decrease and add numbers to calculate with numbers
If setnx exists, the setting is successful
b. Application scenarios
Cache token (expiration time)
mysql Before querying mysql, see if redis has dcl double retrieval duoble check lock, only one request hits DB
10ms outside of single query 100ms (if mysqlCan not be optimized)
Incr count related scenarios can be done
Distributed ID
Likes and comments
Soft current limit
SMS verification times, inventory
2, Hash
a. Basic instructions hset key key value hget key key hincrby key key
k k v
b. Application scenarios
1. Cache object data
2. Statistical data
3.Shopping cart but will not do it just cache the redis cap ap model to ensure that it is available and will not care about data loss
3. List
a. Basic instructions lpush queue a lrange queue 0 -1 rpush put rpop on the right and remove the rightThe elements of
store ordered lists
b. Application scenarios
1. Are all ordered lists suitable for timelines
2. Block the message queue (don't go toDo) because we have perfect MQ component rabbit, rocket ack mechanism ap model
4, Set
a. Basic instruction sadd key value value (multiple values) smebers key
srandmember key 2 Randomly get twoElement spop key deletes an element
sdiff key key Difference of two sets
Unordered set (all integers are ordered) Elements are non-repeatable and the query efficiency is close to O(1)b. Application scenarios
1. Lottery draw
2. Common friends in the set-type scene
5. sortSet
Ordered non-repeatable If the score is the same, according to the key
a.Basic instructions zadd key value score add value zrange z1 0 -1 get all values
zrevrange z1 0-1 get elements in reverse order
zrangebyscore z1 20 40 get elements by score range
zscore a 60 give aElements plus 60 pointsb. Application scenarios
1. Ranking list6.BitMap
001001001001001
Command: setibt key 5 1 Add the element at the fifth position of the element
bitcount key count the element
getbit key get the element
Application scenario:
Permission: 101010
边栏推荐
猜你喜欢
随机推荐
Point Cloud Scene Reconstruction with Depth Estimation
Kotlin协程:协程上下文与上下文元素
宽客必备神器-AKShare
牛客网刷题训练(四)
VSCode高效开源神器有哪些
IOT cross-platform component design scheme
软件开发设计流程
MySQL数据库进阶篇
47. 【Pointers and Arrays】
从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
How to install joiplay emulator rtp
How to use joiplay emulator
神经网络(ANN)
firewalld
【唐宇迪 深度学习-3D点云实战系列】学习笔记
How to open the payment channel interface?
从两个易错的笔试题深入理解自增运算符
binglog log tracking: data backup and backup tracking
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
作业:iptables防止nmap扫描以及binlog








