redis - 如何设置Redis最大内存?

标签 redis

我在 this 中找到配置,它只是说使用指定配置的命令:

./redis-server <path>/redis.conf

但是,我不知道如何编写配置。所以我在 this 中找到了默认配置.但是,我仍然不明白如何设置最大内存。它只是在配置中添加这一行吗?

maxmemory 2mb

对了,我想知道默认内存是多少。我想将内存设置为2GB,怎么办?

然后,我将这一行添加到 redis 配置中以将 maxmemory 设置为 40GB:

maxmemory 41943040

然后我在redis-cli中使用命令:

config get maxmemory

它告诉我:

127.0.0.1:6379> config get maxmemory
1) "maxmemory"
2) "41943040"

但是,当键号大约为 200000 时,我的 java 程序抛出这样的异常:

Exception in thread "Thread-228" redis.clients.jedis.exceptions.JedisDataException: OOM command not allowed when used memory > 'maxmemory'.
    at redis.clients.jedis.Protocol.processError(Protocol.java:117)
    at redis.clients.jedis.Protocol.process(Protocol.java:151)
    at redis.clients.jedis.Protocol.read(Protocol.java:205)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196)
    at redis.clients.jedis.Jedis.hmset(Jedis.java:644)
    at cn.ict.dt2redis.analyser.AbstractAnalyser.pushOne(AbstractAnalyser.java:21)
    at cn.ict.dt2redis.analyser.BatchAbstractAnalyser.run(BatchAbstractAnalyser.java:16)
    at java.lang.Thread.run(Thread.java:722)

我不知道,我是否成功将最大内存设置为 40 GB?怎么做?请给我一些详细的代码。

最佳答案

是的 - 要设置内存限制,只需取消注释 maxmemory .conf 文件中的行。默认值为 0,表示无限制(直到操作系统用完 RAM 并终止进程 - 我建议始终将 maxmemory 设置为合理的值)。

更新:正如@Eric Uldall 在评论中提到的,CONFIG SET maxmemory <sane value> , 其次是 CONFIG REWRITE也应该做的伎俩。这将修改您的 redis.conf 以在重启时保留更改

关于redis - 如何设置Redis最大内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33115325/

相关文章:

golang + redis 并发调度器性能问题

redis - ServiceStack - Redis session 累积

python - Django & Redis : How do I properly use connection pooling?

javascript - Node 错误 - 在 MakeCallback 中使用域属性已被弃用

encryption - 在键值存储中查找加密 key

python - 带有 redis 代理可见性超时的 celery

redis - 在 Kubernetes 中多次部署相同的部署

redis - redis/kafka如何实现禁止重复消费

redis - Redis 命令 ZRANGEBYLEX 返回元素的顺序是什么

python - RQ - 清空和删除队列