标签:服务器配置 时间 dbi com water alt diff ping basis
keys
返回满足给定条件的所有key
127.0.0.1:6379> keys *
1) "testlist2"
2) "testset4"
3) "testset2"
4) "mytest"
5) "num2"
6) "testset1"
7) "testset3"
8) "testset"
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
4) "testset3"
5) "testset"
exists
确认一个key 是否存在
127.0.0.1:6379> exists test
(integer) 0
127.0.0.1:6379> exists testset
(integer) 1
dbsize
返回当前数据库中key 的数目。
127.0.0.1:6379> dbsize
(integer) 10
127.0.0.1:6379> keys *
1) "testlist2"
2) "testset4"
3) "testset2"
4) "mytest"
5) "name_new"
6) "num2"
7) "testset1"
8) "num3"
9) "age1"
10) "num1"
del
删除一个key
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
4) "testset3"
5) "testset"
127.0.0.1:6379> del testset
(integer) 1
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
4) "testset3"
flushdb
删除当前选择数据库中的所有key。
127.0.0.1:6379[1]> keys *
1) "age"
127.0.0.1:6379[1]> flushdb
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> dbsize
(integer) 10
flushall
删除所有数据库中的所有key。
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> set age 15
OK
127.0.0.1:6379[1]> keys *
1) "age"
127.0.0.1:6379[1]> flushall
OK
127.0.0.1:6379[1]> dbsize
(integer) 0
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> dbsize
(integer) 0
expire
设置一个key 的过期时间(单位:秒),ttl命令检测有效时长
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
4) "testset3"
127.0.0.1:6379> expire testset3 10
(integer) 1
127.0.0.1:6379> ttl testset3
(integer) 1
127.0.0.1:6379> ttl testset3
(integer) -2
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
persist
移除给定key 的过期时间,取消过期
127.0.0.1:6379> expire age 100
(integer) 1
127.0.0.1:6379> ttl age
(integer) 94
127.0.0.1:6379> ttl age
(integer) 90
127.0.0.1:6379> persist age
(integer) 1
127.0.0.1:6379> ttl age
(integer) -1
127.0.0.1:6379> get age
"15"
select
选择数据库(redis默认16个数据库 0~15)
# vim redis.conf
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and ‘databases‘-1
databases 16
127.0.0.1:6379> select 0
OK
move
将当前数据库中的key 转移到其它数据库中
127.0.0.1:6379> select 0
OK
127.0.0.1:6379> set age 15
OK
127.0.0.1:6379> get age
"15"
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> get age
(nil)
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> move age 1
(integer) 1
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> get age
"15"
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> get age
(nil)
randomkey
随机返回一个key
127.0.0.1:6379> keys *
1) "testlist2"
2) "testset4"
3) "testset2"
4) "mytest"
5) "num2"
6) "testset1"
7) "num3"
8) "age1"
9) "num1"
10) "name"
127.0.0.1:6379> randomkey
"num3"
rename
重命名key
127.0.0.1:6379> keys *
1) "testlist2"
2) "testset4"
3) "testset2"
4) "mytest"
5) "num2"
6) "testset1"
7) "num3"
8) "age1"
9) "num1"
10) "name"
127.0.0.1:6379> rename name name_new
OK
127.0.0.1:6379> keys name*
1) "name_new"
type
返回值的类型
127.0.0.1:6379> keys testset*
1) "testset4"
2) "testset2"
3) "testset1"
127.0.0.1:6379> type testset1
set
127.0.0.1:6379> keys name*
1) "name_new"
127.0.0.1:6379> type name
none
127.0.0.1:6379> keys num*
1) "num2"
2) "num3"
3) "num1"
127.0.0.1:6379> type num1
string
ping
测试连接是否存活
127.0.0.1:6379> ping
PONG
echo
在命令行输出内容
127.0.0.1:6379> echo "Hello world!"
"Hello world!"
info
获取服务器的信息
127.0.0.1:6379> info
monitor
实时转储收到的请求
127.0.0.1:6379> monitor
OK
1543934476.796187 [0 127.0.0.1:52841] "info"
1543934614.406197 [0 127.0.0.1:52841] "config" "get"
1543934632.306195 [0 127.0.0.1:52841] "config" "get" "dir"
1543934662.761337 [0 127.0.0.1:52841] "config" "get" "*"
config get
获取服务器配置信息。
129.127.0.0.1:6379> config get *
quit / shutdown
退出连接。
标签:服务器配置 时间 dbi com water alt diff ping basis
原文地址:http://blog.51cto.com/13689359/2326224