redis-lua-scripts icon indicating copy to clipboard operation
redis-lua-scripts copied to clipboard

SQL like BYs in LUA?

Open doodirock opened this issue 10 years ago • 2 comments

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.

doodirock avatar Aug 05 '14 18:08 doodirock

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.

dcartoon avatar Aug 06 '14 16:08 dcartoon

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.

doodirock avatar Aug 06 '14 16:08 doodirock