如何读取redis中的key值中的结果
程序员文章站
2022-03-30 16:57:53
...
现在redis中有一个key,key名叫 wz_user
我读取wz_user
$redis->hGetAll("wz_user");
出现值:
???Array ( [1170202] => a:52:{ s:2:"id";s:7:"1170202"; s:3:"pid";s:1:"0";s:8:"user";s:11:"13520966111";s:8:"password";s:32:"04cb57ee0653c0f49b5ec72afcf9a15d";s:5:"image";s:0:"";s:5:"email";s:0:"";s:8:"sharenum";s:1:"0";s:9:"invitenum";s:1:"0";s:8:"clicknum";s:1:"0";s:5:"money";s:5:"1.000";s:6:"remain";s:5:"1.000";s:12:"invite_money";s:5:"0.000";s:8:"topmoney";s:5:"1.000";s:6:"amount";s:1:"0";s:6:"profit";s:1:"0";s:7:"levelid";s:1:"1";s:7:"account";s:0:"";s:6:"txname";s:0:"";s:3:"tip";s:0:"";s:5:"locks";s:1:"1";s:6:"adjust";s:0:"";s:2:"ip";s:14:"61.148.221.114";s:4:"area";s:0:"";s:8:"reg_type";s:1:"0";s:7:"created";s:10:"1437445187";s:7:"encrypt";s:6:"DtC1ju";s:6:"invite";s:0:"";s:7:"addtype";s:1:"0";s:2:"nc";s:1:"0";s:5:"isOne";s:1:"1";s:6:"freeze";s:1:"0";s:8:"freetime";s:1:"0";s:6:"keyong";s:1:"0";s:5:"close";s:1:"0";s:9:"closetime";s:1:"0";s:10:"tel_status";s:1:"1";s:7:"payment";s:1:"0";s:10:"paymentime";s:1:"0";s:8:"is_white";s:1:"0";s:9:"whitetime";s:1:"0";s:5:"token";s:0:"";s:8:"platform";s:1:"0";s:8:"is_water";s:1:"0";s:9:"watertime";s:1:"0";s:10:"active_val";s:1:"0";s:5:"score";s:5:"0.000";s:10:"sentizinum";s:1:"0";s:10:"teamleader";s:1:"0";s:15:"distributor_img";s:0:"";s:17:"distributor_money";s:5:"0.000";s:16:"distributor_team";s:1:"0";s:18:"distributor_indent";s:1:"0";} )
类似于值里面的 s:2:"id";s:7:"1170202"; 在数据库中是id=1170202
s:3:"pid";s:1:"0";s:8:"user";s:11:"13520966111"; 数据库中user = 13520966111
应该如何把这些值从redis的value中单独取出来呢?
我读取wz_user
$redis->hGetAll("wz_user");
出现值:
???Array ( [1170202] => a:52:{ s:2:"id";s:7:"1170202"; s:3:"pid";s:1:"0";s:8:"user";s:11:"13520966111";s:8:"password";s:32:"04cb57ee0653c0f49b5ec72afcf9a15d";s:5:"image";s:0:"";s:5:"email";s:0:"";s:8:"sharenum";s:1:"0";s:9:"invitenum";s:1:"0";s:8:"clicknum";s:1:"0";s:5:"money";s:5:"1.000";s:6:"remain";s:5:"1.000";s:12:"invite_money";s:5:"0.000";s:8:"topmoney";s:5:"1.000";s:6:"amount";s:1:"0";s:6:"profit";s:1:"0";s:7:"levelid";s:1:"1";s:7:"account";s:0:"";s:6:"txname";s:0:"";s:3:"tip";s:0:"";s:5:"locks";s:1:"1";s:6:"adjust";s:0:"";s:2:"ip";s:14:"61.148.221.114";s:4:"area";s:0:"";s:8:"reg_type";s:1:"0";s:7:"created";s:10:"1437445187";s:7:"encrypt";s:6:"DtC1ju";s:6:"invite";s:0:"";s:7:"addtype";s:1:"0";s:2:"nc";s:1:"0";s:5:"isOne";s:1:"1";s:6:"freeze";s:1:"0";s:8:"freetime";s:1:"0";s:6:"keyong";s:1:"0";s:5:"close";s:1:"0";s:9:"closetime";s:1:"0";s:10:"tel_status";s:1:"1";s:7:"payment";s:1:"0";s:10:"paymentime";s:1:"0";s:8:"is_white";s:1:"0";s:9:"whitetime";s:1:"0";s:5:"token";s:0:"";s:8:"platform";s:1:"0";s:8:"is_water";s:1:"0";s:9:"watertime";s:1:"0";s:10:"active_val";s:1:"0";s:5:"score";s:5:"0.000";s:10:"sentizinum";s:1:"0";s:10:"teamleader";s:1:"0";s:15:"distributor_img";s:0:"";s:17:"distributor_money";s:5:"0.000";s:16:"distributor_team";s:1:"0";s:18:"distributor_indent";s:1:"0";} )
类似于值里面的 s:2:"id";s:7:"1170202"; 在数据库中是id=1170202
s:3:"pid";s:1:"0";s:8:"user";s:11:"13520966111"; 数据库中user = 13520966111
应该如何把这些值从redis的value中单独取出来呢?
回复讨论(解决方案)
hget就是取一个数据呀。
你的数据结构是什么样子的
这是序列化后的值,可用 unserialize 反序列化
感谢xuzuning , 遍历一下,得到值后,反序列化一下就可以了
Array( [id] => 1170202 [pid] => 0 [user] => 13520966111 [password] => 04cb57ee0653c0f49b5ec72afcf9a15d [image] => [email] => [sharenum] => 0 [invitenum] => 0 [clicknum] => 0 [money] => 1.000 [remain] => 1.000 [invite_money] => 0.000 [topmoney] => 1.000 [amount] => 0 [profit] => 0 [levelid] => 1 [account] => [txname] => [tip] => [locks] => 1 [adjust] => [ip] => 61.148.221.114 [area] => [reg_type] => 0 [created] => 1437445187 [encrypt] => DtC1ju [invite] => [addtype] => 0 [nc] => 0 [isOne] => 1 [freeze] => 0 [freetime] => 0 [keyong] => 0 [close] => 0 [closetime] => 0 [tel_status] => 1 [payment] => 0 [paymentime] => 0 [is_white] => 0 [whitetime] => 0 [token] => [platform] => 0 [is_water] => 0 [watertime] => 0 [active_val] => 0 [score] => 0.000 [sentizinum] => 0 [teamleader] => 0 [distributor_img] => [distributor_money] => 0.000 [distributor_team] => 0 [distributor_indent] => 0)
xuzuning 感谢,这个问题已经搞定,
我现在还有个问题,想问一下
因为这个库是一个联合查询的库,里面有很多联合查询的条件,所以采用的redis,现在想把查询的信息不经过mysql,直接从redis里面查,如何利用得到的这些得到的值当判断条件?
比如redis中,在这个wz_user key中的数据一共有100W条,现在我想把key中存入的数据作为数据,然后判断 user = 13520966111 的时候,从redis中取出这条数据 , 或者是当locks = 1 时,取出这100W条中所有的locks=1的数据。