activeUtil.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --[[
  2. Descripttion:活跃玩家
  3. version:
  4. Author: Neo,Huang
  5. Date: 2021-08-31 17:38:42
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2021-08-31 17:38:43
  8. --]]
  9. local timeUtil = require "utils.timeUtil"
  10. local lib_game_redis = require("lib_game_redis")
  11. local root = {}
  12. ----------------------------------------
  13. -- 活跃
  14. ----------------------------------------
  15. local function get_active_key(date)
  16. local time = date or timeUtil.currentTime()
  17. return "active:uid:" .. timeUtil.toDate(time)
  18. end
  19. -- 增加当天活跃玩家ID
  20. function root.add_active_player(uid)
  21. local key = get_active_key()
  22. lib_game_redis:sadd(key, uid)
  23. end
  24. -- 获取活跃玩家ID列表
  25. function root.get_active_uid_list(date)
  26. local key = get_active_key(date)
  27. return lib_game_redis:smembers(key)
  28. end
  29. ----------------------------------------
  30. -- 被动活跃
  31. ----------------------------------------
  32. local function get_inactive_key(date)
  33. local time = date or timeUtil.currentTime()
  34. return "inactive:" .. timeUtil.toDate(time)
  35. end
  36. -- 增加当天被活跃玩家ID
  37. function root.add_inactive_player(uid)
  38. local key = get_inactive_key()
  39. lib_game_redis:sadd(key, uid)
  40. end
  41. -- 获取活跃玩家ID列表
  42. function root.get_inactive_uid_list(date)
  43. local key = get_inactive_key(date)
  44. return lib_game_redis:smembers(key)
  45. end
  46. -- 删除被活跃玩家列表
  47. function root.del_inactive_uid_list(date)
  48. local key = get_inactive_key(date)
  49. lib_game_redis:del(key)
  50. end
  51. return root