redis怎么动态添加内存,动态配置,无需重启。

时间:2022-01-17 10:29:40

在redis的使用过程中,有时候需要急需修改redis的配置,比如在业务运行的情况下,内存不够怎么办,这时要么赶紧删除无用的内存,要么扩展内存。如果有无用的内容可删除那么所有问题都已经解决。如果内容都是重要的,那只能选择扩展内存。说到扩展内存,redis为我们提供了一个命令。

CONFIG SET
CONFIG SET parameter value
CONFIG SET 命令可以动态地调整 Redis 服务器的配置(configuration)而无须重启。
你可以使用它修改配置参数,或者改变 Redis 的持久化(Persistence)方式。
CONFIG SET 可以修改的配置参数可以使用命令 CONFIG GET * 来列出,所有被 CONFIG SET 修改的配置参数都会立即生效。
关于 CONFIG SET 命令的更多消息,请参见命令 CONFIG GET 的说明。
关于如何使用 CONFIG SET 命令修改 Redis 持久化方式,请参见 Redis Persistence 。
可用版本:>= 2.0.0时间复杂度:不明确返回值:当设置成功时返回 OK ,否则返回一个错误。

例如:动态添加内存

redis 127.0.0.1:> config get maxmemory
) "maxmemory"
) ""
redis 127.0.0.1:> config set maxmemory
OK
redis 127.0.0.1:> config get maxmemory
) "maxmemory"
) ""

我们看看那些参数 redis可以动态设置

redis 127.0.0.1:> config get *
) "dbfilename"
) "dump.rdb"
) "requirepass"
) ""
) "masterauth"
) ""
) "bind"
) ""
) "unixsocket"
) ""
) "logfile"
) ""
) "pidfile"
) "/usr/local/redis/var/run/redis.pid"
) "maxmemory"
) ""
) "maxmemory-samples"
) ""
) "timeout"
) ""
) "tcp-keepalive"
) ""
) "auto-aof-rewrite-percentage"
) ""
) "auto-aof-rewrite-min-size"
) ""
) "hash-max-ziplist-entries"
) ""
) "hash-max-ziplist-value"
) ""
) "list-max-ziplist-entries"
) ""
) "list-max-ziplist-value"
) ""
) "set-max-intset-entries"
) ""
) "zset-max-ziplist-entries"
) ""
) "zset-max-ziplist-value"
) ""
) "lua-time-limit"
) ""
) "slowlog-log-slower-than"
) ""
) "slowlog-max-len"
) ""
) "port"
) ""
) "databases"
) ""
) "repl-ping-slave-period"
) ""
) "repl-timeout"
) ""
) "maxclients"
) ""
) "watchdog-period"
) ""
) "slave-priority"
) ""
) "hz"
) ""
) "no-appendfsync-on-rewrite"
) "no"
) "slave-serve-stale-data"
) "yes"
) "slave-read-only"
) "yes"
) "stop-writes-on-bgsave-error"
) "yes"
) "daemonize"
) "yes"
) "rdbcompression"
) "yes"
) "rdbchecksum"
) "yes"
) "activerehashing"
) "yes"
) "repl-disable-tcp-nodelay"
) "no"
) "aof-rewrite-incremental-fsync"
) "yes"
) "appendonly"
) "no"
) "dir"
) "/usr/local/redis/db"
) "maxmemory-policy"
) "volatile-lru"
) "appendfsync"
) "everysec"
) "save"
) "900 1 300 10 60 10000"
) "loglevel"
) "notice"
) "client-output-buffer-limit"
) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
) "unixsocketperm"
) ""
) "slaveof"