所有。我写了一个数据项给Redis。然后,我从Redis中读取数据项。
由于可能有多个服务器接受这些Redis请求并满足它们,如果我在发出读取请求之前1 ms发出写入请求(假设它们都是由同一个进程完成的)我保证读取请求不会先被处理,我得到一个回复,例如"该数据项目不存在"?
答案 0 :(得分: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...