当前位置:网站首页>What data types does redis have and their application scenarios
What data types does redis have and their application scenarios
2022-07-02 12:37:00 【Squat in the corner and count the ants】
One 、 data type :
String、Hash、List、Set、zSet、HyperLogLog、Geo、Pub/Sub
Two 、 Application scenarios :
1、String( character string )
set、setnx、get、decr、incr、mget
Cache layer (mysql Storage layer ,redis Make cache layer )、 Counter ( For example, the number of videos played , Blog views, etc )、 share session、 How many seconds can the SMS verification code be obtained again
2、Hash(hashMap)
hset、hget、hdel、hlen、hexists、hkeys、hvals、hgetall
Store user information
3、List( Double linked list )
lpush、rpush、lpop、rpop、brpop、lrange、lindex、len、lrem
Attention list 、 Fans list
Message queue :
lpush + lpop = Stack
lpush + rpop = queue
lpush + ltrim = Collection co., LTD.
lpush + brpop = Message queue
It can also be used list Of lrange Realize simple paging query
4、Set
sadd、spop、sismember、srem、sunion、sdiff
Set elements do not repeat , Support addition, deletion, modification and query in the collection 、 intersect 、 Combine 、 Difference set 、 Collection
(1) label
User interest tags tag, Other preferences of people with the same tag can be obtained according to the tag , For example, novel recommendations when reading novels , And video recommendations when watching videos
(2) Generate random number ( Luck draw )
(3) Social needs
5、SortedSet
zadd、zcard、zscore、zrank、zrem、zincrby、zrange
Set elements do not repeat , And it can be sorted , according to csore Sort
(1) The list
Video playback list 、 Likes list, etc
notes :redis key The design of the
Use colons for segmented storage , The hierarchy is clear , It is conducive to data analysis on the client
6、HyperLogLog
pfadd、pfcount
HyperLogLog Fixed occupied space ,12k about , It can be estimated that about 2^64 The cardinal number of elements
Count the user visits of a page
Although it can also be used set do , But there are tens of millions of data , It will be a very big expense
7、geo
Geoadd: Add coordinates of a geographic location
Geopos: Get the coordinates of a geographical location
Geodist: Gets the distance between two geographical locations
GEORADIUS: Gets the set of geographical locations within a specified range based on the given geographical location coordinates
GEOHASH: To obtain a geographic location geohash value
For example, meituan takeout shows how far away the business is from you , The longitude and latitude coordinates of merchants can be stored in the database , adopt redis Of geo Calculate the distance
8、Pub/Sub
Publish subscribe , There are few practical application scenarios , but redis The sentinel mechanism of , In fact, one of them is useful Pub/Sub.
边栏推荐
- Bom Dom
- Enhance network security of kubernetes with cilium
- What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
- lombok常用注解
- The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
- Simple use of drools decision table
- 寻找二叉树中任意两个数的公共祖先
- How to write a pleasing English mathematical paper
- Differences between nodes and sharding in ES cluster
- Simple understanding of ThreadLocal
猜你喜欢
堆(優先級隊列)
Embedded Software Engineer career planning
堆(优先级队列)
Deep understanding of P-R curve, ROC and AUC
Writing method of then part in drools
High performance erasure code coding
中国交通标志检测数据集
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
Go学习笔记—多线程
WSL 2 will not be installed yet? It's enough to read this article
随机推荐
(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
寻找二叉树中任意两个数的公共祖先
Jenkins voucher management
Mysql database foundation
Find the common ancestor of any two numbers in a binary tree
drools执行String规则或执行某个规则文件
LeetCode—<动态规划专项>剑指 Offer 19、49、60
H5 to app
CDA data analysis -- Introduction and use of aarrr growth model
Simple understanding of ThreadLocal
Gaode map test case
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
Bom Dom
Go学习笔记—多线程
Shuttle encapsulated AppBar
ThreadLocal的简单理解
drools执行完某个规则后终止别的规则执行
使用Sqoop把ADS层数据导出到MySQL