一. Redis 常用命令

键值相关命令

1. KETS 查询所有的key

127.0.0.1:6379> keys *    
1) "tony"
2) "hexu1"
3) "hexu"

2. KETS 查询所有以t开头的key
127.0.0.1:6379> keys h*    
1) "hexu1"
2) "hexu"

3. EXISTS 检测key是否存在,返回1表示存在,0表示不存在

127.0.0.1:6379> EXISTS name
(integer) 0
127.0.0.1:6379> EXISTS hexu
(integer) 1

4. TTL 查看key的TTL值。当 key 不存在时,返回 -2 。 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以毫秒为单位,返回 key 的剩余生存时间。

127.0.0.1:6379> ttl hexu
(integer) -1

5. EXPIRE 设置 值为tony的key的过期时间

127.0.0.1:6379> EXPIRE tony 60
(integer) 1
127.0.0.1:6379> ttl tony
(integer) 57
127.0.0.1:6379> ttl tony
(integer) 53

6. RENAME  重命名key

127.0.0.1:6379> keys *
1) "hexu1"
2) "hexu"
127.0.0.1:6379> rename hexu hexu2
OK
127.0.0.1:6379> keys *
1) "hexu2"
2) "hexu1"

 

服务器相关命令

1. PING 检测服务器是否激活,PONG表示连接正常

127.0.0.1:6379> PING
PONG

2.SELECT 选择数据库

127.0.0.1:6379> select 0
OK
127.0.0.1:6379> select 2
OK

3.QUIT 或 EXIT 退出连接

[root@localhost src]# ./redis-cli
127.0.0.1:6379> exit
[root@localhost src]# ./redis-cli
127.0.0.1:6379> quit

4.DBSIZE 显示当前数据库中的key的数量

127.0.0.1:6379> dbsize
(integer) 2

5. INFO 查看当前Redis服务器的相关信息

6.FLUSHDB 清空当前数据库

127.0.0.1:6379> FLUSHDB
OK

7.FLUSHALL 清空所有数据库

127.0.0.1:6379> FLUSHALL
OK

8. 停止redis服务器

root@localhost redis-3.0.6]# cd src
[root@localhost src]# pkill redis-server

 

posted @ 2016-02-02 11:26  何旭  阅读(250)  评论(0编辑  收藏  举报