0

AFAIK redis is a single threaded and its uses event loop under the hood. I would want to understand 2 things:

  1. are all redis commands synchronous?
  2. if they are asynchronous
  SET mykey "Hello" (first command)
  GET mykey (second command)

there is a possibility for the second command to return nil, if the set command isn't executed yet. Is that correct?

1 Answers1

0

Redis is single-threaded , which means all commands should be atomic. For details

In your above example; If the SET command gets to executed first then GET command will wait until SET completion; if GET command gets to executed first then then it will return nil and SET will subsequently be executed. so each command execution is atomic.

refer documentation; https://redis.io/topics/faq.

ps: for redis4.0 there is some multi-threading capability; refer documentation for details

choppe
  • 493
  • 2
  • 11
  • Meaning a GET command in this case is actually blocking if the SET command is not completed yet? – Navindran Baskaran Apr 05 '20 at 13:05
  • Yes; since redis is single threaded it accepts commands in sequential fashion and executes them atomically. – choppe Apr 05 '20 at 13:27
  • You can refer to this thread as well for details https://stackoverflow.com/questions/48035646/if-redis-is-single-threaded-how-can-it-be-so-fast?rq=1 – choppe Apr 05 '20 at 13:47