Lua - Programatically Creating Keys and Storing Keys in Lists

I built some lua code that recursively walks a DAG data structure with each node stored in a pair of keys, one holding the metadata, and another holding a list of children. This works great in non-clustered mode and also great in cluster-mode when I use a prefix like “{task}” to force the hash slot.

However according the specs this is verboten. One place in the docs it said that it isn’t enforced so that people can do it in non-clustered mode. Another source said “it may work but Redis could change it any point so don’t do it.” Another said basically “That type of thing has been working for a while and probably won’t break any time soon.”

I rewrote it to follow the rules (using redis.py bindinds) but found that I had a bunch of race conditions. Transactions didn’t seem quite right as the keys aren’t known apriori (recursive).

Any one have thoughts on this?

Above I said a pair of keys. There are actually four. Metadata, two counters for use with INCR, and the child list. I am creating three of the keys programatically from the core key by appending suffixes. Again this breaks the guidelines but seems safe in practice. Thoughts?

Hi Joel

The guidelines, which are perhaps a little unclear, do not apply to your case.
Put differently, as long as pin all involved keys to the same slot, you’re good.
That said, you could end up with “hot” slots.

Thanks! That is what I figured…and the hot slots is a guaranteed problem. Maybe by the time I hit the scale problem redis will support routing redis API invocations in lua to the correct nodes. :-p