scala - Redis 中的 "Null reply"到底是什么?

标签 scala redis

我将 Redis 与 Scala(rediscala 库)结合使用。我需要创建这样的交易:

redisTransaction.watch(key)
redisTransaction.zremrangebyscore(key, limit, limit) *>
redisTransaction.zadd(key, (someValue, entry)) *>
redisTransaction.set[ByteString](s"$lastSeqNumKey", sequenceNum) *>
redisTransaction.exec().void

最后一个表达式应该返回一个 Future[Unit],我希望它在事务失败的情况下失败。但是,Redis 文档指出:

When using WATCH, EXEC can return a Null reply if the execution was aborted.

“空回复”到底是什么?我的 Future[Unit] 是否有可能以 null 值或空字符串或类似的值成功?我想编写一个测试,我需要一些有关它的提示。

最佳答案

一个更正,redisTransaction.exec() 上没有void 方法。

简答:

exec() 如果事务失败或执行中止,调用将返回 Future(MultiBulk(None))

长答案:

正如文档所说,

When using WATCH, EXEC can return a Null reply if the execution was aborted.

并链接到 NULL reply的解释

RESP Bulk Strings can also be used in order to signal non-existence of a value using a special format that is used to represent a Null value. In this special format the length is -1, and there is no data, so a Null is represented as:

"$-1\r\n" This is called a Null Bulk String.

The client library API should not return an empty string, but a nil object, when the server replies with a Null Bulk String. For example a Ruby library should return 'nil' while a C library should return NULL (or set a special flag in the reply object), and so forth

这表明服务器将回复 NULL 响应,客户端必须处理它。它不能是空字符串,在这个库中,它处理解码并将来自服务器的响应映射为 MultiBulk(None)

有一个test case用于解码来自 Redis 的 NULL 响应。

关于scala - Redis 中的 "Null reply"到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51394978/

相关文章:

java - 玩! 2 从 Controller 在 View 中渲染 JSON 数据

scala - 如何对案例类字段之间的相互依赖关系进行建模?

asp.net-core - RedisConnectionException : . 网络核心连接到 AWS 中的 Redis 缓存

Redis:集群新增节点后是否需要重新平衡哈希槽

caching - Redis StackExchange 存储 500k 类

caching - redis本身有缓存吗?

scala - 如何将 1000 条记录批量插入数据库?

Scalaz 迭代器 : "Lifting" `EnumeratorT` to match `IterateeT` for a "bigger" monad

scala - 获取一系列 Spark RDD 的列

redis - DigitalOcean pod 具有未绑定(bind)的即时 PersistentVolumeClaims