我将 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/