Because the user information is cached in the Redis hash type
Demand is to get a list of users, such as 30 users per page, want to get the user information of these 30 users at once
But Redis does not have a way to get the hash key in bulk!
May I ask how I can solve it? Is there a problem with my design?
such as user hash key for userinfo:1 user:info:2 user:info:3 user:info:4 ....
These hash keys store the user information
Want to get userinfo:1-30 hash value at once
Reply content:
Because the user information is cached in the Redis hash type
Demand is to get a list of users, such as 30 users per page, want to get the user information of these 30 users at once
But Redis does not have a way to get the hash key in bulk!
May I ask how I can solve it? Is there a problem with my design?
such as user hash key for userinfo:1 user:info:2 user:info:3 user:info:4 ....
These hash keys store the user information
Want to get userinfo:1-30 hash value at once
Looping with LUA scripts
eval "local rst={}; for i,v in pairs(KEYS) do rst[i]=redis.call('hgetall', v) end; return rst" 2 user:1 user:2
127.0.0.1:6379> hgetall user:21) "Age" 2) "3" "name" 4) "Tom" 127.0.0.1:6379> Hgetall user:11) "name" 2) "Jack" 3) "a GE "4)" 127.0.0.1:6379> eval "local rst={}; For i,v in pairs (KEYS) do Rst[i]=redis.call (' Hgetall ', v) end; Return rst "2 user:1 user:21) 1)" "Name" 2) "Jack" 3) "Age" 4) "2" + 1) "Age" 2) "3" " name" 4) "Tom"
Use Lua, or multi.
My word is a for loop, multi is a business.