当前位置:网站首页>Redis notes
Redis notes
2022-07-28 19:44:00 【wyqgg123】
Global operation
**keys *** : Show all the keys
keys *
* For wildcard
keys *b Show it all b The key at the end
keys a* Show it all a Key at the beginning
dbsize: The number of all keys in the current library
dbsize
select 1 : Switch redis Library operation
select [1,2,3,4,5...] There are optional values in brackets
flushdb: Clear current redis All keys in the Library ( As far as possible need not )
flushdb Why should the current library be cleared
flushall: Clear all redis Key of Library ( As far as possible need not )
flushall
ttl: Key to view the expiration time
ttl [key] Keys that never expire ttl by -1
type: see key Data type of
type [key]
expire: Set the expiration time for a key
expire [key] [ttl] key Key value 、ttl For expiration time
del: Delete one key
del [key] key As the key
character string String operation
set: Set up string Type of key-value, If it already exists key be set Override the old value
set key value [ex second ]/[px millisecond ] [nx]/[xx]ex/px : Validity of cache The default is exnx: key When there is no , To perform operations ( Involving distributed locks )xx: key In existence , Will also perform operations , Update old values Default
get: Get the value of the string type key , If not, return nil, If the value of the obtained key is not a string, an error is returned
get [key]
incr: Self increasing , It can be used directly ,key Automatically created , You don't have to set establish
incrby: Specifies the self increment of the step
incr [key] Self increasing Increase by one each time incrby [key] [step] Self increasing step The specified step size can be negative
decr: Self reduction Similar to self increase
decrby: Specify the step size to self reduce
decr [key]decr [key] [step]
append: hold value Append to key The original value of
append [key] [value] key As the key ,value For the value to be appended . Notice that there is no key You can also successfully create , The value is appended value
getset: Take this key Get the old value of and set the new value
getset [key] [value] key As the key value For the new value
list List operation
lpush: from list On the left ( Head ) Insert elements
lpush [key] [value]
rpop : from list To the right of ( The tail ) Delete the element and return the element value
rpop [key]
llen: Get the number of values stored in the list
llen [key] Get the number of values stored in the list
ltrim Intercept the values in the list
ltrim [key] [start] [stop] Intercept the values in the list by index
lrange: Get the value in the list
lrange [key] [start] [stop] start Index for start end Index for the end
The index is shown in the following table
| Positive index | 0 | 1 | 2 |
|---|---|---|---|
| Values in the list | 2 | 3 | 4 |
| De index | -3 | -2 | -1 |
We can get all the values as :
lrange [key] 0 -1
rpoplpush: Remove the last element of the list , And add the element to another list , Return the element
( It is often used to complete logging )
rpoplpush [key1] [key2] here key1 For the source list key key2 For the target list key
Hash hash operation
hset Set up hash Value
hmset Set up multiple hash Value
hset [key] [field] [value] hold key Medium field The value of the field is set to value, If there is a need key、value Coverage hmset [key] [field1] [value1] [field2] [value2] [field3] [value3] Set up multiple hash Value
hget obtain hash It is specified in key The specified field Value
hmget obtain hash Present in China key The multiple field Value
hgetall Get current key All field And value
hget [key] [field] obtain hash It is specified in key The specified field Value hmget [key] [field1] [field2] [field3] obtain hash Present in China key The multiple field Value hgetall [key] obtain key Middle all field And value
hdel Delete hash Of key Of field
hdel [key] [field] Delete hash Of key Of field Can write multiple field
hlen obtain hash Number of records in , That is to say key Medium field Count
hlen [key]
hexists Get current hash Medium key Of field Whether there is
hexists [key] [field]
hkeys Get current key All field Value
hkeys [key] Get current key All field Value
hvals Get current key All value Value
hkeys [key] Get current key All value Value
hincrby Will specify key The specified field The value of increases by the specified amount
hincrby [key] [field] [step] Will specify key The specified field The value of self incrementing specified step Number
aggregate (set) operation
redis Of set Is an unordered set . In the assembly Duplicate elements are not allowed
set The element can contain at most (2 Of 32 Power -1) Elements .
scene : Store users ID, Non repeating information 、 Luck draw 、 Friend relationship
sadd: towards set Set assignment key Insert elements in
sadd [key] [value1] [value2] [value3] ... towards set Set assignment key Insert elements in
smembers: Returns the specified key Set set All the elements in
smembers [key]
scard Returns the total number of elements in the specified set
scard [key]
srem Delete the specified element of the specified set
srem [key] [value]
spop Randomly delete the elements of the specified set
spop [key] [count] here count The parameter is to pop up a specified number of elements randomly , When count If it is greater than the total number of sets, it means all pops up
sismember: View the specified key Does the element of exist
sismember [key] [value] here key As the key value Specify the element for
smove Put value Delete , And added to the target set
smove [set1] [set2] [value] here set1 For source collection ,set2 Specify the set for ,value For elements that need to be moved
sinter: Find out key1,key2 The intersection of two sets
sinter key1 key2
sunion: Find out key1,key2 The union of two sets
sunion key1 key2
sdiff: Find out key1 key2 Difference set between , Different order , The results are different
sdiff key1 key2
The following picture is the relationship between them , Where union is all a and b The element of removes duplicate values .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-dEx2resb-1631930074017)(C:\Users\ Quick fix \OneDrive\ desktop \ note \ note \image\image-20210917113750198.png)]
Ordered set (set) operation
Elements are not allowed to repeat , Each element is associated with a score , You can sort by its score . Such as mobile phones APP Realization of market software ranking and other requirements .
zadd Assign key Additive elements
zadd [key] [score] [value] here score Is the score
zrem Delete ordered set assignment key The elements of
zrem [key] [value]
zrange Query the ordered set to specify key The elements of ( From small to large )
zrange [key] [start] [end] [withscorces] here strat end and lrange Agreement ,withscorces It can be omitted, and if there is, the score will be displayed , If there is no default, the score will not be displayed .zrange Sort from small to large
**zrevrange ** Query the ordered set to specify key The elements of ( From big to small )
zrevrange [key] [start] [end] [withscorces] The parameters are consistent with the above , Here is the order from big to small
zcard Get the ordered set assignment key Number of elements of
zcard [key]
zscore Get the ordered set assignment key The score of the specified element of
zscore [key] [score]
zcount Get the ordered set assignment key The number of elements between the fractions of
zcount [key] [min] [max] The statistics here are min<=score<=max Number
zremrangebyscore Delete value
zremrangebyscore [key] [min] [max]
边栏推荐
- Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
- leetcode day3 超过经理收入的员工
- 【笔记】《结网:互联网产品经理改变世界》
- VAE: understanding and implementation of variational self encoder
- leetcode day5 删除重复的电子邮箱
- MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
- 助力面板行业创新,FPGA将成屏厂TCON最佳选择?
- Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
- 我的第二次博客——C语言
- The mystery of ID number
猜你喜欢

云计算笔记part.1——系统管理

Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters

shared_ PTR and make_ Use of shared

WPF 实现带蒙版的 MessageBox 消息提示框

冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题

Cell综述:人类微生物组研究中的单细胞方法

navicate修改数据库名的方式

Business visualization - let your flowchart "run" (4. Actual business scenario test)

shared_ptr 和 make_shared 的使用

彻底理解位运算——与(&)、非(~)、或(|)、异或(^)
随机推荐
idea properties文件显示\u不显示中文的解决
MySQL8 Encrypting InnoDB Tablespaces
shared_ PTR and make_ Use of shared
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
leetcode day1 分数排名
Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters
Rust Getting Started Guide (rustup, cargo)
MySQL性能测试工具sysbench学习
MySQL8 基于clone创建主从复制
Getting started with saltstack
Saltstack system initialization
Serial port receiving application ring buffer
11、 学习MySQL UNION 操作符
Left alignment function of Lua language (handwriting)
Design of library management database system
华为入股南京芯视界,布局固态激光雷达芯片领域
MySQL8 Encrypting InnoDB Tablespaces
这个客制化键盘,秀翻我了~
英文翻译意大利语-批量英文翻译意大利语工具免费