コード例 #1
0
ファイル: cronHold.py プロジェクト: fycheung/misc
         gc = seconds * (Speed.get(row['GiverId'], {}).get(2, 0) / 3600.)
         j = row['JcoinGive'] + jc
         g = row['GcoinGive'] + gc
         tmplst.append([row['GiverId'], j, g])
         incdic[row["GiverId"]] = {1:jc,2:gc}
     # + 更新本服进贡表
     j, g = ' CASE GiverId ', ' CASE GiverId'
     for lst in tmplst:
         j += ' WHEN %d THEN %d ' % (lst[0], lst[1])
         g += ' WHEN %d THEN %d ' % (lst[0], lst[2])
     j += ' END '; g += ' END '
     sql = 'UPDATE %s SET JcoinGive=%s, GcoinGive=%s, LastCollectTime=%d WHERE %s' % (table, j, g, int(curtime), where)
     pyDB.execute(sql)
 
 #总服redis
 redis_client = pyCache.getConn()
 holds = redis_client.hgetall('sgHold')
 print 'holds', holds
 for giver in holds:
     print 'giver is', giver
     try:
         sid, uid = map(int, giver.split('.'))
         if sid != config.SERVER_ID: #奴隶不是本服的
             continue
         v_fields = map(int, holds[giver].split('.'))
         print 'fields', fields
         if v_fields[0] == config.SERVER_ID:
             continue
         
         endtime, lastcollecttime, j, g = v_fields[4:]
         seconds = int(min(endtime, curtime) - lastcollecttime)
コード例 #2
0
#coding:utf8
#author:zhoujingjiang
#将用户表导入到redis

import pyDB
import pyCache
import config

redis = pyCache.getConn()

server_id = 2#config.SERVER_ID
server_group = config.SERVER_GROUP
limit_cnt = config.LIMIT_COUNT
fields = ['UserId','UserCamp','UserIcon',\
          'UserLevel', 'VipLevel']
cnt = 0

while 1:
    print '第%s次循环' % (cnt+1)
    start, n = cnt * limit_cnt, limit_cnt - 1
    rows = pyDB.out_rows('tb_user', fields, '1 LIMIT %s,%s' % (start, n))

    if len(rows) == 0:
        break

    for row in rows:
        UserId = row.pop('UserId')
        k = 'sgUser.%s.%s' % (UserId, server_id)
        v = row
        redis.set(k, v)
        
コード例 #3
0
ファイル: cronHold.py プロジェクト: hw233/python_misc
                g = row['GcoinGive'] + gc
                tmplst.append([row['GiverId'], j, g])
                incdic[row["GiverId"]] = {1: jc, 2: gc}
            # + 更新本服进贡表
            j, g = ' CASE GiverId ', ' CASE GiverId'
            for lst in tmplst:
                j += ' WHEN %d THEN %d ' % (lst[0], lst[1])
                g += ' WHEN %d THEN %d ' % (lst[0], lst[2])
            j += ' END '
            g += ' END '
            sql = 'UPDATE %s SET JcoinGive=%s, GcoinGive=%s, LastCollectTime=%d WHERE %s' % (
                table, j, g, int(curtime), where)
            pyDB.execute(sql)

        #总服redis
        redis_client = pyCache.getConn()
        holds = redis_client.hgetall('sgHold')
        print 'holds', holds
        for giver in holds:
            print 'giver is', giver
            try:
                sid, uid = map(int, giver.split('.'))
                if sid != config.SERVER_ID:  #奴隶不是本服的
                    continue
                v_fields = map(int, holds[giver].split('.'))
                print 'fields', fields
                if v_fields[0] == config.SERVER_ID:
                    continue

                endtime, lastcollecttime, j, g = v_fields[4:]
                seconds = int(min(endtime, curtime) - lastcollecttime)