当前位置:网站首页>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
边栏推荐
- Redis Distributed Lock
- [Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
- 如何使用 etcd 实现分布式 /etc 目录
- Pytest learning notes (13) -allure of allure Description () and @allure title()
- (十六)ADC转换实验
- 线上开通ETF基金账户安全吗?有哪些步骤?
- C language implementation of sum of two numbers [easy to understand]
- (27) Open operation, close operation, morphological gradient, top hat, black hat
- SQL injection vulnerability (MySQL and MSSQL features)
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
猜你喜欢
英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
How to use etcd to realize distributed /etc directory
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
SQL注入漏洞(Mysql与MSSQL特性)
vulnhub靶场-Hacker_Kid-v1.0.1
ShenYu 网关开发:在本地启用运行
SQL question brushing 586 Customers with the most orders
(17) DAC conversion experiment
Redis 分布式鎖
随机推荐
两数之和c语言实现[通俗易懂]
Report on research and investment prospects of UHMWPE industry in China (2022 Edition)
Jojogan practice
Code example of libcurl download file
Alibaba cloud Li Feifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
redis -- 数据类型及操作
如何写出好代码 — 防御式编程指南
中国一次性卫生用品生产设备行业深度调研报告(2022版)
[C language foundation] 12 strings
Enter wechat applet
Gameframework eating guide
In depth evaluation and development trend prediction report of China's ice cream market (2022 Edition)
Research Report on China's enzyme Market Forecast and investment strategy (2022 Edition)
China sorbitol Market Forecast and investment strategy report (2022 Edition)
Pytest learning notes (13) -allure of allure Description () and @allure title()
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
Petrv2: a unified framework for 3D perception of multi camera images
Replace UUID, nanoid is faster and safer!
官宣!香港科技大学(广州)获批!
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速