在 CentOS 上测试 Redis 配置是否生效,一般可以从服务状态、连通性、配置参数、功能验证几个方面来做。下面给你一套比较实用的测试方法。
systemctl status redis
# 或
systemctl status redis-server
看到 active (running) 说明服务正常。
systemctl start redis
systemctl restart redis
redis-cli
进入后执行:
ping
返回:
PONG
说明连接正常。
redis-cli -h 127.0.0.1 -p 6379 ping
在 redis-cli 中执行:
CONFIG GET *
查看某一项,例如:
CONFIG GET maxmemory
CONFIG GET requirepass
CONFIG GET bind
例如修改 redis.conf:
vim /etc/redis.conf
改:
maxmemory 256mb
requirepass 123456
重启后测试:
redis-cli
AUTH 123456
ping
set testkey hello
get testkey
set tempkey abc ex 10
ttl tempkey
CONFIG GET bind
CONFIG GET protected-mode
若需远程:
bind 0.0.0.0
protected-mode no
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
redis-cli -h <centos_ip> -p 6379 ping
redis-benchmark -q -n 10000
如果你愿意,可以告诉我:
我可以直接给你对应的测试命令。