0

As I know redis is single threaded solution from client point of view. But what about the general architecture?

Amuse we have some lua script that going to execute several commands on keys that has some TTL. How does redis garbage collections works? Could it interrupt the EVAL execution & evict some value or internal tasks share the single thread with user tasks?

Silk0vsky
  • 941
  • 1
  • 18
  • 34
  • Possible duplicate of [How does redis expire keys?](https://stackoverflow.com/questions/36172745/how-does-redis-expire-keys) – TheDude Apr 26 '18 at 09:07
  • @TheDude this is not a duplicate. This is details request for exceptional case which hadn't been covered in those question neither in documentation provided in form of answer. – Silk0vsky May 01 '18 at 16:51

1 Answers1

2

Lua is majik, and because that is the case time stops when Redis is doing Lua. Put differently, expiration stops once you start running the script in the sense that time does not advance. However, if a key expired before the script started, it will not be available for the script to use.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • 2
    Thanks for the answer! I've dived in the sources https://github.com/antirez/redis/blob/unstable/src/db.c a little & found this: ```now = server.lua_caller ? server.lua_time_start : mstime();``` So when redis tries to evaluate current time for expiration it respects for lua context. – Silk0vsky May 01 '18 at 16:38
  • 1
    @Itamar Haber, thanks for correcting me! And sorry for my wrong answer... – for_stack May 02 '18 at 02:00
  • @for_stack it is my rare pleasure to correct you, and more often it is my pleasure to read your answers - thank you for all the work you're putting here :) – Itamar Haber May 02 '18 at 12:43
  • @Silk0vsky nothing beats reading the source code - happy hacking! – Itamar Haber May 02 '18 at 12:43
  • @ItamarHaber It's also my pleasure to share here :) – for_stack May 03 '18 at 02:25