def __initRedisLua(self): k1, k2, k3 = self.matchPlugin.playingRankingKey(self.bigRoomId), \ self.matchPlugin.rankingKey(self.bigRoomId), \ self.matchPlugin.enterMatchTotalKey(self.bigRoomId) getPlayinLenLua = 'return {redis.call("ZCARD", "%s"), redis.call("LLEN", "%s"), redis.call("GET", "%s")}' % ( k1, k2, k3) userLeaveLua = ''' local ret = redis.call("ZREM", "%s", ARGV[1]) if ret == 1 then redis.call("RPUSH", "%s", ARGV[1]); end return {redis.call("ZCARD", "%s"), redis.call("LLEN", "%s"), redis.call("GET", "%s"), ret} ''' % (k1, k2, k1, k2, k3) # self.userLeaveLua += self.getPlayinLenLua userSigninLua = 'redis.call("ZADD", "%s", %s, ARGV[1]);' % ( k1, self.matchPlugin.match_room_confs[self.bigRoomId]["buyIn"]) userDelaySigninLua = userSigninLua + 'return redis.call("INCR", "%s");' % (k3) # 注册脚本 self.getPlayinLenLuaSha = daobase.loadLuaScripts("mtt_room_getPlayinLenLua_%s" % self.bigRoomId, getPlayinLenLua) self.userLeaveLuaSha = daobase.loadLuaScripts("mtt_room_userLeaveLua_%s" % self.bigRoomId, userLeaveLua) self.userSigninLuaSha = daobase.loadLuaScripts("mtt_room_userSigninLua_%s" % self.bigRoomId, userSigninLua) self.userDelaySigninLuaSha = daobase.loadLuaScripts("mtt_room_userDelaySigninLua_%s" % self.bigRoomId, userDelaySigninLua)
def loadLuaScripts(cls): scripts = { cls.setpacketdata_key: cls.setpacketdata, cls.selectpacket_key: cls.selectpacket, cls.getpacketnumber_key: cls.getpacketnumber } for x in scripts: daobase.loadLuaScripts(x, scripts[x])
def __init__(self): daobase.loadLuaScripts(self._set_user_score_alias, self._set_user_score_script) daobase.loadLuaScripts(self._get_user_alias, self._get_user_script) daobase.loadLuaScripts(self._remove_user_alias, self._remove_user_script) daobase.loadLuaScripts(self._get_topn_alias, self._get_topn_script)
def _getPrize(self, itemId=""): key = self.dbPrefix + self.id + self.PACKAGES if not itemId: prizesJson = daobase.executeMixCmd('LPOP', key) else: global get_content_by_item_sha if not get_content_by_item_sha: luaName = 'hall_red_envelope_get_content_by_item' get_content_by_item_sha = daobase.loadLuaScripts(luaName, get_content_by_item_script) prizesJson = daobase.executeMixCmd("EVALSHA", get_content_by_item_sha, 1, key, itemId) return prizesJson
def __init__(self): daobase.loadLuaScripts(self._REDIS_LUA_PERIOD_LIMIT_LOCK_NAME, self._REDIS_LUA_PERIOD_LIMIT_LOCK_SCRIPT) daobase.loadLuaScripts(self._REDIS_LUA_PERIOD_LIMIT_UNLOCK_NAME, self._REDIS_LUA_PERIOD_LIMIT_UNLOCK_SCRIPT) daobase.loadLuaScripts(self._REDIS_LUA_PERIOD_LIMIT_DELIVERY_NAME, self._REDIS_LUA_PERIOD_LIMIT_DELIVERY_SCRIPT)
def initialize(cls): if cls._hasLoadedScript: return cls._scriptName = "activity_exchange_code_script" cls._script = ''' local userId = tostring(KEYS[1]) local serial = tostring(KEYS[2]) local excode = tostring(KEYS[3]) local unique = tonumber(KEYS[4]) local userkey = "excodeuser:"******"excodeready:"..serial local finishkey = "excodefinish:"..serial if unique >= 0.9 then local isdeal = redis.call("SISMEMBER", userkey, userId) if isdeal == 1 then return 1 end end local isfinish = redis.call("SISMEMBER", finishkey, excode) if isfinish == 1 then return 2 end local isexist = redis.call("SISMEMBER", readykey, excode) if isexist == 0 then return 3 end redis.call("SADD", userkey, userId) redis.call("SMOVE", readykey, finishkey, excode) return 0 ''' daobase.loadLuaScripts(cls._scriptName, cls._script) ftlog.info('ExchangeCode->initialize', cls._scriptName) cls._hasLoadedScript = True return True
def _getPrize(self, itemId=""): key = self.dbPrefix + self.id + self.PACKAGES if not itemId: prizesJson = daobase.executeMixCmd('LPOP', key) else: global get_content_by_item_sha if not get_content_by_item_sha: luaName = 'hall_red_envelope_get_content_by_item' get_content_by_item_sha = daobase.loadLuaScripts( luaName, get_content_by_item_script) prizesJson = daobase.executeMixCmd("EVALSHA", get_content_by_item_sha, 1, key, itemId) return prizesJson
def initialize(cls, serverId): """初始化,加载lua脚本,清除serverId对应的数据 """ ftlog.debug('CreateTableData.initialize serverId:', serverId , ' load_lua_script:', cls._load_lua_script) if not cls._load_lua_script: cls._load_lua_script = True daobase.loadLuaScripts(cls.ADD_CREATE_TABLE_NO_SCRIPT_NAME, cls._add_create_table_no_script) daobase.loadLuaScripts(cls.REMOVE_CREATE_TABLE_SCRIPT_NAME, cls._remove_create_table_script) daobase.loadLuaScripts(cls.CLEAR_CREATE_TABLE_SCRIPT_NAME, cls._clear_create_table_script) cls._clearCreateTableData(serverId)
def initialize(cls): if not cls.hasLoadedScript: daobase.loadLuaScripts(cls.EXCHANGE_SCRIPT, cls.__exchange_script) daobase.loadLuaScripts(cls.HANDLE_EVENT_SCRIPT, cls.__handle_event_script) cls.hasLoadedScript = True
def __init__(self): daobase.loadLuaScripts(self.UPDATE_LUA_ALIAS, self.UPDATE_STATE_LUA_SCRIPT)
local num = redis.call("LLEN", item) if isitemvip then redis.call("HSET", key_itemmap_vip, item, num) else redis.call("HSET", key_itemmap_general, item, num) end if num <= 0 then redis.call("HDEL", key_itemmap_vip, item) redis.call("HDEL", key_itemmap_general, item) end return {item, itemcount} ''' daobase.loadLuaScripts(_REDIS_LUA_PUSHLIST_NAME, _REDIS_LUA_PUSHLIST_SCRIPT) daobase.loadLuaScripts(_REDIS_LUA_GETCOUNT_NAME, _REDIS_LUA_GETCOUNT_SCRIPT) daobase.loadLuaScripts(_REDIS_LUA_GET_NAME, _REDIS_LUA_GET_SCRIPT) _redenvelopeWrapper = None class DdzRedEnvelope(object): _timelist = None _datetime_start = None _datetime_end = None @classmethod def registerListener(cls, eventbus): ftlog.debug("DdzRedEnvelope.registerListener: enter") globalEventBus.subscribe(EventHeartBeat, cls.onHeartBeat)
def __init__(self, namespace): self._key = 'stock:%s' % (namespace) daobase.loadLuaScripts(self._REDIS_LUA_IN_STOCK_NAME, self._REDIS_LUA_IN_STOCK_SCRIPT) daobase.loadLuaScripts(self._REDIS_LUA_OUT_STOCK_NAME, self._REDIS_LUA_OUT_STOCK_SCRIPT)
def initialize(cls): if cls._hasLoadedScript: return cls._scriptName = "activity_exchange_code_script" cls._script = ''' local userId = tostring(KEYS[1]) local serial = tostring(KEYS[2]) local excode = tostring(KEYS[3]) local unique = tonumber(KEYS[4]) local userkey = "excodeuser:"******"excodeready:"..serial local finishkey = "excodefinish:"..serial if unique >= 0.9 then local isdeal = redis.call("SISMEMBER", userkey, userId) if isdeal == 1 then return 1 end end local isfinish = redis.call("SISMEMBER", finishkey, excode) if isfinish == 1 then return 2 end local isexist = redis.call("SISMEMBER", readykey, excode) if isexist == 0 then return 3 end redis.call("SADD", userkey, userId) redis.call("SMOVE", readykey, finishkey, excode) return 0 ''' daobase.loadLuaScripts(cls._scriptName, cls._script) ftlog.info('ExchangeCode->initialize', cls._scriptName) #2018-3-19 新兑换码脚本 xy cls._scriptNameNew = "activity_new_exchange_code_script" cls._scriptNew = ''' local userId = tostring(KEYS[1]) local serial = tostring(KEYS[2]) local excode = tostring(KEYS[3]) local unique = tonumber(KEYS[4]) local deviceId = tostring(KEYS[5]) local receiveNum = tonumber(KEYS[6]) local userkey = "excodeuser:"******"excodedevice:"..serial local useinfokey = "excode:"..serial if unique >= 0.9 then local isdealuser = redis.call("SISMEMBER", userkey, userId) if isdealuser == 1 then return 1 end end local usenum = redis.call("HGET", useinfokey, excode) if usenum then if tonumber(usenum) >= receiveNum then return 4 end else return 3 end local isdealdevice = redis.call("SISMEMBER", devicekey, deviceId) if isdealdevice == 1 then return 5 end redis.call("SADD", userkey, userId) redis.call("SADD", devicekey, deviceId) redis.call("HSET", useinfokey, excode, tonumber(usenum) + 1) return 0 ''' daobase.loadLuaScripts(cls._scriptNameNew, cls._scriptNew) ftlog.info('NewExchangeCode->initialize', cls._scriptNameNew) cls._hasLoadedScript = True return True