Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"MGET ZRANGE z:Type:index offset limit" and global ID for all types #3

Open
marcusgreenwood opened this issue Apr 19, 2013 · 2 comments
Assignees

Comments

@marcusgreenwood
Copy link
Contributor

It would appear that MGET ZRANGE can be chained together in Redis to allow you to return the keys matching the result of a ZRANGE or ZRANGEBYSCORE command. This means that we can reduce the chatter between redis-hq from node and Redis by 1/2 for all data retrieval functions.

A caveat of this is that we need to store the full key for each entity within the sorted set indexes. In order to avoid prefixing the ids with the type name, we could have a global ID rather than an ID per type.

This creates another minor problem which is that it becomes possible to retrive an object of the wrong type with Type.find(). In order to prevent this we could validate the type by storing a "_type" attribute with all stored JSON objects.

@ghost ghost assigned 1602 Apr 19, 2013
@marcusgreenwood
Copy link
Contributor Author

Oops. In fact this does not work
http://stackoverflow.com/questions/15647590/redis-compound-commands-or-command-piping

My test was just getting the results of the keys ZRANGE, 0 and 100. #fail

There is however a solution which involves passing the commands into Lua but will probably be more complex

@marcusgreenwood
Copy link
Contributor Author

This works as a replacement for the ZRANGE function:

eval 'local ids = redis.call("ZRANGE", "z:dev/Content@id", 0, 100); local newIds = {}; for i,v in ipairs(ids) do newIds[i] = "dev/Content:" .. v; end; return redis.call("MGET", unpack(newIds));' 0

Just need to put the parameters for the ZRANGE function and the id prefix as parameters on the EVAL call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants