Redis Bulk Gets the hash key data

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.