doina

一个小菜鸟运维工程师.

yum安装redis及常用指令

#安装epel 数据源
[root@baiyongjie ~]# yum install epel-release

#安装redis
[root@baiyongjie ~]# yum -y install redis

#查看redis版本
[root@baiyongjie ~]# redis-cli -v
redis-cli 3.2.10

#启动redis
[root@baiyongjie ~]# systemctl start redis

#查看redis的监听端口
[root@baiyongjie ~]# netstat -nplt|grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 10784/redis-server

#设置redis开机启动
[root@baiyongjie ~]# systemctl is-enabled redis
disabled
[root@baiyongjie ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[root@baiyongjie ~]# systemctl is-enabled redis
enabled

#连接redis
[root@baiyongjie ~]# redis-cli -h localhost
localhost:6379&gt;</pre>
<pre>
#redis 常用操作
#设置一个key
localhost:6379&gt; set name baiyongjie
OK
#查看key的值
localhost:6379&gt; get name
"baiyongjie"
#查看key是否存在,存在返回1,不存在返回0
localhost:6379&gt; exists name
(integer) 1
localhost:6379&gt; exists names
(integer) 0
#查看key对应value的类型
localhost:6379> type name
string
#查看redis库中 key的数量
localhost:6379> dbsize
(integer) 2
#删除key
localhost:6379> set number 123123
OK
localhost:6379> get number
"123123"
localhost:6379> del number 
(integer) 1
localhost:6379> get number
(nil)
localhost:6379> keys *
1) "name"
#删除所有key,
  - flushdb:删除当前选择数据库中的所有key
  - flushall:删除所有数据库中的所有key
localhost:6379> keys *
1) "sex"
2) "number"
3) "name"
localhost:6379> flushdb
OK
localhost:6379> keys *
(empty list or set)

#查看redis已建立的连接数
[root@baiyongjie ~]# redis-cli  -h localhost
localhost:6379>  info clients
# Clients
connected_clients:1 #1个连接
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
#查看允许的最大连接数
localhost:6379> config get maxclients 
1) "maxclients"
2) "10000"
#查看内存使用
localhost:6379> info memory
# Memory
used_memory:811576
used_memory_human:792.55K
used_memory_rss:2539520
used_memory_rss_human:2.42M
used_memory_peak:812688
used_memory_peak_human:793.64K
total_system_memory:1928699904
total_system_memory_human:1.80G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:3.13
mem_allocator:jemalloc-3.6.0
点赞

发表评论

电子邮件地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据