欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

理解 Redis(3) - 字符串类型

程序员文章站 2022-04-28 22:10:04
正如前面所讲的, redis 的数据结构就是一系列的键值对键 -> printable ASCII (可打印的 ASCII 码, 最大值是 512MB)值 -> Primitives (基本的) string 字符串 (最大值是 512MB) Containers (of string) (以其他形 ......

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

  • primitives (基本的)
    • string 字符串 (最大值是 512mb)
  • containers (of string) (以其他形式包裹的字符串)
    • hash (哈希)
    • list (序列)
    • set (集合)
    • ordered set (有序集合)
    下图是关于存储字符串值的示意图
    理解 Redis(3) - 字符串类型

下面开始介绍 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 的基本命令.