当前位置:网站首页>Redis -- data type and operation
Redis -- data type and operation
2022-07-01 17:30:00 【zyanwei2018】
Remote connection
redis-cli -h host -p port -a password
# Chinese garbled
--raw
Basic data type
string
- String
# establish key
> set name zhangsan
OK
# obtain key
> get name
"zhangsan"
# Set multiple items and get multiple items at the same time
> set name zhangsan
> set age 18
> mset city wuhan country China
> mget name age city country
1) "zhangsan"
2) "18"
3) "wuhan"
4) "China"
# Delete key
> del name
(integer) 1
> get name
(nil)
# Check for presence
> exists name
(integer) 1
> exists age
(integer) 0
- Numeric String
> set n 11
OK
> get n
"11"
# Add one... In turn
> incr n
(integer) 12
# One in turn
> decr n
(integer) 11
# Gat fixed value
> incrby n 10
(integer) 14
# Subtract a specific value
> decrby n 10
(integer) 4
set
string Unordered collection of type , The bottom is HashTable data structure ,
String elements are unordered , And can't repeat
# add to
> sadd friends zhangsan
(integer) 1
> sadd friends lisi
(integer) 1
# see
> smembers friends
1) "lisi"
2) "zhangsan"
# Remove the specified value
> srem friends lisi
# Random delete
> spop friends
"zhangsan"
# Determine whether an element exists
> sismember friends zhangsan
(integer) 1
zset
# add to
> zadd country 1 China
(integer) 1
> zadd country 1 UK
(integer) 1
# see
> zrange country 0 -1
1) "China"
2) "UK"
> zrange country 0 -1 withscores
1) "China"
2) "1"
3) "UK"
4) "1"
# Remove the specified value
> zrem country UK
(integer) 1
List
# Insert from the left
> lpush rlist zhangsan lisi
(integer) 2
> lpush rlist wangwu
(integer) 3
# Insert from the right
> rpush rlist chenliu
(integer) 4
# see
> lrange rlist 0 -1
1) "wangwu"
2) "lisi"
3) "zhangsan"
4) "chenliu"
# Delete from the left
> lpop rlist
"wangwu"
# Delete from the left
> rpop rlist
"chenliu"
> lrange rlist 0 -1
1) "lisi"
2) "zhangsan"
# The view index is 1 Of key value
> lindex rlist 1
"zhangsan"
# Change the index to 1 Of key value
> lset rlist 1 lili
OK
> lrange rlist 0 -1
1) "lisi"
2) "lili"
Hash
Be similar to Java Medium Map, It's a String Type of field and value Mapping table ( Key value pair set ), And it is especially suitable for storing objects
# hset
> hmset user name zhangsan age 18 sex male
OK
# hget
> hget user name
"zhangsan"
# hmget
> hmget user name
1) "zhangsan"
# Check all values
hkeys user
1) "name"
2) "age"
3) "sex"
4) "height"
# modify
> hset user height 145
(integer) 0
> hmget user height
1) "145"
- Expiration time
- expire: Set expiration time
- ttl: Get expiration time , return -1 Indicates no settings ,-2 Indicates that the data does not exist
> set name zhangsan
OK
> expire name 20
(integer) 1
> ttl name
(integer) 4
> ttl name
(integer) -2
边栏推荐
- (28) Shape matching based on contour features
- Vulnhub range hacksudo Thor
- SQL question brushing 586 Customers with the most orders
- Radhat builds intranet Yum source server
- Hidden Markov model (HMM): model parameter estimation
- Redis Distributed Lock
- 存在安全隐患 起亚召回部分K3新能源
- libcurl下载文件的代码示例
- [C language foundation] 12 strings
- Why should you consider using prism
猜你喜欢

(17) DAC conversion experiment

Gameframework eating guide

ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing

【Try to Hack】vulnhub DC4

How to use etcd to realize distributed /etc directory

整形数组合并【JS】

Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!

Machine learning 11 clustering, outlier discrimination

英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放

Why should you consider using prism
随机推荐
Leetcode records - sort -215, 347, 451, 75
Gameframework eating guide
中国酶制剂市场预测与投资战略研究报告(2022版)
Pytest learning notes (13) -allure of allure Description () and @allure title()
期货先锋这个软件正规吗安全吗?选择哪家期货公司更安全?
中国乙腈市场预测与战略咨询研究报告(2022版)
SQL injection vulnerability (MySQL and MSSQL features)
In depth Research Report on China's disposable sanitary products production equipment industry (2022 Edition)
拼接字符串,得到字典序最小的结果
ACL 2022 | 分解的元学习小样本命名实体识别
Object. fromEntries()
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
中国生物降解塑料市场预测与投资战略报告(2022版)
中国PBAT树脂市场预测及战略研究报告(2022版)
Judge whether a binary tree is a balanced binary tree
多线程使用不当导致的 OOM
Replace UUID, nanoid is faster and safer!
DNS
Research Report on China's enzyme Market Forecast and investment strategy (2022 Edition)
ShenYu 网关开发:在本地启用运行