当前位置:网站首页>Common redis data types and application scenarios
Common redis data types and application scenarios
2022-07-05 15:04:00 【Back end regular developers】
List of articles
Five common data types : character string string, list list, hash hash, aggregate set, Ordered set sorted set
1. character string string:
The string type is Redis The most basic data storage type in , It's a sequence of bytes , He was in Redis Is binary safe , This means that the type can accept data in any format , It's standard key-value, It's usually used to store strings , Integers and floating point numbers .Value The maximum data length that can be accommodated is 512MB
Application scenarios : A very common scenario is used to count the number of website visits , Number of people currently online, etc .incr command (++ operation )
2. list list:
Redis The list allows users to push or pop elements from both ends of the sequence , A list is an ordered, repeatable sequence of multiple string values , It's a list structure , So the time complexity of adding elements to both ends of the list is 0(1), The closer you get to both ends, the faster . This means even a list of tens of millions of elements , To obtain the head or tail of 10 Records are also very fast .List The maximum number of elements that can be contained in is 4294967295.
Application scenarios :1. The latest news leaderboard .2. Message queue , To complete the message exchange between multiple programs . It can be used push The operation will cause the task to exist list in ( producer ), Then the thread is in use pop The operation takes the task out for execution
3. hash hash:
Redis Hash in can be regarded as having String key and String value Of map Containers , Multiple key-value Store in a key in . every last Hash Can be stored 4294967295 Key value pairs .
Application scenarios : Such as storage 、 Read 、 Modify user properties (name,age,pwd etc. )
4. aggregate set:
Redis The set of is unordered and unrepeatable , Just like the list , When performing insert and delete and determining whether an element exists , Efficiency is very high . The biggest advantage of a set is that it can perform intersection, union and subtraction operations .Set The maximum number of elements that can be included is 4294967295.
Application scenarios :1. Use intersection to find common friends .2. Using uniqueness , You can count all the independent websites you visit IP.3. Friends recommend according to tag Find the intersection , Greater than one threshold( Of the critical value ) You can recommend .
5. Ordered set sorted set:
and set It's like , It's a collection of strings , Do not allow duplicate members to appear in a set in . The difference between them is that each member of the ordered set will have a score (score) Associated with it ,Redis It's the scores that sort the members of a collection from small to large . Although the members in the ordered set must be guards , But the score (score) But it can be repeated .
Application scenarios : Can be used for a large online game ranking , Whenever a player's score changes , It can be executed zadd Update player scores (score), After that, we passed zrange Get some points top ten User information for .
Last , There's another one right key General operation of , All data types can be used
Reprinted from :https://blog.csdn.net/m0_54425879/article/details/116783792
边栏推荐
猜你喜欢
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
Under the crisis of enterprise development, is digital transformation the future savior of enterprises
Fr exercise topic --- comprehensive question
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
B站做短视频,学抖音死,学YouTube生?
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
爱可可AI前沿推介(7.5)
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
超级哇塞的快排,你值得学会!
随机推荐
当代人的水焦虑:好水究竟在哪里?
Ten billion massage machine blue ocean, difficult to be a giant
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
Anaconda uses China University of science and technology source
【華為機試真題詳解】歡樂的周末
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
ICML 2022 | 探索语言模型的最佳架构和训练方法
MySQL----函数
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
用 Go 跑的更快:使用 Golang 为机器学习服务
Magic methods and usage in PHP (PHP interview theory questions)
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
超级哇塞的快排,你值得学会!
裁员下的上海
MongDB学习笔记
Interview shock 62: what are the precautions for group by?
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发