Redis SET命令不能失败,但是可以吗?

标签 redis

我正在尝试调试我遇到的一些 Redis 问题,但发现了一些关于 SET 命令的不确定文档。

在我的 Redis 配置中;我有以下几行(片段):

# Note: with all the kind of policies, Redis will return an error on write
#       operations, when there are not suitable keys for eviction.
#
#       At the date of writing this commands are: set setnx setex append

关于documentation page for the SET command我发现:

Status code reply: always OK since SET can't fail.

对最终行为有什么见解吗?

最佳答案

tl;dr:如果 redis 实例内存不足,SET 将返回错误响应。

据我从 redis.c 中的源代码可以看出,基本上当一个命令被处理时,流程是这样的(伪代码):

IF memory is needed
    IF we can free keys
        Free keys
        Process the command
            SET -> process and return OK response
    ELSE return error response
ELSE
    Process command
        SET -> process and return OK response

虽然不完全是这样写的,但基本思路是:在执行命令之前会检查内存,所以即使命令不会失败,如果没有内存也会返回错误响应,不管实际是什么命令的响应。

关于Redis SET命令不能失败,但是可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911248/

相关文章:

node.js - Hapi.js Catbox Redis 返回 "server.cache is not a function"

redis - 如何清除redis中的SLOWLOG?

c# - Booksleve 中的 Redis 事务

scala - 从 docker-it-scala 旋转 redis

javascript - 使用nodejs时多次调用redis客户端的连接事件

c# - ServiceStack.Redis 服务可用性

Redis Slave Master 连接失败 Slave 日志显示 : Unable to connect to MASTER: Permission denied

redis - 如何使用 redisTemplate 获取和设置数据到特定的 redis 数据库索引?

Redis 将所有键从一个数据库移动到另一个数据库

c# - 使用 C# 扫描 Redis 缓存中的缓存键