javaRedis.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. var redisLib = require('../libs/redis');
  3. /**
  4. * 连接旧javaredis库使用的
  5. * @type {javaRedisCo}
  6. */
  7. var redisCo = redisLib.javaRedisCo;
  8. var C = require('../config');
  9. var F = require('../common/function');
  10. var _ = require('underscore');
  11. _.str = require('underscore.string');
  12. _.v = require('validator');
  13. function redisMgr(app, common_mgr) {
  14. var model_map = app.model_mgr.model_map;
  15. var mgr_map = common_mgr.mgr_map;
  16. var that = this;
  17. /****
  18. * 注意该manager只能操作旧java的redis库
  19. */
  20. /**
  21. * 检查ticket
  22. * @param uid
  23. * @returns {*}
  24. */
  25. this.getTicketByUid = function* (uid) {
  26. var key = C.redisPre.uid_ticket;
  27. var res = yield redisCo.hmget(key, [uid]);
  28. return res;
  29. }
  30. /**
  31. * 获取房间坑位信息
  32. */
  33. this.getRoomMicList = function* (room_id) {
  34. let room_info = yield mgr_map.room.getRoomInfo(room_id);
  35. if (F.isNull(room_info)) {
  36. F.throwErrCode(100200);
  37. }
  38. let room_mic_list = C.redisPre.room_mic_list;
  39. room_mic_list = _.str.vsprintf(room_mic_list, [room_info.uid]);
  40. let mic_key_list = [-1, 0, 1, 2, 3, 4, 5, 6, 7];
  41. let mic_info_list = yield redisCo.hmget(room_mic_list, mic_key_list);
  42. for (let i = 0; i < mic_info_list.length; i++) {
  43. if (!F.isNull(mic_info_list[i])) {
  44. mic_info_list[i] = JSON.parse(mic_info_list[i]);
  45. continue;
  46. }
  47. mic_info_list[i] = {"position": mic_key_list[i], "posState": 0, "micState": 0}
  48. yield redisCo.hmset(room_mic_list, mic_key_list[i], JSON.stringify(mic_info_list[i]));
  49. }
  50. return mic_info_list;
  51. }
  52. }
  53. module.exports = redisMgr;