Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a "Null reply" in Redis?

Tags:

redis

scala

I use Redis with Scala (rediscala library). I need to create a transaction like this:

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

The last expression should return a Future[Unit] which I expect to fail in case of failed transaction. However, Redis documentation states that:

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

What exactly is a "null reply"? Is it possible that my Future[Unit] will succeed with a null value, or empty String or something similar? I'd like to write a test and I need some hints about it.

like image 323
kciesielski Avatar asked Jul 18 '18 06:07

kciesielski


People also ask

Does Redis support atomicity?

Redis transaction is also atomic. Atomic means either all of the commands or none are processed.

What is set in Redis?

Redis sets are unordered collections of unique strings that act like the sets from your favorite programming language (for example, Java HashSets, Python sets, and so on). With a Redis set, you can add, remove, and test for existence O(1) time (in other words, regardless of the number of set elements).


1 Answers

One correction, there is no void method on redisTransaction.exec().

Short answer:

exec() call will return Future(MultiBulk(None)) if the transaction fails or the execution is aborted.

Long answer:

As the documentation says,

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

and links to NULL reply 's explanation

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

This points to the fact that server will reply with a NULL response and the client has to deal with it. It can't be an empty string and in this library it is dealt to decode & map the response from server as MultiBulk(None)

There is a test case for the decoding of NULL responses from redis.

like image 115
curious Avatar answered Oct 14 '22 20:10

curious