console.log for redis lua on macOS

April 5th, 2024


redis.log(redis.LOG_WARNING, 'foo')
tail -f /usr/local/var/db/redis/redis-server.log

When debugging a redis lua script, it’s often convenient to be able to log, especially when the script is integrated in a larger system and you’d rather not change the script’s signature or log to some random key that you need to clean up later. redis.log is your typical print statement, but astoundingly not mentioned in the scripting or debugging tutorials. Yes, it’s probably massively inferior to real debugging, but I’m often too lazy to do things the right way. Plus, I get the sense that the redis debugger is for debugging with redis-client, whereas sometimes I’m debugging from my application.

> brew info redis

Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/redis/bin/redis-server /opt/homebrew/etc/redis.conf

Search for logfile entry, which in my case, was /usr/local/var/db/redis/redis-server.log. If you had to change it, restart the redis server. Then tail -f /usr/local/var/db/redis/redis-server.log and run a script like EVAL "redis.log(redis.LOG_WARNING, 'foo')" 0. You should see the output in the log file.

I’m sure there are less dumb ways of doing it, but this is my way.