search

Home  >  Q&A  >  body text

php - 如何统计reids内的特定key

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

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

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

巴扎黑巴扎黑2902 days ago476

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-10 14:30:25

    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> 
    

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-10 14:30:25

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

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

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

    reply
    0
  • Cancelreply