Home  >  Article  >  Backend Development  >  Redis 如何维护一个 用户列表

Redis 如何维护一个 用户列表

WBOY
WBOYOriginal
2016-06-06 20:14:091487browse

想通过redis 维护一个用户列表。
1.redis提供list、set、hash map,该选择那个数据结构,保存一个php 的User对象合适呢?
2.怎么通过redis 维护一个 用户列表 呢? 可增可减,可以查看数量。

回复内容:

想通过redis 维护一个用户列表。
1.redis提供list、set、hash map,该选择那个数据结构,保存一个php 的User对象合适呢?
2.怎么通过redis 维护一个 用户列表 呢? 可增可减,可以查看数量。

如果是无序的话,用set存储用户的唯一id,如SADD users {id};然后用hash map存储用户的各种属性,如HSET user_{id} name "Tom"。这样你可以在set中查看用户数量,然后在set中增减的同时,同步操作hash中的对应user就行了

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