Company
Date Published
Author
Redis
Word count
1485
Language
English
Hacker News points
None

Summary

Lua scripting is a powerful feature of Redis, but it can be tricky to get right. The EVAL command accepts full Lua source followed by keys count, keys, and arguments, while SCRIPT LOAD lets you send the source code once and receive a SHA-1 digest for later use with EVALSHA. However, if you try to run a script that doesn't exist in the cache, you'll get an error. RedisPy abstracts away managing SHA-1 hashes and loading scripts, making it easier to work with Lua scripting. It also provides abstractions around pipelining and transactions, which can be used to ensure atomicity and avoid chaotic SCRIPT FLUSHing or cache fills and evictions. However, using the register_script function within a pipeline or transaction may introduce risks if not handled carefully, but it's not necessarily something to avoid in all cases.