加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

NoSQL之Redis常用命令--服务器相关命令

发布时间:2020-12-13 13:48:38 所属栏目:百科 来源:网络整理
导读:1.ping: 测试服务器是否存 127.0.0.1:6379 ping PONG ping pong类似于打乒乓球,pong说明服务器有相应。 然后我们把redis关闭掉 127.0.0.1:6379 ping Could not connect to Redis at 127.0.0.1:6379: Connection refused 可以看到已经连接不上了 然后再启动

1.ping:测试服务器是否存

127.0.0.1:6379> ping
PONG

ping pong类似于打乒乓球,pong说明服务器有相应。

然后我们把redis关闭掉

127.0.0.1:6379> ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused

可以看到已经连接不上了

然后再启动redis

127.0.0.1:6379> ping
PONG

2.echo content 再命令行输出content

127.0.0.1:6379> echo 'test echo'
"test echo"

3.select dbindex:选择数据库。Redis数据库的编号是0-15,我们可以选择任意一个数据库来进行数据的存取。当选择16时会报错。

127.0.0.1:6379> select 11
OK
127.0.0.1:6379> select 16
(error) ERR invalid DB index

4.quit/exit:退出和redis的链接

5.dbsize:返回当前数据库中key的数目

127.0.0.1:6379> select 0
OK
127.0.0.1:6379> keys *
1) "key2"
2) "key4"
3) "key1"
4) "key3"
5) "zsetkey1"
127.0.0.1:6379> dbsize
(integer) 5
127.0.0.1:6379> select 1
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> dbsize
(integer) 0

6.info:获取服务器的信息和统计

7.config get key:获取配置文件中的信息

127.0.0.1:6379> config get dir
1) "dir"
2) "/usr/local/redis-2.8.1/src"
127.0.0.1:6379> config get timeout
1) "timeout"
2) "0"

如果用config get *可以将所有的配置信息取出

8.flushdb:删除当前数据库中的所有key

127.0.0.1:6379[1]> dbsize
(integer) 1
127.0.0.1:6379[1]> keys *
1) "listkey1"
127.0.0.1:6379[1]> flushdb
OK
127.0.0.1:6379[1]> keys *
(empty list or set)

9.flushall:删除所有数据库的所有key

127.0.0.1:6379[1]> select 0 OK 127.0.0.1:6379> dbsize (integer) 1 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> dbsize (integer) 2 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读