I have a series of scripts that move elements between Redis Sets. Sometimes these operations need to be atomic. Sometimes one script will fail but others will continue working.
I’m curious what will happen if in one script I run MULTI and start but then the script somehow fails and I never call EXEC or DISCARD – I know that my data integrity is fine because the transaction will never occur, but since the commands are queued somewhere and never executed I’m concerned that if this happens too often (it shouldn’t, but who knows?) I need to clean the queue?
Depends on the exact meaning of ‘Script fails’
If the connection to redis server is lost, then the query buffer will be freed.
If the connection to redis server is still active, and other sections of your code do not use it at all, then the query buffer will continue to occupy memory on the server. By default, idle client connections are not terminated. If you have specified a
timeoutin your redis.conf, the query buffer will eventually be reclaimed.If the connection to the redis server is still active, and another module/function/block in your script reuses the connection, things get more interesting. Any commands they execute will be queued on the server, because they are part of the previous multi block. If this module starts another multi, redis server will respond with “(error) ERR MULTI calls can not be nested”, but the query buffer is NOT cleared. How your application will behave will depend largely on the redis driver you are using.