1、DEL key [key ...]
删除给定的一个或多个 key 。
不存在的 key 会被忽略。
返回值:
被删除 key 的数量。
实例:

127.0.0.1:6379> set kinds science OK 127.0.0.1:6379> del kinds #删除键 (integer) 1 127.0.0.1:6379> exists kinds #删除不存在的键 (integer) 0 127.0.0.1:6379>
2、EXISTS key
检查给定 key 是否存在。
返回值:
若 key 存在,返回 1 ,否则返回 0
实例:

127.0.0.1:6379> set db mysql OK 127.0.0.1:6379> exists db (integer) 1 127.0.0.1:6379> del db (integer) 1 127.0.0.1:6379> exists db (integer) 0
3、KEYS pattern
查找所有符合给定模式 pattern 的 key 。 KEYS * 匹配数据库中所有 key 。 KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 KEYS h*llo 匹配 hllo 和 heeeeello 等。 KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。 特殊符号用 隔开 返回值: 符合给定模式的 key 列表。
实例:

127.0.0.1:6379> keys * 1) "apple" 2) "l1" 3) "l5" 4) "zstov1" 5) "z1" 6) "s7" 7) "harry" 127.0.0.1:6379> keys a* 1) "apple" 2) "author"
4、MOVE key db
将当前数据库的 key 移动到给定的数据库 db 当中。
如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key ,或者 key 不存在于当前数据库,那么 MOVE 没有任何效果。
返回值:
移动成功返回 1 ,失败则返回 0 。
实例:

#将数据库中的键k1移动到第一个数据库中 127.0.0.1:6379> set k1 v1 OK 127.0.0.1:6379> move k1 1 (integer) 1 127.0.0.1:6379> exists k1 (integer) 0
5、EXPIRE key seconds
为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。
实例:

127.0.0.1:6379> set k1 v1 OK 127.0.0.1:6379> expire k1 5 #设置k1的生存时间 (integer) 1
6、PERSIST key
移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。

127.0.0.1:6379> set k2 v2 OK 127.0.0.1:6379> expire k2 15 #设置过期时间 (integer) 1 127.0.0.1:6379> persist k2 #取消过期时间 (integer) 1 127.0.0.1:6379> ttl k2 #查看过期时间 (integer) -1
7、RANDOMKEY
从当前数据库中随机返回(不删除)一个 key 。
返回值:
当数据库不为空时,返回一个 key 。
当数据库为空时,返回 nil 。
实例:

127.0.0.1:6379> randomkey "time1"
8、FLUSHD
删除当前数据库所有 key
9、RENAME key newkey
将 key 改名为 newkey 。
当 key 和 newkey 相同,或者 key 不存在时,返回一个错误。
当 newkey 已经存在时, RENAME 命令将覆盖旧值。

127.0.0.1:6379> rename message message1 OK 127.0.0.1:6379> exists message (integer) 0 127.0.0.1:6379> exists message1 (integer) 1
10、SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC | DESC] [ALPHA] [STORE destination]
返回或保存给定列表、集合、有序集合 key 中经过排序的元素。
排序默认以数字作为对象,值被解释为双精度浮点数,然后进行比较。
最简单的 SORT 使用方法是 SORT key 和 SORT key DESC :
SORT key 返回键值从小到大排序的结果。
SORT key DESC 返回键值从大到小排序的结果。

127.0.0.1:6379> lpush salary 2000 6000 5000 3000 (integer) 4 127.0.0.1:6379> sort salary #升序 1) "2000" 2) "3000" 3) "5000" 4) "6000" 127.0.0.1:6379> sort salary desc #降序 1) "6000" 2) "5000" 3) "3000" 4) "2000"
11、TTL key
以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
实例:

#设置key但没有设置时间 127.0.0.1:6379> set key value OK 127.0.0.1:6379> ttl key (integer) -1 #设置时间为20s 127.0.0.1:6379> expire key 20 (integer) 1 127.0.0.1:6379> ttl key #查看剩余生存时间 (integer) 14
12、TYPE key
返回 key 所储存的值的类型。
返回值:
none (key不存在)
string (字符串)
list (列表)
set (集合)
zset (有序集)
hash (哈希表)
实例:

#哈希类型 127.0.0.1:6379> hset boy name bright (integer) 1 127.0.0.1:6379> type boy hash #字符串类型 127.0.0.1:6379> set fruit apple OK 127.0.0.1:6379> type fruit string #列表类型 127.0.0.1:6379> lpush animals dog cat penguim (integer) 3 127.0.0.1:6379> type animals list
13、SCAN cursor [MATCH pattern] [COUNT count]
SCAN 命令用于迭代当前数据库中的数据库键。
SCAN 命令是一个基于游标的迭代器(cursor based iterator): SCAN 命令每次被调用之后, 都会向用户返回一个新的游标,
用户在下次迭代时需要使用这个新游标作为 SCAN 命令的游标参数, 以此来延续之前的迭代过程。
当 SCAN 命令的游标参数被设置为 0 时, 服务器将开始一次新的迭代, 而当服务器向用户返回值为 0 的游标时, 表示迭代已结束。
实例:

127.0.0.1:6379> scan 0 1) "50" 2) 1) "food" 2) "time" 3) "pear" 4) "z2" 5) "flowers" 6) "zstov2" 7) "num" 8) "fruit" 9) "mylist" 10) "l1" 127.0.0.1:6379> scan 50 1) "62" 2) 1) "kinds" 2) "z3" 3) "l5" 4) "author" 5) "apple" 6) "salary" 7) "num2" 8) "strw" 9) "z1" 10) "name2" 11) "l3" # SCAN 命令的回复是一个包含两个元素的数组, 第一个数组元素是用于进#行下一次迭代的新游标, 而第二个数组元素则是一个数组, 这个数组中包#含了所有被迭代的元素。当返回的第一个数组元素是0时,说明已经完整的#遍历了所有元素。