Home  >  Article  >  Backend Development  >  phpredis 怎么存用户信息

phpredis 怎么存用户信息

WBOY
WBOYOriginal
2016-06-06 20:35:101608browse

比如一个用户有三个字段:id,name,age
应该怎么存到redis中?
现在有三个用户
id name age
1 张三 10
2 李四 20
3 三四 21
满足查询 name中带‘四’的用户信息?或者id为2的用户信息?类似如此的查询!

回复内容:

比如一个用户有三个字段:id,name,age
应该怎么存到redis中?
现在有三个用户
id name age
1 张三 10
2 李四 20
3 三四 21
满足查询 name中带‘四’的用户信息?或者id为2的用户信息?类似如此的查询!

name中带‘四’的用户信息

这种不太适合用 Redis

存用户信息用 Hash 比较合适。

<code>php</code><code>$redis->hMset('user:1', array('name' => '张三', 'age' => 10));
</code>

获取 id 为 2 的用户信息:

<code>php</code><code>$redis->hGetAll('user:2');
</code>

redis在模糊查找显得无力。建议用mongoDB

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn