我现在想把用户信息缓存进Redis里。
用户可以用手机号和身份证来查询,手机号和身份证号都是唯一不可重复的。
是不是需要分别以手机号和身份证号为KEY来存两份资料?
如何可以只存一份数据就可以通过手机号或身份证来取得用户信息?
曾经蜡笔没有小新2017-04-25 09:05:09
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;
给我你的怀抱2017-04-25 09:05:09
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
.
天蓬老师2017-04-25 09:05:09
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.