• 修改 redis 配置参数查看和修改,无需重启


    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
    
  • 相关阅读:
    【C++】资源管理
    【Shell脚本】逐行处理文本文件
    【算法题】rand5()产生rand7()
    【Shell脚本】字符串处理
    Apple iOS产品硬件参数. 不及格的程序员
    与iPhone的差距! 不及格的程序员
    iPhone游戏 Mr.Karoshi"过劳死"通关. 不及格的程序员
    XCode V4 发布了, 苹果的却是个变态. 不及格的程序员
    何时readonly 字段不是 readonly 的?结果出呼你想象!!! 不及格的程序员
    object file format unrecognized, invalid, or unsuitable Command 不及格的程序员
  • 原文地址:https://www.cnblogs.com/xzlive/p/14363351.html
Copyright © 2020-2023  润新知