mysql表如何使用redis保存?

mysql表:

userid username password email
9 Lisi 111111 lisi@163.com

对应redis存储:

127.0.0.1:6379> set user:userid:9:username lisi
OK
127.0.0.1:6379> set user:userid:9:password 111111
OK
127.0.0.1:6379> set user:userid:9:email lisi@163.com
OK
127.0.0.1:6379>
127.0.0.1:6379> keys user:userid:9*    #查找有几个属性
1) "user:userid:9:password"
2) "user:userid:9:username"
3) "user:userid:9:email"
127.0.0.1:6379>

如果要通过username来查找信息, 只能通过再建立一个对应关系

127.0.0.1:6379> set user:username:lisi:userid 9    #建立一个username和userid对应的表
OK
127.0.0.1:6379> 
127.0.0.1:6379> get user:username:lisi:userid    #获取到userid
"9"
127.0.0.1:6379> 
127.0.0.1:6379> keys user:userid:9*    #通过userid找到所有键
1) "user:userid:9:password"
2) "user:userid:9:username"
3) "user:userid:9:email"
127.0.0.1:6379> 
127.0.0.1:6379> get user:userid:9:email    #获取其它键的信息
"lisi@163.com"
127.0.0.1:6379>
posted @ 2019-06-09 22:11  脚本小娃子  阅读(1763)  评论(0编辑  收藏  举报