Redis Config Get 命令
Redis Config Get 命令用於獲取 redis 服務的配置參數。
在 Redis 2.4 版本中, 有部分參數沒有辦法用 CONFIG GET 訪問,但是在最新的 Redis 2.6 版本中,所有配置參數都已經可以用 CONFIG GET 訪問了。
語法
redis Config Get 命令基本語法如下:
redis 127.0.0.1:6379> CONFIG GET parameter
可用版本
>= 2.0.0
返回值
給定配置參數的值。
實例
redis 127.0.0.1:6379> config get *max-*-entries* 1) "hash-max-zipmap-entries" 2) "512" 3) "list-max-ziplist-entries" 4) "512" 5) "set-max-intset-entries" 6) "512"
Redis Config Set 命令
Redis Config Set 命令可以動態地調整 Redis 服務器的配置(configuration)而無須重啟。
你可以使用它修改配置參數,或者改變 Redis 的持久化(Persistence)方式。
語法
redis Config Set 命令基本語法如下:
redis 127.0.0.1:6379> CONFIG Set parameter value
可用版本
>= 2.0.0
返回值
當設置成功時返回 OK ,否則返回一個錯誤。
實例
redis 127.0.0.1:6379> CONFIG GET slowlog-max-len 1) "slowlog-max-len" 2) "1024" redis 127.0.0.1:6379> CONFIG SET slowlog-max-len 10086 OK redis 127.0.0.1:6379> CONFIG GET slowlog-max-len 1) "slowlog-max-len" 2) "10086"
實際案例
redis由於key刪除策略配置錯誤導致內存滿,不能寫入redis。修改key刪除策略,不重啟redis
1、查看配置文件及現在redis加載中的配置
[root@w15 redis]# cat 6379.conf|grep maxmemory-policy # according to the eviction policy selected (see maxmemory-policy). maxmemory-policy noeviction [root@w15 redis]# redis-cli -p 6379 127.0.0.1:6379> CONFIG GET maxmemory-policy 1) "maxmemory-policy" 2) "noeviction" 127.0.0.1:6379>
2、修改配置文件(下次redis重啟生效)以及在線修改redis配置
[root@w15 redis]# cat 6379.conf|grep maxmemory-policy # according to the eviction policy selected (see maxmemory-policy). maxmemory-policy volatile-lru [root@w15 redis]# redis-cli -p 6379 127.0.0.1:6379> CONFIG GET maxmemory-policy 1) "maxmemory-policy" 2) "volatile-lru" 127.0.0.1:16379> exit