当前位置:网站首页>Redis-02. Redis command
Redis-02. Redis command
2022-07-05 06:28:00 【Cold leaves elegant_】
Redis-02.Redis command
1.Redis Data structure introduction
Redis yes - individual key-value The database of , key- Like String type , however value There are many types of :
Basic types :
- String:HelloWorld
- Hash:{name:“Jack”, age:12}
- List:[A->B->C->B]
- Set:{A, B, C}
- SortedSet:{A:1, B:2, C:3}
Special type :
- GEO:{A:(111.1, 22.2)}
- BitMap:0011010101100101
- HyperLog:0011010101100101
2.Redis General Command
General instructions are partial data types , Can be used , Common are :
- KEYS: View all that match the template key( It is not recommended to use... On production environment equipment ,redis Single thread , Blocking occurs when the amount of data is large )
- DEL: Delete a specified key
- EXISTS: Judge key Whether there is
- EXPIRE: Give me a key Set expiration date , At the expiration of the validity period, the key Will be automatically deleted
- TTL: View one KEY The remaining validity period of (-1 For permanent validity ,-2 Is invalid )
3.String type
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.
String Common commands are :
- SET: Add or modify an existing - individual 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
4.Key Hierarchical structure
key Structure
Redis Of key Multiple words are allowed to form a hierarchy , Use... Between multiple words ’:' separate , The format is as follows :
Project name : Business name : type :id
This format is not fixed , You can delete or add entries according to your own needs
if value It's a java object , For example, one user object , You can serialize the object as JSON String is stored :
key | value |
---|---|
project1:user:1 | {“id”:1,“name”:“Sam”,age:22} |
5.Hash type
Hash type , Also called hash , Its value It's one 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 :
key | value |
---|---|
project1:user:1 | {“id”:1,“name”:“Sam”,age:22} |
Hash Structure can store each field in the object independently , You can do this for a single field CRUD:
key | filed | value |
---|---|---|
project1:user:1 | id | 1 |
name | Sam | |
age | 22 |
Hash Common commands are :
- 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: Give Way - individual hash type key The field value of is incremented and the step size is specified
- HSETNX: Add one - individual hash Type of key Of field value , The premise is this field non-existent , Otherwise, do not execute
List type
Redis Medium List The type and Java Medium LinkedList similar , You can view it 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 .
List Common commands are :
- 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 to the first... On the right side of the list - Elements
- LRANGEkeystarend: 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 null
Set type
Redis Of Set Structure and Java Medium HashSet similar , You can view it as - - individual value by nul Of HashMap. Because it is also a hash surface , Therefore, it has the ability to communicate with HashSet Similar features :
- Element is not repeatable
- Quick search
- Support intersection 、 Combine 、 Difference set and other functions
Set Common types of commands :
- SADD key member … : towards set Add one more - Elements or elements
- 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
SortedSet type
Redis Of SortedSet yes - - Sortable set aggregate , And Java in Of TreeSet Some similar , But the underlying data structure is very different .SortedSet in
Every - - Each element has - individual 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 .
SortedSet Common commands are :
- 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 One of the specified elements 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
- ZDIFF、ZINTER、 ZUNION: Difference set 、 intersection 、 Combine
notes : 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
Reference material :
- https://www.bilibili.com/video/BV1cr4y1671t?p=16&spm_id_from=pageDriver
边栏推荐
- vsCode创建自己的代码模板
- TypeScript入门
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- 栈 AcWing 3302. 表达式求值
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Game theory acwing 891 Nim games
- Chart. JS - Format Y axis - chart js - Formatting Y axis
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- Idea debug failed
- H5 module suspension drag effect
猜你喜欢
Bit of MySQL_ OR、BIT_ Count function
容斥原理 AcWing 890. 能被整除的数
Single chip computer engineering experience - layered idea
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
博弈论 AcWing 893. 集合-Nim游戏
‘mongoexport‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
5.Oracle-錶空間
Redis-01.初识Redis
Operator priority, one catch, no doubt
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
随机推荐
H5内嵌App适配暗黑模式
June 29, 2022 daily
Niu Mei's math problems
微信小程序路由再次跳转不触发onload
MySQL advanced part 2: the use of indexes
Winter vacation water test 1 Summary
H5 module suspension drag effect
将webApp或者H5页面打包成App
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
Vant Weapp SwipeCell设置多个按钮
LeetCode 0107. Sequence traversal of binary tree II - another method
Stack acwing 3302 Expression evaluation
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
WordPress switches the page, and the domain name changes back to the IP address
2048 project realization
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
What is socket? Basic introduction to socket
Bit of MySQL_ OR、BIT_ Count function
高斯消元 AcWing 884. 高斯消元解异或線性方程組