Describe the bug
lua script will not persist in aof file when aof-use-rdb-preamble is set as no, and then execute bgrewriteaof command.
To reproduce
# turn off aof and rdb preamble
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> config get aof-use-rdb-preamble
1) "aof-use-rdb-preamble"
2) "no"
# load lua script
127.0.0.1:6379> SCRIPT FLUSH
OK
127.0.0.1:6379> script load "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"
"a42059b356c875f0717db19a51f6aaca9ae659ea"
127.0.0.1:6379> BGREWRITEAOF
Background append only file rewriting started
we can find that the aof file is empty。
Additional information redis_version:6.2.4
Comment From: oranagra
@opt-m LUA scripts were never intended to be persisted, the contract with the application is that it needs to re-load them when needed if they're missing.. or put differently, EVAL was initially intended to always be used (i.e. the script is part of the application client side, not the server side), and SCRIPT LOAD and EVALSHA is just an optimization.
The reasons scripts may find themselves replicated or persisted were in case these were write scripts (ones that perform modifications to the data), in which case they had to be propagated to AOF and replicas and get executed there too. For many years this was only done by propagating an EVAL or SCRIPT LOAD command to the AOF or replication stream, and only recently, they were added to the RDB file to comply with PSYNC2 (a way for a master and replica to change roles without full-sync).
also worth to mention that today scripts are by default propagated as effects (see lua-replicate-commands config), and the next version of redis (7.0), is going to completely disable the old way of script replication (delete all the code that handles that together with that config). so after doing that, we won't save any scripts to the RDB anymore, or propagate a SCRIPT LOAD or EVAL commands to either AOF or replicas.