1

all. I write a data item to Redis. Then later, I read the data item out of Redis.

Since there may be multiple servers taking these Redis requests and satisfying them, if I make the write request 1 ms before I make the read request (suppose they're both being done by the same process) am I assured that the read request won't be processed first, and I get a response back like "that data item doesn't exist"?

user2171796
  • 397
  • 2
  • 16

1 Answers1

0

Assuming that the commands are being issued in sequence, you can assume that they will be atomic and single-threaded operations. Read more about this in this stackoverflow answer.

The above is True for a single Redis server, and not guaranteed for a Cluster behavior (thanks @mwp). In that situation, I'd recommend adding a check at the client level. If key doesn't exist when Redis makes its GET call, by default a nil value is returned.

Last note: depending on your implementation you may want to look into storing your redis items in a list, LPUSH-ing the write requests and BRPOP-ing the out values so you would always be guaranteed a value exists...

Community
  • 1
  • 1
dizzyf
  • 3,263
  • 19
  • 29
  • Yes, but here's clearly asking about Redis Cluster, or some kind of Redis cluster, so the rules that govern a single single-threaded instance of Redis may or may not apply here. – mwp Sep 01 '16 at 19:31
  • @mwp: Oh shoot, you are quite right. I missed that part of the question. – dizzyf Sep 01 '16 at 19:51
  • Hmm. Thanks for the insights. I will go and read up on LPUSH and BRPOP. If I had paid more attention in geography class when I was a little faun, I might know those places. I am using Heroku's RedisCloud. So I really have no idea what they're doing behind the scenes. They encourage you to think of it as "your Redis database" so I hope their infrastructure supports that illusion. – user2171796 Sep 02 '16 at 21:31