加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – Redis中的“Null回复”究竟是什么?

发布时间:2020-12-16 08:56:16 所属栏目:安全 来源:网络整理
导读:我使用Redis和 Scala( rediscala库).我需要创建一个这样的事务: redisTransaction.watch(key)redisTransaction.zremrangebyscore(key,limit,limit) *redisTransaction.zadd(key,(someValue,entry)) *redisTransaction.set[ByteString](s"$lastSeqNumKey",se
我使用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值或空String或类似的东西成功?我想写一个测试,我需要一些关于它的提示.

解决方法

一次更正,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:

"$-1rn" 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(无)

有一个test case用于解码redis的NULL响应.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读