当前位置:网站首页>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
边栏推荐
- (12) About time-consuming printing
- Kia recalls some K3 new energy with potential safety hazards
- MySQL learning summary
- The difference between the lazy mode of singleton mode and the evil mode
- Introduction to software engineering - Chapter 6 - detailed design
- DNS
- 在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
- [wrung Ba wrung Ba is 20] [essay] why should I learn this in college?
- 《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
- Soft test network engineer full truth simulation question (including answer and analysis)
猜你喜欢

Cookies and session keeping technology

Detailed explanation of string's trim() and substring()

【C语言基础】12 字符串

ACL 2022 | decomposed meta learning small sample named entity recognition

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

(16) ADC conversion experiment

整形数组合并【JS】

Yyds dry inventory MySQL RC transaction isolation level implementation

String的trim()和substring()详解

In aks, use secret in CSI driver mount key vault
随机推荐
(十七)DAC转换实验
ACL 2022 | decomposed meta learning small sample named entity recognition
Openlayers customize bubble boxes and navigate to bubble boxes
In depth evaluation and development trend prediction report of China's ice cream market (2022 Edition)
Computed property “xxx“ was assigned to but it has no setter.
Enter wechat applet
libcurl下载文件的代码示例
Report on Market Research and investment prospects of ammonium dihydrogen phosphate industry in China (2022 Edition)
[pyg] document summary and project experience (continuously updated
MySQL learning summary
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求
荣威 RX5 的「多一点」产品策略
Countdownlatch blocking wait for multithreading concurrency
unity3d扩展工具栏
ShenYu 网关开发:在本地启用运行
【C语言补充】判断明天是哪一天(明天的日期)
Introduction to software engineering - Chapter 6 - detailed design
存在安全隐患 起亚召回部分K3新能源
vulnhub靶场-Hacker_Kid-v1.0.1