redis可以多key对应一个value吗?
仅有的幸福
仅有的幸福 2017-04-25 09:03:09
0
3
1371

我现在想把用户信息缓存进Redis里。
用户可以用手机号和身份证来查询,手机号和身份证号都是唯一不可重复的。
是不是需要分别以手机号和身份证号为KEY来存两份资料?
如何可以只存一份数据就可以通过手机号或身份证来取得用户信息?

仅有的幸福
仅有的幸福

reply all(3)
曾经蜡笔没有小新

The following ideas are for reference only:

1: Both the mobile phone number and the ID number are unique. Choose either one as the key for user information. For example, use the mobile phone number mobile as the key and use a hash structure;
mobile->hash
2: Create an ID card and The corresponding relationship between mobile phone numbers uses the string structure: id->mobile
3: User data can be directly queried with the mobile phone number. If you use an ID card, first find the corresponding mobile phone number, and then get the hash data based on the mobile phone number;

给我你的怀抱

Personally, I think you can use Hash to save. For example, user A has a mobile phone number of 123 and an ID number of 456. The key can be in the form of A:手机号或者A:身份证号.

That’s okayHSET A:123 phone 123 id 456或者HSET A:456 phone 123 id 456.

Peter_Zhu

Ideal situation: Regardless of the foreigner’s ID card and mobile phone number, your idea is totally fine. Map both the ID card number and mobile phone number to the key. When calling this key, if the key is 15 or 18 digits, it is the ID card, and 11 digits is the mobile phone number. It is OK to judge the length.
But in actual applications, it is recommended to store these two fields separately.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template