set和get是Redis中最简单的两个命令,它们实现的功能和编程语言中的读写变量相似,如key=“hello”在redis中是这样表示的。
127.0.0.1:6379> set key hello
OK
127.0.0.1:6379> get key
"hello"
127.0.0.1:6379> incr num
(integer) 1
127.0.0.1:6379> get num
"1"
127.0.0.1:6379> decr num
(integer) 0
127.0.0.1:6379> get num
"0"
127.0.0.1:6379> incrby num 5
(integer) 5
127.0.0.1:6379> get num
"5"
127.0.0.1:6379> decrby num 3
(integer) 2
127.0.0.1:6379> get num
"2"
127.0.0.1:6379> incrbyfloat num 3.1
"5.1"
127.0.0.1:6379> get num
"5.1"
127.0.0.1:6379> set key hello
OK
127.0.0.1:6379> get key
"hello"
127.0.0.1:6379> append key " world!"
(integer) 12
127.0.0.1:6379> get key
"hello world!"
UTF-8的编码长度为3,GBK的编码长度为2。
127.0.0.1:6379> strlen key
(integer) 12
127.0.0.1:6379> set key "你好"
OK
127.0.0.1:6379> strlen key
(integer) 6
127.0.0.1:6379> mset key1 1 key2 2 key3 3
OK
127.0.0.1:6379> mget key1 key2 key3
1) "1"
2) "2"
3) "3"
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有