当前位置:网站首页>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.
边栏推荐
- 深拷貝 事件總線
- Performance tuning project case
- [ybtoj advanced training guide] similar string [string] [simulation]
- Differences between nodes and sharding in ES cluster
- Intel internal instructions - AVX and avx2 learning notes
- [ybtoj advanced training guidance] judgment overflow [error]
- Enhance network security of kubernetes with cilium
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
- Go学习笔记—多线程
- (C language) octal conversion decimal
猜你喜欢

Sparkcontext: error initializing sparkcontext solution

Distributed machine learning framework and high-dimensional real-time recommendation system

Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students

浏览器存储方案

AI中台技术调研

Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)

Sort---

模块化 CommonJS ES Module

记录一下MySql update会锁定哪些范围的数据

Find the common ancestor of any two numbers in a binary tree
随机推荐
Drools terminates the execution of other rules after executing one rule
Simple use of drools decision table
Anti shake throttle
Jenkins user rights management
Maximum profit of jz63 shares
"As a junior college student, I found out how difficult it is to counter attack after graduation."
drools动态增加、修改、删除规则
SparkContext: Error initializing SparkContext解决方法
包管理工具
ThreadLocal的简单理解
CDH6之Sqoop添加数据库驱动
When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
Post request body content cannot be retrieved repeatedly
深拷貝 事件總線
Record the range of data that MySQL update will lock
Lombok common annotations
计数类DP AcWing 900. 整数划分
post请求体内容无法重复获取
JSON序列化 与 解析
LeetCode—剑指 Offer 37、38