当前位置:网站首页>Five basic data structures of redis
Five basic data structures of redis
2022-07-27 04:13:00 【crazyK.】
Catalog
One 、String
1. brief introduction
String type , That is string type , yes Redis The simplest storage type in .
Its value Is string , However, depending on the format of the string , Can be divided into 3 class :
string: Normal string
int: Integer types , Can do self increasing 、 Since the reduction of operating
float: Floating point type , Can do self increasing 、 Since the reduction of operating
Either format , The bottom layer is stored in the form of byte array , It's just that the coding method is different . The maximum space of string type cannot exceed 512m.
2. Common commands
SET: Add or modify an existing String Key value pairs of type
GET: according to key obtain String Type of value
MSET: Batch add multiple String Key value pairs of type
MGET: According to the multiple key Get multiple String Type of value
INCR: Let an integer key Self increasing 1
INCRBY: Let an integer key Increment and specify the step size , for example :incrby num 2 Give Way num Value on the 2
INCRBYFLOAT: Increment a floating-point number and specify the step size
SETNX: Add one String Key value pairs of type , The premise is this key non-existent , Otherwise, do not execute
SETEX: Add one String Key value pairs of type , And specify the validity period
3. Examples of use


Two 、Hash
1. brief introduction
Hash type , Also called hash , Its value It's an unordered Dictionary , Be similar to Java Medium HashMap structure . String Structure is to serialize an object into JSON Store after string , It is inconvenient to modify a field of an object :

Hash Structure can store each field in the object independently , You can do this for a single field CRUD:

2. Common commands
HSET key field value: Add or modify hash type key Of field Value
HGET key field: Get one hash type key Of field Value
HMSET: Batch add multiple hash type key Of field Value
HMGET: Get more than one in batch hash type key Of field Value
HGETALL: Get one hash Type of key All of them field and value
HKEYS: Get one hash Type of key All of them field
HVALS: Get one hash Type of key All of them value
HINCRBY: To make a hash type key The field value of is incremented and the step size is specified
HSETNX: Add one hash Type of key Of field value , The premise is this field non-existent , Otherwise, do not execute
3. Examples of use



3、 ... and 、List
1. brief introduction
Redis Medium List The type and Java Medium LinkedList similar , It can be regarded as a two-way linked list structure . It can support both forward retrieval and reverse retrieval .
Characteristics are also related to LinkedList similar :
Orderly Elements can be repeated Insert and delete fast The query speed is average
Often used to store an ordered data , for example : Friends circle the likes list , Comment list, etc .
2. Commonly used instructions
LPUSH key element ... : Insert one or more elements to the left of the list
LPOP key: Remove and return the first element to the left of the list , No return nil
RPUSH key element ... : Insert one or more elements to the right of the list
RPOP key: Remove and return the first element to the right of the list
LRANGE key star end: Returns all elements within a range of subscripts
BLPOP and BRPOP: And LPOP and RPOP similar , Just wait for the specified time when there is no element , Not directly back nil
3. Examples of use

Four 、Set
1. brief introduction
Redis Of Set Structure and Java Medium HashSet similar , It can be seen as a value by null Of HashMap. Because it is also a hash surface , Therefore, it has the ability to communicate with HashSet Similar features : disorder Element is not repeatable Quick search Support intersection 、 Combine 、 Difference set and other functions
2. Common commands
SADD key member ... : towards set Add one or more elements to
SREM key member ... : remove set The specified element in
SCARD key: return set The number of elements in
SISMEMBER key member: Determine whether an element exists in set in
SMEMBERS: obtain set All elements in
SINTER key1 key2 ... : seek key1 And key2 Intersection
SDIFF key1 key2 ... : seek key1 And key2 The difference between the set
SUNION key1 key2 ..: seek key1 and key2 Union
3. Examples of use

5、 ... and 、ZSet
1. brief introduction
Redis Of SortedSet It's a sortable set aggregate , And Java Medium TreeSet Some similar , But the underlying data structure is very different .SortedSet Each element in the has a score attribute , Can be based on score Attribute to sort elements , The underlying implementation is a jump table (SkipList) Add hash surface .
SortedSet It has the following characteristics : Sortable Elements do not repeat Fast query speed
because SortedSet Sortable properties of , Often used to implement functions like leaderboards .
2. Common commands
ZADD key score member: Add one or more elements to sorted set , If it already exists, update its score value
ZREM key member: Delete sorted set A specified element in
ZSCORE key member : obtain sorted set Of the specified element in score value
ZRANK key member: obtain sorted set The ranking of the specified elements in
ZCARD key: obtain sorted set The number of elements in
ZCOUNT key min max: Statistics score The number of all elements whose values are within a given range
ZINCRBY key increment member: Give Way sorted set The specified element in is incremented , The step size is the specified increment value
ZRANGE key min max: according to score After ordering , Get the elements within the specified ranking range
ZRANGEBYSCORE key min max: according to score After ordering , Get specified score Elements in scope
Be careful : All rankings are in ascending order by default , If you want to order in descending order, in the... Of the command Z Add later REV that will do
3. Examples of use

边栏推荐
- Is VR panorama just needed now? After reading it, you will understand
- Interview question 16.05 factorial mantissa
- leetcode每日一练:将句子排序
- 【愚公系列】2022年7月 Go教学课程 018-分支结构之switch
- 【obs】动态码率:码率估算
- Skywalking distributed system application performance monitoring tool - medium
- 356页14万字高端商业办公综合楼弱电智能化系统2022版
- Want to get the Apache official domain name mailbox? Exclusive interview with Apache linkis five new committers to tell you how to do it
- 真正意义上的数字零售应当具有更加丰富的内涵和意义
- 0726~简历梳理面试总结
猜你喜欢

11.zuul路由网关

Parallels Desktop启动虚拟机“操作失败”问题解决

E-commerce system combined with commodity spike activities, VR panorama continues to bring benefits

Redis (IX) - redis distributed lock

【MySQL系列】MySQL索引事务

什么是动画效果?什么是过渡效果?

科目三: 济南章丘五号线

科目三: 济南章丘二号线

288页18万字智能化校园总体设计 目录

2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units
随机推荐
【愚公系列】2022年7月 Go教学课程 018-分支结构之switch
Subject 3: Jinan Zhangqiu line 3
SkyWalking分布式系统应用程序性能监控工具-中
Maximum nesting depth of parentheses
括号的最大嵌套深度
288页18万字智能化校园总体设计 目录
ArrayList与LinkedList区别
Detailed analysis of trajectory generation tool in psins toolbox
ApacheCon Asia 预热直播之孵化器主题全回顾
mysql中case when返回多个字段处理方案
Subject 3: Jinan Zhangqiu line 6
Application of one-dimensional array
每日一题:奇偶树
【OBS】circlebuf
暑假加餐|有钱人和你想的不一样(第5天)+电力系统潮流仿真(文档和Matlab代码)
基于风能转换系统的非线性优化跟踪控制(Matlab代码实现)
Lixia action | Yuanqi Digitalization: existing mode or open source innovation?
Chapter 5 decision tree and random forest practice
VR全景人淘金“小心机”(上)
科目三: 济南章丘五号线