I have some keys in Redis <K,V> where V is a comma separated string of sub strings V: <v1,v2,v3,...,vn>.
Until now I was simply setting keys by using a transaction in Jedis (Redis API in Java). But a new requirement needs me to perform some operations on the existing keys. So I have two options:
- Retrieve Keys, Perform Operations, Set keys
- Code the operations in Lua and pass the file along with keys as arguments.
Option 2 seems faster as it will save a round trip but I have the following considerations:
- What if Lua execution fails in between at Redis, say after n keys. (May be an issue with script or Redis). Does Redis ensure consistency? In option 1, I could abort writing and prevent inconsistent state.
- Lua script as I understand takes keys as arguments. However I need to operate on 10 million keys. Is Lua fine with such a huge argument list?
My Solution
Since as said by the answer below none of them are a feasible choice. I wrote my own Redis command in C and compiled the source. So now I will call
redis-cli> MyCommand K V
For each <K,V> in pipeline. I followed the tutorial here - Hacking Redis. However it might not be adequate and require one to browse and understand some code by yourself!