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"

相关推荐

  1. Linux经常使用相关命令

    2024-01-12 00:50:02       61 阅读
  2. Springbean相关问题

    2024-01-12 00:50:02       48 阅读
  3. Git相关命令

    2024-01-12 00:50:02       58 阅读
  4. docker相关命令

    2024-01-12 00:50:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-12 00:50:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-12 00:50:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-12 00:50:02       87 阅读
  4. Python语言-面向对象

    2024-01-12 00:50:02       96 阅读

热门阅读

  1. Python Pandas 时间序列分析 日期时间的处理和转换

    2024-01-12 00:50:02       60 阅读
  2. 前端工程师常用的ChatGPT通用提示词模板

    2024-01-12 00:50:02       51 阅读
  3. vue中slot和template用法传值

    2024-01-12 00:50:02       62 阅读
  4. 【K8S环境搭建】

    2024-01-12 00:50:02       49 阅读
  5. yum命令报错解决

    2024-01-12 00:50:02       67 阅读
  6. GFS 分布式文件系统

    2024-01-12 00:50:02       46 阅读
  7. leetcode-相同的树

    2024-01-12 00:50:02       66 阅读
  8. RT-Thread入门笔记2-动态内存堆的使用

    2024-01-12 00:50:02       60 阅读
  9. 大模型学习第四课

    2024-01-12 00:50:02       54 阅读