redis-lua-scripts
redis-lua-scripts copied to clipboard
SQL like BYs in LUA?
Has anyone done anything with Lua to mimic SQL sorting of hashes? I'd love to see something for doing multiple BYs. So something like...
sort stuff BY newstuff:*->key1 DESC BY newstuff:*->key2 DESC BY newstuff:*->key3 ASC GET newstuff:*->json
Currently this isnt possible in redis as it will only sort by the last command IE newstuff:*->key3 ASC
It would be great to get a more SQL like sorting feature to sort large hashes and treat them more like tables.
Not that I know of. While useful, that sounds like something that would not perform well in Redis, as those sorts could potentially be expensive and block other commands from executing.
Could you either store your scores in multiple sorted sets, or create a single composite score and store that in a sorted set (where the set value is the hash key)? That would would make finding the top items a much faster operation. Doing a pipelined multi get for hashes by key at that point would be pretty fast, or you could potentially use Lua to create an HMMGET-type command that will allow you to fetch multiple hashes with a single command.
Makes sense. I think possibly the HMMGET type would work well. It seems sorting by multiples is a very common issue in Redis with no solid approach. http://www.dr-josiah.com/2013/10/multi-column-sql-like-sorting-in-redis.html seems like the closest to SQL. Thanks again for the feed back. Great project.