当前位置: 首页>>代码示例>>Python>>正文


Python Gcore.redisKey方法代码示例

本文整理汇总了Python中sgLib.core.Gcore.redisKey方法的典型用法代码示例。如果您正苦于以下问题:Python Gcore.redisKey方法的具体用法?Python Gcore.redisKey怎么用?Python Gcore.redisKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sgLib.core.Gcore的用法示例。


在下文中一共展示了Gcore.redisKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
    def login(self,loginIp=None,loginMode=None):
        '''登入时调用的方法'''
        now = time.time()
        sql = "UPDATE tb_user SET LastLoginTime=UNIX_TIMESTAMP(),Online=1,LoginTimes=LoginTimes+1 WHERE UserId=%s"%self.uid
        self.db.execute(sql)
        
        #if not self.uid in Gcore.StorageUser: #缓存基础用户信息
        if 1: # fixed by zhoujingjiang
            self.cacheUserData(self.uid)

        UserType = Gcore.getUserData(self.uid,'UserType')   
        #添加登录日志
#         loginLogTB = 'tb_log_login201306'
        loginLogTB = self.tb_log_login()
        data = {'UserId':self.uid,'LoginTime':now,'UserType':UserType,
                'LoginModel':loginMode,'LoginIP':loginIp}
        self.logId = self.db.insert(loginLogTB,data)
        print self.uid,'login get logId:%s at %s'%(self.logId,now)
        
        key = Gcore.redisKey(self.uid)
        Gcore.redisM.hset('sgLogin',key,'1')
        UserLevel = self.getUserLevel()
        modActivity=Gcore.getMod('Activity',self.uid)
        modActivity.signin(0,'')
        if UserLevel>=Gcore.loadCfg(9301).get('FightLevel'):
            row = {}
            row['Online']=1 
            row['UserId']=self.uid
开发者ID:fycheung,项目名称:misc,代码行数:30,代码来源:LoginMod.py

示例2: addProtectHoldTime

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
 def addProtectHoldTime(self, second):
     '''添加藩国保护时间 by Qiudx'''
     second = int(second)
     now = Gcore.common.nowtime()
     protectHoldEndTime = self.getUserInfo('ProtectHoldEndTime')
     if protectHoldEndTime < now:
         protectHoldEndTime = now + second
     else:
         protectHoldEndTime += second
     sql = 'UPDATE tb_user SET ProtectHoldEndTime=%s WHERE UserId=%s'%(protectHoldEndTime, self.uid)
     self.db.execute(sql)
     Gcore.redisM.hset('sgProtectHold', Gcore.redisKey(self.uid), protectHoldEndTime)
     return protectHoldEndTime
开发者ID:fycheung,项目名称:misc,代码行数:15,代码来源:PlayerMod.py

示例3: addProtectTime

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
 def addProtectTime(self,second):
     '''添加保护时间By Yew  此方法是对的 by Lizr'''
     second = int(second)
     now=Gcore.common.nowtime()
     protectEndTime=self.getUserInfo('ProtectEndTime')
     if protectEndTime<now:
         protectEndTime=now+second
     else:
         protectEndTime=protectEndTime+second
     
     sql='UPDATE tb_user SET ProtectEndTime=%s WHERE UserId=%s'%(protectEndTime,self.uid)
     self.db.execute(sql)
     Gcore.redisM.hset('sgProtect', Gcore.redisKey(self.uid), protectEndTime) #更新总服redis 其他人不可以攻打
     #Gcore.sendmq(1, 10000, {'UserId':self.uid,'protectEndTime':protectEndTime}) #发送到总服更新 攻城查找表
     
     return protectEndTime   #返回保护结束时间 by qiudx 2013/06/27
开发者ID:fycheung,项目名称:misc,代码行数:18,代码来源:PlayerMod.py

示例4: getProtectHoldTime

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
 def getProtectHoldTime(self, PeerUID, PeerSID, tm):
     '''获取调停保护时间 add by qiudx 2013/07/11'''
     tm = tm if tm else int(time.time())
     if PeerSID == self.serverid:
         pMod = Gcore.getMod('Player', PeerUID)
         protectHoldEndTime = pMod.getUserInfo('ProtectHoldEndTime')
         protectTime = protectHoldEndTime - tm
         protectTime = protectTime if protectTime > 0 else 0
     else:
         peerKey = Gcore.redisKey(PeerUID)
         protectHoldEndTime = Gcore.redisM.hget('sgProtectHold', peerKey)
         if protectHoldEndTime and protectHoldEndTime > tm:
             protectTime = protectHoldEndTime - tm
         else:
             protectTime = 0
     return protectTime
开发者ID:fycheung,项目名称:misc,代码行数:18,代码来源:Building_holdMod.py

示例5: collect

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
 def collect(self, uid, sid, jr, gr, ts):
     '''纳贡'''
     jr=abs(jr)
     gr=abs(gr)
     if jr or gr:
         if sid == self.serverid: #本服
             sql = "UPDATE tb_hold SET JcoinGive=JcoinGive-'%s',GcoinGive=GcoinGive-'%s' WHERE HolderId='%s' AND GiverId='%s'" \
             %(jr,gr,self.uid, uid)
             self.db.execute(sql)
             
         else: #非本服,更新总服redis
             key = '%s.%s' % (sid, uid)
             key+=Gcore.redisKey(self.uid)
             
             jr = int(jr)*-1
             gr = int(gr)*-1
             Gcore.redisM.hincrby('sgHoldJcoin',key,jr)
             Gcore.redisM.hincrby('sgHoldJcoin',key,gr)
     return True
开发者ID:fycheung,项目名称:misc,代码行数:21,代码来源:Building_holdMod.py

示例6: isMyHold

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
 def isMyHold(self, uid, sid):
     '''判断是否是我的藩国
     @note 如果是我的藩国,返回(可纳贡的军资,可纳贡的铜币),否则返回False
     '''
     
     if sid == self.serverid:#本服
         table = 'tb_hold'
         fields = ['JcoinGive', 'GcoinGive']
         where = 'HolderId="%s" AND GiverId="%s"' % (self.uid, uid)
         res = self.db.out_fields(table, fields, where)
         return False if not res else (res["JcoinGive"], res["GcoinGive"])
     else: #跨服
         try:
             key = '%s.%s' %(sid, uid)
             key += Gcore.redisKey(self.uid)
             Jcoin = Gcore.redisM.hget('sgHoldJcoin', key)
             Gcoin = Gcore.redisM.hget('sgHoldGcoin', key)
             return (int(Jcoin), int(Gcoin))
         except Exception, e:
             print str(e)
             return False
开发者ID:fycheung,项目名称:misc,代码行数:23,代码来源:Building_holdMod.py

示例7: logout

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
    def logout(self):
        '''登出时调用的方法'''
        now = time.time()
        sql = "UPDATE tb_user SET LastLogoutTime=UNIX_TIMESTAMP(),Online=0 WHERE UserId=%s"%self.uid
        #print sql
        self.db.execute(sql)
        #更新登录日志

        loginLogTB = self.tb_log_login()
        if self.logId:
            loginLogId = self.logId
        else:
            loginLogId = self.db.out_field(loginLogTB,'LogId','UserId=%s ORDER BY LogId DESC LIMIT 0,1'%self.uid)
            
        sql = '''UPDATE %s  
                SET LogoutTime=%s,OnlineTime=%s-LoginTime  
                WHERE LogId=%s'''%(loginLogTB,now,now,loginLogId)
        print self.uid,'logout at %s'%now,sql
        self.db.execute(sql)
        
        Gcore.getMod('Redis', self.uid).offCacheAll() #更新Redis
        
        row = self.getUserInfo(['UserId','UserLevel','UserCamp','ProtectEndTime']) #只是用于查询 不是十分准确
        if row['UserLevel']>=Gcore.loadCfg(9301).get('FightLevel'):
            row['Online']=0 
            #Gcore.sendmq(1, 10000, row) #发送到总服更新
        
        key = Gcore.redisKey(self.uid)
        ProtectEndTime = Gcore.redisM.hget('sgProtect',key)
        if not ProtectEndTime:
            ProtectEndTime = 0
        if row['ProtectEndTime'] > int(ProtectEndTime): #更新保护时间
            Gcore.redisM.hset('sgProtect',key,row['ProtectEndTime'])
        
        modActivity=Gcore.getMod('Activity',self.uid)
        modActivity.refreashTime()#在线奖励活动更新时间 Yew
        
        Gcore.redisM.hdel('sgLogin',key)
开发者ID:fycheung,项目名称:misc,代码行数:40,代码来源:LoginMod.py

示例8: setHold

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
    def setHold(self, PeerUID, PeerSID):
        '''设置别人成为藩国'''
        #根据配置得出自动解除的天
        HoldConfig = Gcore.loadCfg(Gcore.defined.CFG_BUILDING_HOLD)
        RemoveRatio = HoldConfig['RemoveRatio']
        d = None
        for ind in range(1, len(RemoveRatio) + 1, 1):
            r = random.random()
            if  r <= RemoveRatio[str(ind)]:
                d = ind
                break

        #初始化元数据
        BeginTime = int(time.time()) #开始时间
        EndTime = BeginTime + int(d * 24 * 60 * 60) #预计结束时间(自动解除时间)
        # + StopTime是真正结束的时间:默认是EndTime
        # + LastCollectTime是最近一次奴隶的自动收集资源时间
        StopTime, LastCollectTime = EndTime, BeginTime    
        Jcoin, Gcoin = 0, 0 #奴隶的贡献
        
        print '是否是本服', PeerSID == self.serverid, PeerSID, self.serverid
        if PeerSID == self.serverid: #本服
            print '本服'
            pMod = Gcore.getMod('Player', PeerUID)
            protectHoldEndTime = pMod.getUserInfo('ProtectHoldEndTime')
            if BeginTime < protectHoldEndTime:
                return -1   #对方处于保护时间内,设置失败add by qiudx
            
            Data = Gcore.getMod('Building_resource',PeerUID).collectAll() #将地里的资源以自由身的身份收集一次
            Data['HoldEndTime'] = EndTime if not Gcore.TEST else int(time.time()+180)
            Data['HolderName'] = Gcore.getUserData(self.uid,'NickName')
            Data['GiveRatio'] = Gcore.loadCfg(1506).get('GiveRatio',0.05)
            Gcore.push(112, PeerUID, Data,Type=1)
            
            # + 更新用户表
            arr = {'HolderId':self.uid,'HolderServerId':self.serverid,'HoldEndTime':EndTime}
            self.db.update('tb_user', arr, 'UserId=%s' % PeerUID)
            # + 插入本服藩国记录
            arr = {"HolderId":self.uid, "GiverId":PeerUID, "LastCollectTime":LastCollectTime,
                   "JcoinGive":Jcoin, "GcoinGive":Gcoin, "StopTime":StopTime, 
                   "BeginTime": BeginTime, "EndTime":EndTime}
            #self.db.insert('tb_hold', arr)
            self.db.insert_update('tb_hold', arr, {"GiverId":PeerUID} )
            
            # + 插入纳贡记录
            arr = {"UserId":PeerUID, "HolderId":self.uid, "Gcoin":0,
                   "HolderServerId":self.serverid, "Jcoin":0, "LastGiveTime":BeginTime}
            self.db.insert_update('tb_hold_log', arr, {"UserId":PeerUID} )
            
            # + 插入藩国反抗记录
            date = datetime.date.strftime(datetime.date.fromtimestamp(BeginTime), "%Y-%m-%d")
            arr = {"UserId":PeerUID, "HolderId":self.uid, "HolderServerId":self.serverid,
                   "ProcessTotal":0, "RevengeCount":0, "LastRevengeDate":date}
            self.db.insert_update('tb_hold_revenge', arr, {"UserId":PeerUID} )
        else: #非本服,发消息
            peerKey = Gcore.redisKey(PeerUID)
            protectHoldEndTime = Gcore.redisM.hget('sgProtectHold', peerKey)
            if BeginTime < protectHoldEndTime:
                return -1   #潘国保护时间内,设置失败
            Gcore.sendmq(1, PeerSID, {'HolderId':self.uid,
                                      'HolderServerId':self.serverid,
                                      'GiverId':PeerUID,
                                      'EndTime':int(EndTime)})
        k = '%s.%s' % (PeerSID, PeerUID)
        v = '%s.%s.%s.%s.%s.%s' % (self.serverid, self.uid, BeginTime, StopTime, EndTime, LastCollectTime)
        Gcore.redisM.hset('sgHold', k, v) #货币相关已独立出来 by Lizr
        k += Gcore.redisKey(self.uid)
        Gcore.redisM.hset('sgHoldJcoin', k, 0) #1.1008.2.1001  前面是进贡的人 后面的纳贡的人
        Gcore.redisM.hset('sgHoldGcoin', k, 0)
        return True
开发者ID:fycheung,项目名称:misc,代码行数:72,代码来源:Building_holdMod.py

示例9: int

# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import redisKey [as 别名]
                if v_fields[0] == Gcore.getServerId():
                    continue
                
                endtime, lastcollecttime = v_fields[4:]
                seconds = int(min(endtime, curtime) - lastcollecttime)
                jc = int(seconds*(Speed.get(uid, {}).get(1, 0) / 3600.))
                gc = int(seconds*(Speed.get(uid, {}).get(2, 0) / 3600.))
                print 'jc', jc, 'gc',gc

                incdic[uid]={1:jc,2:gc}

                v = '.'.join(map(str, v_fields[0:5] + [int(curtime)]))
                redis_client.hset('sgHold', giver, v)
                
                #by Lizr
                key = Gcore.redisKey(uid)+'%s.%s'%(v_fields[0],v_fields[1])
                redis_client.hincrby('sgHoldJcoin',key,jc)
                redis_client.hincrby('sgHoldGcoin',key,gc)
                
            except Exception, e:
                print 'error', e
                raise

        #进贡记录
        table = 'tb_hold_log'
        where = 'UserId=' + ' OR UserId= '.join(map(str, uids))
        jstr = 'CASE UserId '
        gstr = ' CASE UserId'
        for UserId in uids:
            jstr += ' WHEN %d THEN %d' % (UserId, incdic.get(UserId, {}).get(1, 0))
            gstr += ' WHEN %d THEN %d' % (UserId, incdic.get(UserId, {}).get(2, 0))
开发者ID:fycheung,项目名称:misc,代码行数:33,代码来源:cronHold.py


注:本文中的sgLib.core.Gcore.redisKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。