Redis Lua: Store JSON as MessagePack and Retrieve MessagePack as JSON


JSON is nearly universal in the web world, and Redis Lua scripting supports encoding and decoding it, which can be very useful for having advanced logic based on JSON values without having to fully normalize your database.
Redis Lua scripting also has bindings to MessagePack, which is a structurally compatible format that is much, much more condensed.
Since we have bindings to both, we can potentially save space, but keep the familiar JSON payload on the client side; why not have the best of both worlds?

> EVAL "[the set script]" 1 testkey '{"hello": true}'

> GET testkey

> EVAL "[the get script]" 1 testkey