Reputation: 9076
I have just been through this Redis tutorial, https://redis.io/topics/twitter-clone. The essence of it, if I am understanding correctly, is that to view a user's posts, PHP (or other client) has to call Redis for the List
of posts that the user is eligible to view, then has to cycle through that List
, making a separate call to Redis to retrieve each post (which is stored as a Hash
).
All things being equal, it would be better if the client could make a single call to Redis, and Redis could combine the List of posts with the related Hashes and return only the eligible posts. Is this possible? If not, are there alternatives to Redis where it is possible?
Upvotes: 0
Views: 225
Reputation: 49205
You can do it with Lua scripts that you can preload into redis, and execute at will, something like stored procedures in SQL databases. The Twitter clone tutorial is very old and predates Lua scripts in Redis IIRC.
Here is some good documentation on it: https://redislabs.com/ebook/part-3-next-steps/chapter-11-scripting-redis-with-lua/11-1-adding-functionality-without-writing-c/11-1-1-loading-lua-scripts-into-redis/
Upvotes: 6