当前位置:网站首页>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
边栏推荐
- 47. 【Pointers and Arrays】
- Neural Network (ANN)
- what is jira
- Dry goods | 4 tips for MySQL performance optimization
- 45.【list链表的应用】
- web漏洞之需要准备的工作
- 47.【指针与数组】
- [In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
- An easy-to-use interface testing tools - the Postman
- WebServer process explanation (registration module)
猜你喜欢
随机推荐
Asser uses ant sword to log in
MySQL数据库约束,表的设计
Shell programming conditional statement test command Integer value, string comparison Logical test File test
在微服务中使用事件溯源的六大原因 - Herath
乌克兰外交部:乌已完成恢复粮食安全出口的必要准备
go mode tidy出现报错go warning “all“ matched no packages
The first level must project independently
MySQL数据库的truncate与delete区别
A Brief Talk About MPI
Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
Summary of the stock problem of state machine dynamic programming
46.<list链表的举列>
Homework: iptables prevent nmap scan and binlog
How to open the payment channel interface?
Jetpack Compose学习(8)——State及remeber
MySQL数据库(基础)
Encapsulate and obtain system user information, roles and permission control
如何在WordPress网站上添加导航菜单
什么是Promise?Promise的原理是什么?Promise怎么用?
After writing business code for many years, I found these 11 doorways, which only experts know



![45. [Application of list linked list]](/img/7a/ca026cafeceffd2daee68fe66e1882.png)



![[In-depth and easy-to-follow FPGA learning 15---------- Timing analysis basics]](/img/a9/4c7a703a36a244394b586bfb42ab6b.png)

