DEL key [key ...]

Delete a key

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> DEL foo hello
(integer) 1
127.0.0.1:6379> EXISTS foo
(integer) 0

DUMP key

Return a serialized version of the value stored at the specified key.

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> DUMP foo
"\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99"

EXISTS key

Determine if a key exists

127.0.0.1:6379> EXISTS foo
(integer) 0
127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> EXISTS foo
(integer) 1

EXPIRE key seconds

Set a key's time to live in seconds

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> EXPIRE foo 10
(integer) 1
127.0.0.1:6379> TTL foo
(integer) 5
127.0.0.1:6379> GET foo
"hello"
127.0.0.1:6379> TTL foo
(integer) -2
127.0.0.1:6379> GET foo
(nil)

EXPIREAT key timestamp

Set the expiration for a key as a UNIX timestamp

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> TIME
1) "1427471335"
2) "585724"
127.0.0.1:6379> EXPIREAT foo 1427471400
(integer) 1
127.0.0.1:6379> TIME
1) "1427471420"
2) "109363"
127.0.0.1:6379> GET foo
(nil)

KEYS pattern

Find all keys matching the given pattern

127.0.0.1:6379> SET foo 1
OK
127.0.0.1:6379> SET bar 2
OK
127.0.0.1:6379> SET far 3
OK
127.0.0.1:6379> SET bat 4
OK
127.0.0.1:6379> KEYS ba?
1) "bat"
2) "bar"
127.0.0.1:6379> KEYS f*
1) "far"
2) "foo"

MIGRATE host port key destination-db timeout [COPY] [REPLACE]

Available since 2.6.0.

Atomically transfer a key from a Redis instance to another one.

More: http://redis.io/commands/migratehttp://www.redis.cn/commands/migrate.html

MOVE key db

Move a key to another database

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> MOVE foo 1
(integer) 1
127.0.0.1:6379> GET foo
(nil)
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> GET foo
"hello"

OBJECT subcommand [arguments [arguments ...]]

Inspect the internals of Redis objects

More: http://redis.io/commands/object

PERSIST key

Remove the expiration from a key

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> EXPIRE foo 10
(integer) 1
127.0.0.1:6379> TTL foo
(integer) 7
127.0.0.1:6379> PERSIST foo
(integer) 1
127.0.0.1:6379> TTL foo
(integer) -1

PEXPIRE key milliseconds

Set a key's time to live in milliseconds

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> PEXPIRE foo 10000
(integer) 1
127.0.0.1:6379> PTTL foo
(integer) 5937
127.0.0.1:6379> GET foo
"hello"
127.0.0.1:6379> PTTL foo
(integer) -2
127.0.0.1:6379> GET foo
(nil)

PEXPIREAT key milliseconds-timestamp

Set the expiration for a key as a UNIX timestamp specified in milliseconds

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> TIME
1) "1427475623"
2) "105070"
127.0.0.1:6379> PEXPIREAT foo 1427475723105
(integer) 1
127.0.0.1:6379> GET foo
"hello"
127.0.0.1:6379> TIME
1) "1427475724"
2) "402347"
127.0.0.1:6379> GET foo
(nil)

PTTL key

Get the time to live for a key in milliseconds

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> PTTL foo
(integer) -1
127.0.0.1:6379> PEXPIRE foo 10000
(integer) 1
127.0.0.1:6379> PTTL foo
(integer) 8658
127.0.0.1:6379> GET foo
"hello"
127.0.0.1:6379> PTTL foo
(integer) -2
127.0.0.1:6379> GET foo
(nil)

RANDOMKEY

Return a random key from the keyspace

127.0.0.1:6379> MSET foo1 1 foo2 2 foo3 3 foo4 4 foo5 5
OK
127.0.0.1:6379> KEYS *
1) "foo1"
2) "foo4"
3) "foo2"
4) "foo5"
5) "foo3"
127.0.0.1:6379> RANDOMKEY
"foo2"
127.0.0.1:6379> RANDOMKEY
"foo1"
127.0.0.1:6379> RANDOMKEY
"foo5"

RENAME key newkey

Rename a key

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> RENAME foo bar
OK
127.0.0.1:6379> GET bar
"hello"

RENAMENX key newkey

Rename a key, only if the new key does not exist

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> SET bar 0
OK
127.0.0.1:6379> RENAMENX foo bar
(integer) 0
127.0.0.1:6379> GET bar
"0"
127.0.0.1:6379> RENAME foo boo
OK
127.0.0.1:6379> GET boo
"hello"

RESTORE key ttl serialized-value [REPLACE]

Create a key using the provided serialized value, previously obtained using DUMP.

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> DUMP foo
"\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99"
127.0.0.1:6379> DEL foo
(integer) 1
127.0.0.1:6379> RESTORE foo 0 "\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99"
OK
127.0.0.1:6379> GET foo
"hello"

More: http://redis.io/commands/restore

SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]

Sort the elements in a list, set or sorted set

Detail: http://www.cnblogs.com/huey/p/5655023.html

More: http://redis.io/commands/sort

TTL key

Get the time to live for a key

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> TTL foo
(integer) -1
127.0.0.1:6379> EXPIRE foo 10
(integer) 1
127.0.0.1:6379> TTL foo
(integer) 7
127.0.0.1:6379> GET foo
"hello"
127.0.0.1:6379> TTL foo
(integer) -2
127.0.0.1:6379> GET foo
(nil)

TYPE key

Determine the type stored at key

127.0.0.1:6379> SET foo hello
OK
127.0.0.1:6379> TYPE foo
string
127.0.0.1:6379> LPUSH bar 1
(integer) 1
127.0.0.1:6379> TYPE bar
list

SCAN cursor [MATCH pattern] [COUNT count]

Incrementally iterate the keys space

More: http://redis.io/commands/scanhttp://www.redis.cn/commands/scan.html

Redis 命令 - Keys的更多相关文章

  1. 关于Redis命令keys在性能方面的说明

    redis的keys命令类似于Mysql的like命令,无非就是模糊匹配相近的字符数据. KEYS 的速度非常快,但在一个大的数据库中使用它仍然可能造成性能问题,如果你需要从一个数据集中查找特定的 k ...

  2. redis命令Keys(九)

    常用命令 1>keys 返回满足给定pattern 的所有key redis 127.0.0.1:6379> keys mylist* 1) "mylist" 2) & ...

  3. Redis的KEYS命令引起宕机事件

    摘要: 使用 Redis 的开发者必看,吸取教训啊! 原文:Redis 的 KEYS 命令引起 RDS 数据库雪崩,RDS 发生两次宕机,造成几百万的资金损失 作者:陈浩翔 Fundebug经授权转载 ...

  4. Redis 的 KEYS 命令不能乱用啊

    KESY 命令 时间复杂度: O(N) , 假设Redis中的键名和给定的模式的长度有限的情况下,N为数据库中key的个数. Redis Keys 命令用于查找所有符合给定模式 pattern 的 k ...

  5. redis中keys命令带来的线上性能问题

    起因 下午接到运维反馈,生产redis有个执行keys的命令请求太慢了,要两三秒才能响应 涉及命令如下: KEYS ttl_600::findHeadFootData-15349232-*-head ...

  6. redis命令总结

     Redis命令总结 redis 127.0.0.1:6379> info  #查看server版本内存使用连接等信息 redis 127.0.0.1:6379> client list  ...

  7. 常用 redis 命令(for php)

    Redis 主要能存储 5 种数据结构,分别是 strings,hashes,lists,sets 以及 sorted sets. 新建一个 redis 数据库 $redis = new Redis( ...

  8. Redis命令大全&中文解释&在线测试命令工具&在线中文文档

    在线测试命令地址:http://try.redis.io/ 官方文档:http://redis.io/commands http://redis.io/documentation Redis 命令参考 ...

  9. Redis命令

    redis的常用命令主要分为两个方面.一个是键值相关命令.一个是服务器相关命令(redis-cli进入终端) 1.键值相关命令 keys * 取出当前所有的key exists name 查看n是否有 ...

随机推荐

  1. UVaLive 6623 Battle for Silver (最大值,暴力)

    题意:给定一个图,让你找一个最大的子图,在这个子图中任何两点都有边相连,并且边不交叉,求这样子图中权值最大的是多少. 析:首先要知道的是,要想不交叉,那么最大的子图就是四个点,否则一定交叉,然后就暴力 ...

  2. linux(centos 6)下记录所有用户的操作以及ip、时间

    编辑/etc/profile文件,在文件末尾加入下面代码: [root@iZ23nn1p4mjZ root]# vi /etc/profile history USER=`whoami` USER_I ...

  3. 201. Segment Tree Build

    最后更新 二刷 08-Jan-2017 一刷忘了什么时候做的,只是觉得这几个题挺好的,一步一步手动构建线段树,最终理解了这个数据结构,并且后面有利用的地方. 其实重要的3个东西题目已经提供了: 1) ...

  4. jsp页面显示数据库的数据信息表

    在日常jsp开发中:最基本的一个操作之一是把之前添加到数据库中的信息在jsp页面中显示出来,也就是增删改查中的查找的一部分: 下面是以上部分的开发步骤及分析. 1.在jsp页面: <thead& ...

  5. Science上发表的超赞聚类算法(转)

    作者(Alex Rodriguez, Alessandro Laio)提出了一种很简洁优美的聚类算法, 可以识别各种形状的类簇, 并且其超参数很容易确定. 算法思想 该算法的假设是类簇的中心由一些局部 ...

  6. SSL握手过程

    原文地址: http://my.oschina.net/u/1188877/blog/164982 一.SSL握手有三个目的:1. 客户端与服务器需要就一组用于保护数据的算法达成一致:2. 它们需要确 ...

  7. java搭建finagle(1)

    1.新建maven项目 2.pom文件添加依赖 添加3个主要依赖<dependency> <groupId>com.twitter</groupId> <ar ...

  8. OpenCV 2.2版本号以上显示图片到 MFC 的 Picture Control 控件中

    OpenCV 2.2 以及后面的版本号取消掉了 CvvImage.h 和CvvImage.cpp 两个文件,直接导致了苦逼的程序猿无法调用里面的显示函数来将图片显示到 MFC 的 Picture Co ...

  9. Java多线程之wait(),notify(),notifyAll()

    在多线程的情况下,因为同一进程的多个线程共享同一片存储空间,在带来方便的同一时候,也带来了訪问冲突这个严重的问题.Java语言提供了专门机制以解决这样的冲突,有效避免了同一个数据对象被多个线程同一时候 ...

  10. phpstorm 和web storm汉化

    http://www.jincaimao.com/cms-phpstorm-index.html phpStorm汉化方法: B1).找到X:\Program Files\JetBrains\PhpS ...