redis中的string相关的部分命令

redis命令手册

redis中文官网查看文档

挨个进行输出调试

Redis Setnx 命令

Redis Getrange 命令

Redis Mset 命令

redis 127.0.0.1:6379> MSET key1 "Hello" key2 "World"
OK
redis 127.0.0.1:6379> GET key1
"Hello"
redis 127.0.0.1:6379> GET key2
1) "World"

Redis Setex 命令

redis 127.0.0.1:6379> SETEX mykey 60 redis
OK
redis 127.0.0.1:6379> TTL mykey
60
redis 127.0.0.1:6379> GET mykey
"redis

Redis SET 命令

Redis Get 命令

Redis Getbit 命令

 对不存在的 key 或者不存在的 offset 进行 GETBIT, 返回 0
 
redis> EXISTS bit
(integer) 0
 
redis> GETBIT bit 10086
(integer) 0
 
 
# 对已存在的 offset 进行 GETBIT
 
redis> SETBIT bit 10086 1
(integer) 0
 
redis> GETBIT bit 10086
(integer) 1

Redis Setbit 命令

redis> SETBIT bit 10086 1
(integer) 0
 
redis> GETBIT bit 10086
(integer) 1
 
redis> GETBIT bit 100   # bit 默认被初始化为 0
(integer) 0

Redis Decr 命令

# 对存在的数字值 key 进行 DECR
 
redis> SET failure_times 10
OK
 
redis> DECR failure_times
(integer) 9
 
 
# 对不存在的 key 值进行 DECR
 
redis> EXISTS count
(integer) 0
 
redis> DECR count
(integer) -1
 
 
# 对存在但不是数值的 key 进行 DECR
 
redis> SET company YOUR_CODE_SUCKS.LLC
OK
 
redis> DECR company
(error) ERR value is not an integer or out of range

Redis Decrby 命令

# 对已存在的 key 进行 DECRBY
 
redis> SET count 100
OK
 
redis> DECRBY count 20
(integer) 80
 
 
# 对不存在的 key 进行DECRBY
 
redis> EXISTS pages
(integer) 0
 
redis> DECRBY pages 10
(integer) -10

Redis Strlen 命令

# 获取字符串的长度
 
redis> SET mykey "Hello world"
OK
 
redis> STRLEN mykey
(integer) 11
 
 
# 不存在的 key 长度为 0
 
redis> STRLEN nonexisting
(integer) 0

Redis Msetnx 命令

# 对不存在的 key 进行 MSETNX
 
redis> MSETNX rmdbs "MySQL" nosql "MongoDB" key-value-store "redis"
(integer) 1
 
redis> MGET rmdbs nosql key-value-store
1) "MySQL"
2) "MongoDB"
3) "redis"
 
 
# MSET 的给定 key 当中有已存在的 key
 
redis> MSETNX rmdbs "Sqlite" language "python"  # rmdbs 键已经存在,操作失败
(integer) 0
 
redis> EXISTS language                          # 因为 MSET 是原子性操作,language 没有被设置
(integer) 0
 
redis> GET rmdbs                                # rmdbs 也没有被修改
"MySQL"

Redis Incrby 命令

# key 存在且是数字值
 
redis> SET rank 50
OK
 
redis> INCRBY rank 20
(integer) 70
 
redis> GET rank
"70"
 
 
# key 不存在时
 
redis> EXISTS counter
(integer) 0
 
redis> INCRBY counter 30
(integer) 30
 
redis> GET counter
"30"
 
 
# key 不是数字值时
 
redis> SET book "long long ago..."
OK
 
redis> INCRBY book 200
(error) ERR value is not an integer or out of range

Redis Incrbyfloat 命令

# 值和增量都不是指数符号
 
redis> SET mykey 10.50
OK
 
redis> INCRBYFLOAT mykey 0.1
"10.6"
 
 
# 值和增量都是指数符号
 
redis> SET mykey 314e-2
OK
 
redis> GET mykey                # 用 SET 设置的值可以是指数符号
"314e-2"
 
redis> INCRBYFLOAT mykey 0      # 但执行 INCRBYFLOAT 之后格式会被改成非指数符号
"3.14"
 
 
# 可以对整数类型执行
 
redis> SET mykey 3
OK
 
redis> INCRBYFLOAT mykey 1.1
"4.1"
 
 
# 后跟的 0 会被移除
 
redis> SET mykey 3.0
OK
 
redis> GET mykey                                    # SET 设置的值小数部分可以是 0
"3.0"
 
redis> INCRBYFLOAT mykey 1.000000000000000000000    # 但 INCRBYFLOAT 会将无用的 0 忽略掉,有需要的话,将浮点变为整数
"4"
 
redis> GET mykey
"4"

Redis Setrange 命令

redis 127.0.0.1:6379> SET key1 "Hello World"
OK
redis 127.0.0.1:6379> SETRANGE key1 6 "Redis"
(integer) 11
redis 127.0.0.1:6379> GET key1
"Hello Redis"

Redis Psetex 命令

redis 127.0.0.1:6379> SET key1 "Hello World"
OK
redis 127.0.0.1:6379> SETRANGE key1 6 "Redis"
(integer) 11
redis 127.0.0.1:6379> GET key1
"Hello Redis"

Redis Append 命令

redis 127.0.0.1:6379> SET key1 "Hello World"
OK
redis 127.0.0.1:6379> SETRANGE key1 6 "Redis"
(integer) 11
redis 127.0.0.1:6379> GET key1
"Hello Redis"

Redis Getset 命令

redis 127.0.0.1:6379> GETSET mynewkey "This is my test key"
(nil)
redis 127.0.0.1:6379> GETSET mynewkey "This is my new value to test getset"
"This is my test key"

Redis Mget 命令

redis 127.0.0.1:6379> GETSET mynewkey "This is my test key"
(nil)
redis 127.0.0.1:6379> GETSET mynewkey "This is my new value to test getset"
"This is my test key"

Redis Incr 命令

redis 127.0.0.1:6379> GETSET mynewkey "This is my test key"
(nil)
redis 127.0.0.1:6379> GETSET mynewkey "This is my new value to test getset"
"This is my test key"
相关推荐
行走的山峰34 分钟前
etcd三节点,其中一个坏掉了的恢复办法
数据库·etcd
一只特立独行的猪6111 小时前
Java面试——集合篇
java·开发语言·面试
讓丄帝愛伱2 小时前
spring boot启动报错:so that it conforms to the canonical names requirements
java·spring boot·后端
weixin_586062022 小时前
Spring Boot 入门指南
java·spring boot·后端
ImomoTo3 小时前
HarmonyOS学习(十三)——数据管理(二) 关系型数据库
数据库·学习·harmonyos·arkts·鸿蒙
Dola_Pan6 小时前
Linux文件IO(二)-文件操作使用详解
java·linux·服务器
wang_book6 小时前
Gitlab学习(007 gitlab项目操作)
java·运维·git·学习·spring·gitlab
机器视觉知识推荐、就业指导6 小时前
Qt/C++事件过滤器与控件响应重写的使用、场景的不同
开发语言·数据库·c++·qt
jnrjian6 小时前
export rman 备份会占用buff/cache 导致内存压力
数据库·oracle
蜗牛^^O^6 小时前
Docker和K8S
java·docker·kubernetes