php - 如何统计reids内的特定key
巴扎黑
巴扎黑 2017-04-10 14:28:25
0
2
478

是这样,项目的在线好友是用redis的set做的,在每个用户登录的时候

set user_123466 时间戳 60*5  //user_用户id

这样里面有很多user_*的数据,现在要统计在线人数,怎么查找呢?
当前库还有许多其他信息,所以不能用dbsize,
info里面的key数量也不能用.

巴扎黑
巴扎黑

reply all(2)
大家讲道理

redis的keys命令可以满足你的查询要求。

http://redis.io/commands/keys

redis> MSET one 1 two 2 three 3 four 4
OK
redis> KEYS *o*
1) "one"
2) "two"
3) "four"
redis> KEYS t??
1) "two"
redis> KEYS *
1) "one"
2) "two"
3) "three"
4) "four"
redis> 
Peter_Zhu

20w数据测试,
在cli模式keys *用时11秒,
在php里面用时0.2秒, 0.0

$re = $redis->keys('*');    
dump(count($re));

可能php扩展里面做了些什么

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template