当前位置:网站首页>Redis basic usage 1
Redis basic usage 1
2022-06-10 14:13:00 【tnan2522】
stay redis There is 5 Type of data string: character string hash: hash ( Personal understanding is python Medium dict)list: list set: aggregate zset: Ordered set
Delete
del key
string
string character string , With key - value For storage ,
set name lowang set Set a key value pair
mset name laowang age 10 sex male mset Set key value pairs in batch
mget name age sex mget Get key value pairs in batch
getrange name 1 2 obtain value And cut
getset name laoli Get it name After setting name Value
setex aaa 10 bbb Set up aaa value The value of is bbb The expiration time is 10 second
setnx name laoluo When name The key value pair is set only when the value does not exist name laoluo This avoids the problem of overwriting values
strlen name Get current name Corresponding value Length of string
incr age Can give current key Corresponding value Value number +1 The storage format is string , But you can +1 Of , If stored in a non numeric format , That would be a mistake
append age 110 If key non-existent , Then we will add key Key value pair , If key There is , Then we will value Add to key Corresponding value Behind
hash
hash Dictionaries stay redis In storage , Store in the form of a dictionary ,
hset dict name laowang Set up a dictionary , Only one key value pair can be set
hmset dict name laowang age 18 sex male Batch set Dictionary ,key yes dict value yes {
"name": " Lao Wang ", "age": "18", "sex": " male "}
hget dict name Get the corresponding key-value You can only get one
hmget dic name id age It can be obtained in batches value
hgetall dict Get all key and value
hexists dict name To get in dict In the dictionary key Whether there is , If there is , return 1, There is no return 0
hkeys dict obtain dict All of the key
hsetnx dict name laowangba If dict Does not exist in the key name , Then set , If there is , Then do not set
hvals dict obtain dict All in Of value value
list
lpush lists laowang laoli laozhao add to 3 individual value It's worth it lists In the list , The way to add this is to insert forward , The last data is at the top
llen lists View how many data there are in the current list
lindex lists 0 Get list number 0 Data , Negative numbers can also be used (-1) This is the last data in the list
rpush lists laoluo Add data to the far right of the list , Be similar to python List in append() Add to the end
rpoplpush lists lists1 take lists The last data in the list is removed and added to lists1 In the list
lpop lists Delete the first element data in the list
blpop lists 10 Delete the first element in the list , If there is no data in the list , Will wait for 10 second , stay 10 If any data is added, it will be deleted , No, just wait 10 Seconds to exit the command
lrem lists 1 aaaa Start at the far left of the list , Delete a value of aaaa The data of , If count by 0 when , All values in the list will be aaaa Data deletion , If count If it's negative , Data will be found from the right to the front for deletion , The deleted value is the absolute value of a negative number
ltrim lists 1 -1 take 1 To -1 Data retention between , Delete data outside this interval
linsert lists after eee ggg Insert data in eee Insert... At the back , after( Insert after element )before ( Insert before element )
lset lists 0 abcdefg Modify the subscript in the list as 0 Of value Value
set
set Can't repeat
sadd set laowang laoli 20 nan Set up set aggregate , add to value laowang laoli etc. value
sunion set obtain set aggregate All in Of value
sunion set set1 duplicate removal , Get the data in two sets , If there are duplicates , Only once
scard set Get the number of elements in the collection , When the set does not exist, it returns 0
srandmember set 10 Random access set In the collection 10 Elements , When insufficient 10 When it's time , Get all
sinter set Get all the data
sinter set set1 Get data common to both sets
srem set 10 20 laowang Delete... From the collection 10 20 laowang value value , If you don't have these elements in the collection , So it will return 0 If the value exists 1 individual , Then return to 1,( Only one... Is deleted )
smove sets set 20 take set1 Medium 20 value Move add to set Set the last
sismember set 20 Inquire about set Is there any 20 This element
sdiff set set1 Get the elements in the first set that are not in the second set
sdiffstore sets set set1 The elements in the first set that are not in the second set sadd To sets Collection
spop set Random deletion returns a data
zset
zadd myset 1 laowang 2 laoli get Ordered set myset Add data 1 Lao Wang This 1 It's sort , The smaller the value, the more forward the row , When the sorting values are the same redis Sort automatically , These same values are automatically set internally value Sort
zrange myset 0 -1 Loop through the values of the current set , Get by subscript , stay redis in , If the subscript is negative, it is from right to front ,-1 On behalf of the last
zrange myset 0 -1 withscores Loop the current set value and sort value ( It's the weight ),
zremrangebyrank myset 0 1 Remove subscript 0-1 Data between
zcard myset Get the number of elements in the collection , When the list does not exist, it returns 0
zrem myset aaa bbb ccc Delete multiple data
zrank myset ccc obtain ccc The index of
zremrangebyscore myset 4 5 Delete the score in 4 and 5 All values between
zcount myset 0 100 Get points in 0 - 100 The total number of all values between
边栏推荐
- Is it safe to open an account in qiniu
- 互联网公司研发效能团队为啥必须独立?何时独立?
- 2022山东省安全员C证复训题库及在线模拟考试
- How to build Haojing technology when the computing power network is brought into reality?
- 2022 practice questions and online simulation test for the third batch of Guangdong Provincial Safety Officer a certificate (principal)
- Implementation of VGA protocol based on FPGA
- Kotlin bubbling algorithm, Gaud map filters out the data whose distance between two points is less than 50, and does not repeat the display
- [cloud computing] what is the relationship between a multi cloud management platform and a public cloud?
- 2022广东省安全员A证第三批(主要负责人)考试练习题及在线模拟考试
- Kotlin 冒泡算法 ,高德地图 过滤掉两点之间距离小于50的数据,不重复显示
猜你喜欢

The interview at the big factory was held at 10:00 a.m. and came out at 10:09 a.m. the question was really too

【笔记】74HC573的一些记录

Shutter wrap button bottomnavigationbar learning summary 4

2022广东省安全员A证第三批(主要负责人)考试练习题及在线模拟考试

Simulated 100 questions and online simulated examination for safety production management personnel of hazardous chemical production units in 2022

Flutter listview, column, row learning personal summary 2

大厂面试上午10:00面试,10:09就出来了 ,问的实在是太...

C#多线程学习笔记一

大厂必备的40个方法论

数仓的基本概念
随机推荐
基于FPGA的VGA协议实现
Gorm设置外键
Binary tree and figure 1
在启牛开户安全么
Primary master-slave table integration process development process
Recyclerview multi layout writing method, "my" and "personal center" page classic writing method demonstration
C#多线程学习笔记三
How to solve the problem that vmware tools are grayed out when VMware Workstation is installed
[solution] each time the trained model is loaded, the generated vector will be different
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
Anaconda installs opencv (CV2) and uses it in the jupyter notebook
D:\setup Exe could not find the problem
[original] poi 5 X xssf and HSSF use custom font colors
UE5如何將屏幕坐標轉為世界坐標和世界方向
什么是CAS 以及 CAS 中的 ABA 问题
Simulated 100 questions and online simulated examination for safety production management personnel of hazardous chemical production units in 2022
Cell asynchronously invokes method change records
[discrete mathematics review series] v. some special charts
one
Flutter learning personal summary 1