DEL key [key ...]

Delete a key

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> DEL foo hello
  4. (integer) 1
  5. 127.0.0.1:6379> EXISTS foo
  6. (integer) 0

DUMP key

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

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

EXISTS key

Determine if a key exists

  1. 127.0.0.1:6379> EXISTS foo
  2. (integer) 0
  3. 127.0.0.1:6379> SET foo hello
  4. OK
  5. 127.0.0.1:6379> EXISTS foo
  6. (integer) 1

EXPIRE key seconds

Set a key's time to live in seconds

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> EXPIRE foo 10
  4. (integer) 1
  5. 127.0.0.1:6379> TTL foo
  6. (integer) 5
  7. 127.0.0.1:6379> GET foo
  8. "hello"
  9. 127.0.0.1:6379> TTL foo
  10. (integer) -2
  11. 127.0.0.1:6379> GET foo
  12. (nil)

EXPIREAT key timestamp

Set the expiration for a key as a UNIX timestamp

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> TIME
  4. 1) "1427471335"
  5. 2) "585724"
  6. 127.0.0.1:6379> EXPIREAT foo 1427471400
  7. (integer) 1
  8. 127.0.0.1:6379> TIME
  9. 1) "1427471420"
  10. 2) "109363"
  11. 127.0.0.1:6379> GET foo
  12. (nil)

KEYS pattern

Find all keys matching the given pattern

  1. 127.0.0.1:6379> SET foo 1
  2. OK
  3. 127.0.0.1:6379> SET bar 2
  4. OK
  5. 127.0.0.1:6379> SET far 3
  6. OK
  7. 127.0.0.1:6379> SET bat 4
  8. OK
  9. 127.0.0.1:6379> KEYS ba?
  10. 1) "bat"
  11. 2) "bar"
  12. 127.0.0.1:6379> KEYS f*
  13. 1) "far"
  14. 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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> MOVE foo 1
  4. (integer) 1
  5. 127.0.0.1:6379> GET foo
  6. (nil)
  7. 127.0.0.1:6379> select 1
  8. OK
  9. 127.0.0.1:6379[1]> GET foo
  10. "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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> EXPIRE foo 10
  4. (integer) 1
  5. 127.0.0.1:6379> TTL foo
  6. (integer) 7
  7. 127.0.0.1:6379> PERSIST foo
  8. (integer) 1
  9. 127.0.0.1:6379> TTL foo
  10. (integer) -1

PEXPIRE key milliseconds

Set a key's time to live in milliseconds

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> PEXPIRE foo 10000
  4. (integer) 1
  5. 127.0.0.1:6379> PTTL foo
  6. (integer) 5937
  7. 127.0.0.1:6379> GET foo
  8. "hello"
  9. 127.0.0.1:6379> PTTL foo
  10. (integer) -2
  11. 127.0.0.1:6379> GET foo
  12. (nil)

PEXPIREAT key milliseconds-timestamp

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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> TIME
  4. 1) "1427475623"
  5. 2) "105070"
  6. 127.0.0.1:6379> PEXPIREAT foo 1427475723105
  7. (integer) 1
  8. 127.0.0.1:6379> GET foo
  9. "hello"
  10. 127.0.0.1:6379> TIME
  11. 1) "1427475724"
  12. 2) "402347"
  13. 127.0.0.1:6379> GET foo
  14. (nil)

PTTL key

Get the time to live for a key in milliseconds

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> PTTL foo
  4. (integer) -1
  5. 127.0.0.1:6379> PEXPIRE foo 10000
  6. (integer) 1
  7. 127.0.0.1:6379> PTTL foo
  8. (integer) 8658
  9. 127.0.0.1:6379> GET foo
  10. "hello"
  11. 127.0.0.1:6379> PTTL foo
  12. (integer) -2
  13. 127.0.0.1:6379> GET foo
  14. (nil)

RANDOMKEY

Return a random key from the keyspace

  1. 127.0.0.1:6379> MSET foo1 1 foo2 2 foo3 3 foo4 4 foo5 5
  2. OK
  3. 127.0.0.1:6379> KEYS *
  4. 1) "foo1"
  5. 2) "foo4"
  6. 3) "foo2"
  7. 4) "foo5"
  8. 5) "foo3"
  9. 127.0.0.1:6379> RANDOMKEY
  10. "foo2"
  11. 127.0.0.1:6379> RANDOMKEY
  12. "foo1"
  13. 127.0.0.1:6379> RANDOMKEY
  14. "foo5"

RENAME key newkey

Rename a key

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> RENAME foo bar
  4. OK
  5. 127.0.0.1:6379> GET bar
  6. "hello"

RENAMENX key newkey

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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> SET bar 0
  4. OK
  5. 127.0.0.1:6379> RENAMENX foo bar
  6. (integer) 0
  7. 127.0.0.1:6379> GET bar
  8. "0"
  9. 127.0.0.1:6379> RENAME foo boo
  10. OK
  11. 127.0.0.1:6379> GET boo
  12. "hello"

RESTORE key ttl serialized-value [REPLACE]

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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> DUMP foo
  4. "\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99"
  5. 127.0.0.1:6379> DEL foo
  6. (integer) 1
  7. 127.0.0.1:6379> RESTORE foo 0 "\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99"
  8. OK
  9. 127.0.0.1:6379> GET foo
  10. "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

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> TTL foo
  4. (integer) -1
  5. 127.0.0.1:6379> EXPIRE foo 10
  6. (integer) 1
  7. 127.0.0.1:6379> TTL foo
  8. (integer) 7
  9. 127.0.0.1:6379> GET foo
  10. "hello"
  11. 127.0.0.1:6379> TTL foo
  12. (integer) -2
  13. 127.0.0.1:6379> GET foo
  14. (nil)

TYPE key

Determine the type stored at key

  1. 127.0.0.1:6379> SET foo hello
  2. OK
  3. 127.0.0.1:6379> TYPE foo
  4. string
  5. 127.0.0.1:6379> LPUSH bar 1
  6. (integer) 1
  7. 127.0.0.1:6379> TYPE bar
  8. 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. android使用mount挂载/system/app为读写权限,删除或替换系统应用

    注意:以下代码中#开头的则为需要执行的shell命令,其他的为打印的结果.#代表需要使用ROOT权限(su)执行,所以想要修改您android手机某个目录挂载为读写,首先需要有ROOT权限! 先要得到 ...

  2. 编译小结(6)认识Automake

           我前面说了很多如何用gcc或 Makefile怎么编译的东东,但在Linux下装过软件的都应当见过,很多源码安装的包是用Automake 来编译的.输入下"./configur ...

  3. when not exists 用法

    USE [ChangHong_612]GO/****** Object: StoredProcedure [dbo].[st_MES_UpdateInspectResult] Script Date: ...

  4. ags模版与vs

    esri为每个版本的sdk指定了特定的vs开发版本,比如ags10.0,ags10.1指定的是vs2008和vs2010,大概是因为发布时间的关系. 无论如何,我们可以将模版移植到新的vs下.(注意红 ...

  5. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  6. 基础数据结构 之 栈(python实现)

    栈是编程开发中的两种较为简单的数据结构.栈和队可用于模拟函数的递归.栈的特点是后进先出.其常用操作包括:出栈,入栈等.在出栈前,需判断栈是否为空.在入栈时,需判断栈是否已满. 下面给出一个用pytho ...

  7. lightOJ 1030(期望)

    题意:有一个迷宫是1×n的格子,一个人每到一个格子就能够把这个格子内的金子所有拿走,刚開始站在第1个格子,然后開始掷骰子得到点数x,他就要从当前位置走到加x的位置.假设发现位置是大于n的就又一次掷骰子 ...

  8. Jquery中$与$.fn的差别

    当今web开发往往离不开Jquery的使用,Jquery以其简洁的使用方式.良好的浏览器兼容性赢得了软件研发同行的青睐,作为当中的一员,自然也不例外,虽然刚開始时非常排斥Jquery,今天我谈一下对J ...

  9. Python实践之(七)逻辑回归(Logistic Regression)

    机器学习算法与Python实践之(七)逻辑回归(Logistic Regression) zouxy09@qq.com http://blog.csdn.net/zouxy09 机器学习算法与Pyth ...

  10. 决策树算法实现(train+test,matlab) 转

    原文:http://www.zgxue.com/198/1985544.html 华电北风吹 天津大学认知计算与应用重点实验室 修改日期:2015/8/15 决策树是一种特别简单的机器学习分类算法.决 ...