理解 Redis(3) - 字符串值

正如前面所讲的, redis 的数据结构就是一系列的键值对
键 -> printable ASCII (可打印的 ASCII 码, 最大值是 512MB)
值 -> 

  • Primitives (基本的)
    • string 字符串 (最大值是 512MB)
  • Containers (of string) (以其他形式包裹的字符串)
    • hash (哈希)
    • list (序列)
    • set (集合)
    • ordered set (有序集合)
    下图是关于存储字符串值的示意图

下面开始介绍 string 的相关命令:

设置键值:

127.0.0.1:6379> set name max
OK
127.0.0.1:6379> set name2 join
OK
127.0.0.1:6379> set name3 tom
OK

查看所有的键:

127.0.0.1:6379> keys *
1) "name2"
2) "name"
3) "name3"

获取某个键的值:

127.0.0.1:6379> get name
"max"

删除一条数据:

127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
1) "name2"
2) "name3"

更新某个键的值, 会覆盖原值:

127.0.0.1:6379> get name2
"join"
127.0.0.1:6379> set name2 rachel
OK
127.0.0.1:6379> get name2
"rachel"

一次性删除所有的数据:

127.0.0.1:6379> keys *
1) "name2"
2) "name3"
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
(empty list or set)

以上就是关于 string 的基本命令.

posted @ 2019-02-20 21:40  rachelross  阅读(460)  评论(0编辑  收藏  举报