当前位置:网站首页>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]
边栏推荐
- Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
- 彻底理解位运算——与(&)、非(~)、或(|)、异或(^)
- 【笔记】《结网:互联网产品经理改变世界》
- Transformer for anomaly detection - instra "painting transformer for anomaly detection"
- CodeIgnier框架实现restful API接口编程
- The United States will provide $25billion in subsidies to encourage chip manufacturers such as Intel to move back to production lines
- MySQL8 基于clone创建主从复制
- 软考高级考试中有五大证书,哪个更值得考?
- adb remount of the / superblock failed: Permission denied
- 中国首枚芯片邮票面世:内置120um超薄NFC芯片
猜你喜欢

远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作

Rust Getting Started Guide (crite Management)

source insight项目导入和使用教程

Transformer for anomaly detection - instra "painting transformer for anomaly detection"

微信公众号授权登录后报redirect_uri参数错误的问题

How does app automated testing achieve H5 testing

这个客制化键盘,秀翻我了~

shared_ptr 和 make_shared 的使用

Cloud computing notes part.2 - Application Management

This customized keyboard turns me on~
随机推荐
Oracle insert数据时字符串中有‘单引号问题
Force buckle 1331. Array serial number conversion
初步学习函数(第3篇博客)
MySQL 8 creates master-slave replication based on Clone
Failed to install app-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
The mystery of ID number
【微信小程序开发】页面导航与传参
The peak rate exceeds 2gbps! Qualcomm first passed 5g millimeter wave MIMO OTA test in China
【笔记】《启示录》:产品经理的实践经验与反省清单
博途1200/1500PLC上升沿下降沿指令编程应用技巧(bool数组)
[网络]跨区域网络的通信学习IPv4地址的分类和计算
Rust Getting Started Guide (modules and engineering structures)
How does app automated testing achieve H5 testing
基于MATLAB的函数拟合
第一次写博客
First blog
英语文章翻译-英语文章翻译软件-免费批量翻译
【经验之谈】关于维修电子设备的几点建议和经验
MATLAB实现的图像分割之边缘检测和连接
Rust Getting Started Guide (rustup, cargo)