def redis_do_command(options, userId, roomId, ralias, cmdline): datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] if ralias == 'config': rdb = datas['pokerdict']['config_redis'] elif ralias == 'user': if userId <= 0: return 'param userId ERROR !!' rdb = _getRedisDefCluster(rdbs, userId) elif ralias == 'table': if roomId <= 0: return 'param roomId ERROR !!' rdb = _getRedisDefCluster(rdbs, roomId, 'table') else: rdb = rdbs[ralias] conn = tydb.get_redis_conn(rdb) tylog.debug('redis_do_command->', cmdline) for x in xrange(len(cmdline)): c = cmdline[x] cmdline[x] = _decode_x(c) try: data = conn.execute_command(*cmdline) except Exception, ex: data = str(ex) tylog.error(cmdline)
def redis_do_command(options, userId, roomId, ralias, cmdline): datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] if ralias == 'config' : rdb = datas['pokerdict']['config_redis'] elif ralias == 'user' : if userId <= 0 : return 'param userId ERROR !!' rdb = _getRedisDefCluster(rdbs, userId) elif ralias == 'table' : if roomId <= 0 : return 'param roomId ERROR !!' rdb = _getRedisDefCluster(rdbs, roomId, 'table') else: rdb = rdbs[ralias] conn = tydb.get_redis_conn(rdb) tylog.debug('redis_do_command->', cmdline) for x in xrange(len(cmdline)) : c = cmdline[x] cmdline[x] = _decode_x(c) try: data = conn.execute_command(*cmdline) except Exception, ex: data = str(ex) tylog.error(cmdline)
def redis_del_weakdata(options, userId, resetCheckIn): if userId <= 0 : return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') def delete_nslogin(conn, rkey): conn.hdel(rkey, 'newnslogin.lastlogin') conn.hdel(rkey, 'newnslogin.nslogin') tylog.debug('REDIS HDEL-->[', rkey, 'newnslogin.nslogin, newnslogin.lastlogin]') delkeys.append(rkey + ' newnslogin.nslogin, newnslogin.lastlogin') _execute_scan(conn_datas, 'weak:*:' + str(userId), delete_redis_key) _execute_scan(conn_datas, 'gamedata*:' + str(userId), delete_nslogin) if resetCheckIn : now = int(time.time()) sec_of_1day = 24 * 60 * 60 conn_datas.hset('user:'******'firstDailyCheckin', now - (2 * sec_of_1day)) conn_datas.hset('user:'******'lastDailyCheckin', now - sec_of_1day) del conn_datas return delkeys
def redis_get_config(options, rkey): datas = _getLastOkDefines(options) rdb = datas['pokerdict']['config_redis'] conn = tydb.get_redis_conn(rdb) data = conn.get(rkey) del conn return strutil.loads(data)
def redis_get_config(options, rkey): datas = _getLastOkDefines(options) rdb = datas['pokerdict']['config_redis'] conn = tydb.get_redis_conn(rdb) data = conn.get(rkey) del conn return strutil.loads(data)
def _load_old_datas(redisaddr): actlog.log('Load Redis Old Datas :', redisaddr) # 取得当前的数据库数据 rconn = tydb.get_redis_conn(redisaddr) oldkeys = [] olddatas = {} def get_old_datas(ckeys_): oldkeys.extend(ckeys_) oldvalues = rconn.mget(ckeys_) for x in xrange(len(ckeys_)): # actlog.log('old->', ckeys_[x], '=[', oldvalues[x], ']') olddatas[ckeys_[x]] = oldvalues[x] get_old_datas(["freetime:server", "freetime:db", "freetime:global"]) get_old_datas(["poker:cmd", "poker:oldcmd", "poker:machine", "poker:project", "poker:global"]) get_old_datas(["poker:map.productid"]) get_old_datas(["poker:map.bieventid"]) get_old_datas(["poker:map.clientid"]) get_old_datas(["poker:map.giftid"]) get_old_datas(["poker:map.activityid"]) cur = 0 while cur >= 0: datas = rconn.scan(cur, 'game:*', 999) cur = datas[0] ckeys = datas[1] if ckeys: get_old_datas(ckeys) if cur <= 0: break return oldkeys, olddatas
def redis_del_userdata(options, userId): if userId <= 0: return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) conn_mix = tydb.get_redis_conn(rdbs['mix']) conn_userkeys = tydb.get_redis_conn(rdbs['keymap']) acc, mobile1, snsid, email, devid, mobile2, mobile3, mobile4, devid2 = \ conn_datas.hmget('user:%d' % (userId), 'userAccount', 'mobile', 'snsId', 'email', \ 'mdevid', 'bindMobile', 'phonenumber', 'detect_phonenumber', 'sessionDevId') delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') _execute_scan(conn_datas, '*:' + str(userId), delete_redis_key) _execute_scan(conn_mix, '*:' + str(userId), delete_redis_key) conn_userkeys.delete('devidmap:%s' % (devid)) conn_userkeys.delete('newdevidmap:%s' % (devid)) conn_userkeys.delete('devidmap3:%s' % (devid)) conn_userkeys.delete('devidmap:%s' % (devid2)) conn_userkeys.delete('newdevidmap:%s' % (devid2)) conn_userkeys.delete('devidmap3:%s' % (devid2)) conn_userkeys.delete('snsidmap:%s' % (snsid)) conn_userkeys.delete('mailmap:%s' % (email)) conn_userkeys.delete('accountmap:%s' % (acc)) conn_userkeys.delete('mobilemap:%s' % (mobile1)) conn_userkeys.delete('mobilemap:%s' % (mobile2)) conn_userkeys.delete('mobilemap:%s' % (mobile3)) conn_userkeys.delete('mobilemap:%s' % (mobile4)) del conn_datas del conn_userkeys del conn_mix return delkeys
def redis_del_userdata(options, userId): if userId <= 0 : return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) conn_mix = tydb.get_redis_conn(rdbs['mix']) conn_userkeys = tydb.get_redis_conn(rdbs['keymap']) acc, mobile1, snsid, email, devid, mobile2, mobile3, mobile4, devid2 = \ conn_datas.hmget('user:%d' % (userId), 'userAccount', 'mobile', 'snsId', 'email', \ 'mdevid', 'bindMobile', 'phonenumber', 'detect_phonenumber', 'sessionDevId') delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') _execute_scan(conn_datas, '*:' + str(userId), delete_redis_key) _execute_scan(conn_mix, '*:' + str(userId), delete_redis_key) conn_userkeys.delete('devidmap:%s' % (devid)) conn_userkeys.delete('newdevidmap:%s' % (devid)) conn_userkeys.delete('devidmap3:%s' % (devid)) conn_userkeys.delete('devidmap:%s' % (devid2)) conn_userkeys.delete('newdevidmap:%s' % (devid2)) conn_userkeys.delete('devidmap3:%s' % (devid2)) conn_userkeys.delete('snsidmap:%s' % (snsid)) conn_userkeys.delete('mailmap:%s' % (email)) conn_userkeys.delete('accountmap:%s' % (acc)) conn_userkeys.delete('mobilemap:%s' % (mobile1)) conn_userkeys.delete('mobilemap:%s' % (mobile2)) conn_userkeys.delete('mobilemap:%s' % (mobile3)) conn_userkeys.delete('mobilemap:%s' % (mobile4)) del conn_datas del conn_userkeys del conn_mix return delkeys
def redis_set_userdata(options, userId, key, value): if userId <= 0: return 'param userId ERROR !!' if not key: return 'param key ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn = tydb.get_redis_conn(rdb) conn.hset('user:'******'user:'******'key': key, 'value': data}
def redis_set_userdata(options, userId, key, value): if userId <= 0 : return 'param userId ERROR !!' if not key : return 'param key ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn = tydb.get_redis_conn(rdb) conn.hset('user:'******'user:'******'key' : key, 'value' : data}
def redis_search_all_userdata(options, userId): if userId <= 0 : return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn = tydb.get_redis_conn(rdb) datas = {} def get_data(conn, rkey): tylog.debug('find key->', rkey) datas[rkey] = _execute_redis_fetch(conn, rkey) _execute_scan(conn, '*:' + str(userId), get_data) del conn return datas
def redis_search_all_userdata(options, userId): if userId <= 0: return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn = tydb.get_redis_conn(rdb) datas = {} def get_data(conn, rkey): tylog.debug('find key->', rkey) datas[rkey] = _execute_redis_fetch(conn, rkey) _execute_scan(conn, '*:' + str(userId), get_data) del conn return datas
def redis_del_gamedata(options, userId, gameId): if userId <= 0 : return 'param userId ERROR !!' if gameId <= 0 : return 'param gameId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') _execute_scan(conn_datas, '*:' + str(gameId) + ':' + str(userId), delete_redis_key) del conn_datas return delkeys
def redis_get_usertime(options, userId): if userId <= 0 : return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) infos = [] datas = conn_datas.hmget('user:'******'createTime', 'authorTime') infos.append('user:'******' -> createTime :' + str(datas[0])) infos.append('user:'******' -> authorTime :' + str(datas[1])) def get_game_time(conn, rkey): datas = conn.hmget(rkey, 'createTime', 'authorTime', 'lastlogin') infos.append(rkey + ' -> createTime :' + str(datas[0])) infos.append(rkey + ' -> authorTime :' + str(datas[1])) infos.append(rkey + ' -> lastlogin :'******'gamedata*:' + str(userId), get_game_time) return infos
def redis_del_gamedata(options, userId, gameId): if userId <= 0: return 'param userId ERROR !!' if gameId <= 0: return 'param gameId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') _execute_scan(conn_datas, '*:' + str(gameId) + ':' + str(userId), delete_redis_key) del conn_datas return delkeys
def redis_get_usertime(options, userId): if userId <= 0: return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) infos = [] datas = conn_datas.hmget('user:'******'createTime', 'authorTime') infos.append('user:'******' -> createTime :' + str(datas[0])) infos.append('user:'******' -> authorTime :' + str(datas[1])) def get_game_time(conn, rkey): datas = conn.hmget(rkey, 'createTime', 'authorTime', 'lastlogin') infos.append(rkey + ' -> createTime :' + str(datas[0])) infos.append(rkey + ' -> authorTime :' + str(datas[1])) infos.append(rkey + ' -> lastlogin :'******'gamedata*:' + str(userId), get_game_time) return infos
def redis_del_weakdata(options, userId, resetCheckIn): if userId <= 0: return 'param userId ERROR !!' datas = _getLastOkDefines(options) rdbs = datas['dbdict']['redis'] rdb = _getRedisDefCluster(rdbs, userId) conn_datas = tydb.get_redis_conn(rdb) delkeys = [] def delete_redis_key(conn, rkey): conn.delete(rkey) delkeys.append(rkey) tylog.debug('REDIS DELETE-->[', rkey, ']') def delete_nslogin(conn, rkey): conn.hdel(rkey, 'newnslogin.lastlogin') conn.hdel(rkey, 'newnslogin.nslogin') tylog.debug('REDIS HDEL-->[', rkey, 'newnslogin.nslogin, newnslogin.lastlogin]') delkeys.append(rkey + ' newnslogin.nslogin, newnslogin.lastlogin') _execute_scan(conn_datas, 'weak:*:' + str(userId), delete_redis_key) _execute_scan(conn_datas, 'gamedata*:' + str(userId), delete_nslogin) if resetCheckIn: now = int(time.time()) sec_of_1day = 24 * 60 * 60 conn_datas.hset('user:'******'firstDailyCheckin', now - (2 * sec_of_1day)) conn_datas.hset('user:'******'lastDailyCheckin', now - sec_of_1day) del conn_datas return delkeys
def action(options, extkeys=[]): ''' 装载并检测服务启动配置文件 ''' sleepTime = 0.001 # reloadlist = [] changekeys = options.changekeys serverlist = options.serverlist changelen = options.changelen if extkeys : changekeys.extend(extkeys) if options.reset: changekeys = ['all'] # if options.reset: # reloadlist = ['all'] actlog.log('changekeys=', changekeys) actlog.log('changelen =', changelen) actlog.log('sleep time=', sleepTime) # hotcode = HOTCODE % (strutil.dumps(changekeys), # strutil.dumps(reloadlist), # sleepTime) config_redis = options.pokerdict['config_redis'] rconn = tydb.get_redis_conn(config_redis) _CHANGE_KEYS_NAME = 'configitems.changekey.list' rconn.rpush(_CHANGE_KEYS_NAME, 'CHANG_TIME %s' % (datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))) for ckey in changekeys : rconn.rpush(_CHANGE_KEYS_NAME, ckey) # setattr(options, 'hotfixpy', hotcode) # setattr(options, 'hotfixwait', 1) # x = 0 # ipgroups = {} # for srv in serverlist : # x += 1 # ip = srv['ip'] # if ip in ipgroups : # sids = ipgroups[ip] # else: # sids = [] # ipgroups[ip] = sids # sids.append(srv['type'] + srv['id']) # # # 每次每个机器更新10个进程 # while 1 : # sids = [] # for ip in ipgroups.keys() : # mids = ipgroups[ip] # head = mids[0:10] # ipgroups[ip] = mids[10:] # sids.extend(head) # if not sids : # break # sids = ','.join(sids) # setattr(options, 'serverIds', sids) # actlog.log('notify config changed->', sids) # ret = hotfix.action(options, 0) # if ret.find('"error"') >= 0 : # actlog.log('ERROR !!!') # actlog.log(ret) # actlog.log('ERROR !!!') # return 0 # time.sleep(2) actlog.log('Configure update wait :', 0, '/', len(serverlist)) while 1 : okcounts, allcounts = config_status.action(options, 1) if allcounts <= 0 : # 有异常发生 actlog.log('Configure update ERROR !!') return 0 elif okcounts == allcounts : # 完成同步 actlog.log('Configure update OK :', okcounts, '/', allcounts) return 1 else : # 没有同步完成 actlog.log('Configure update WAIT :', okcounts, '/', allcounts) time.sleep(2) return 1
def action(options, integrate=0): ''' 装载并检测服务启动配置文件 ''' serverlist = options.serverlist setattr(options, 'hotfixpy', HOTCODE) setattr(options, 'hotfixwait', 1) x = 0 serverIds = [] for srv in serverlist : x += 1 serverIds.append(srv['type'] + srv['id']) serverIds = ','.join(serverIds) setattr(options, 'serverIds', serverIds) if integrate == 0 : actlog.log('get configure status->', serverIds) ret = hotfix.action(options, 0) config_redis = options.pokerdict['config_redis'] rconn = tydb.get_redis_conn(config_redis) clen = rconn.llen(_CHANGE_KEYS_NAME) try: datas = strutil.loads(ret) except: actlog.log('ERROR !!', ret) if integrate == 0 : return 0 return 0, 0 confOks = [] confNgs = [] errors = [] errorids = [] for sid in datas : if isinstance(datas[sid], dict): cidx = datas[sid].get('CINDEX', None) cerrs = datas[sid].get('ERRORS', []) else: cidx = '' cerrs = [] actlog.log('ERROR !!!! ', sid, datas[sid]) if cerrs : errorids.append(sid) for cerr in cerrs : erritem = [cerr.get('exception', None), cerr.get('tarceback', None)] if not erritem in errors : errors.append(erritem) if isinstance(cidx, int) : if cidx >= clen : confOks.append(sid) else: confNgs.append(sid) else: actlog.error('ERROR !!', sid, 'GET STATUS ERROR !!', datas[sid]) if errors : actlog.log('ERROR IDS =', ','.join(errorids)) actlog.log('========== ERROR !!!! BEGINE ========') for x in errors : actlog.log('========== Exception ========') for l in x[0] : for m in l.split('\n') : if m : actlog.log(m) actlog.log('========== Traceback ========') for l in x[1] : for m in l.split('\n') : if m : actlog.log(m) actlog.log('========== ERROR !!!! END ========') raise Exception('Remote Exception') if integrate == 0 : return 0 else: return 0, 0 if integrate == 0 : actlog.log('THE CONFIGURE KEY INDEX =', clen) actlog.log('TOTAL_COUNT =', len(serverlist) , 'OK_COUNT =', len(confOks), 'DELAY_COUNT =', len(confNgs)) actlog.log('CONFIGURE_STATUS = %0.2d' % (int(float(len(confOks)) / len(datas) * 100)) + '%') if integrate == 0 : return 1 else: return len(confOks), len(serverlist)