历史版本7 :Redis运维手册 返回文档
编辑时间: 内容长度:图片数:目录数: 修改原因:

目录:

1. 热更改 Redis 配置编辑

Redis 使用 config 命令,可以对配置项参数热修改,不必重启。redis最好不要重启,重启一次会引发如下问题: 

  • 如果数据很多(例如几个G),读起来很慢; 

  • 重启风险很大,Redis有内存陷阱 

  • 重启会引发读快照,读AOF文件

config get *   # 获得所有的配置项的key 
127.0.0.1:6379> config get maxmemory 
maxmemory 2147483648    # 改变redis的内存 
127.0.0.1:6379> maxmemory 2147483648
config get *   # 查看 
127.0.0.1:6379> config get *

2. 查看 Redis 的使用情况编辑

info  #查看redis的使用情况
127.0.0.1:6379> info
# Server
redis_version:2.8.13  # Redis 服务器版本
redis_mode:standalone  # 运行模式是单机状态,redis集群时是cluster nodes
os:Linux3.5.0-48-generic x86_64  # 服务器的宿主操作系统
arch_bits:64  # 架构(32 或 64 位)
multiplexing_api:epoll  # Redis 所使用的事件处理机制
tcp_port:6379  #  TCP/IP 监听端口
uptime_in_seconds:11554  # redis启动至今经过的秒数
uptime_in_days:0   # redis启动至今经过的天数

3. Redis 运维编辑

3.1 redis单机

./redis-cli -p 端口 -a 密码  # 本地启动Redis客户端,可以进行查看key值,删除key值,检查redis状态等操作,如果端口是6379的话可以省略
./redis-cli -h ip -p 端口 -a 密码  # 远程连接Redis服务,ip和端口为要连接的Redis服务,如果端口是6379的话可以省略

3.2 redis集群

./redis-cli -h ip -c -p 端口 -a 密码   # 客户端远程连接某个节点,要输入对应的ip、端口、密码
127.0.0.1:6379> cluster nodes    # 查看redis集群目前的主从分布和运行情况

3.3 通用

127.0.0.1:6379> time  # 显示服务器时间 , 时间戳(秒), 微秒数
127.0.0.1:6379> dbsize  # 当前数据库的key的数量
127.0.0.1:6379> set fine-1-ha "a"  #设置 fine-1-ha 的值为 a
127.0.0.1:6379> keys *  # 查询所有 key
127.0.0.1:6379> keys fine* #模糊查询以 fine 为前缀的 key 值
127.0.0.1:6379> keys *ha #模糊查询以 ha 为后缀的 key 值
127.0.0.1:6379> DEL key1  # 清空指定的key,多个之间用空格隔开
redis 127.0.0.1:6379> flushall #清空整个 Redis 服务器的数据,谨慎使用
redis 127.0.0.1:6379> Flushdb  # 清空当前库所有键
redis 127.0.0.1:6379> exit #退出 Redis 客户端

其他运维命令详情可参考redis官网:http://www.redis.cn/commands.html