Beispiel #1
0
    def _reset(self):
        RedisDB.connect()
        MongoDB.connect()

        GiftCodeUsingLog.objects.all().delete()
        # GiftCodeRecord.objects.all().delete()
        # GiftCodeGen.objects.all().delete()
        # GiftCode.objects.all().delete()

        MailHistoryRecord.objects.all().delete()
        Statistics.objects.all().delete()
        Character.objects.all().delete()
        ForbidChat.objects.all().delete()
        AccountBan.objects.all().delete()
        AccountLoginLog.objects.all().delete()
        AccountThird.objects.all().delete()
        AccountRegular.objects.all().delete()
        Account.objects.all().delete()
        GeTuiClientID.objects.all().delete()

        RedisDB.get().flushall()

        for mc in MongoDB.DBS.values():
            mc.client.drop_database(mc.name)

        for s in Server.objects.all():
            ensure_index(s.id)
Beispiel #2
0
    def _reset(self):
        RedisDB.connect()
        MongoDB.connect()

        GiftCodeUsingLog.objects.all().delete()
        # GiftCodeRecord.objects.all().delete()
        # GiftCodeGen.objects.all().delete()
        # GiftCode.objects.all().delete()

        MailHistoryRecord.objects.all().delete()
        Statistics.objects.all().delete()
        Character.objects.all().delete()
        ForbidChat.objects.all().delete()
        AccountBan.objects.all().delete()
        AccountLoginLog.objects.all().delete()
        AccountThird.objects.all().delete()
        AccountRegular.objects.all().delete()
        Account.objects.all().delete()
        GeTuiClientID.objects.all().delete()

        RedisDB.get().flushall()

        for mc in MongoDB.DBS.values():
            mc.client.drop_database(mc.name)

        for s in Server.objects.all():
            ensure_index(s.id)
Beispiel #3
0
    def new(cls, account_id, value=None):
        key = LoginID.make_key(account_id)
        if not value:
            value = make_short_random_string()

        RedisDB.get(1).setex(key, value, cls.ID_EXPIRE)
        return value
Beispiel #4
0
    def lock(self, wait_timeout=5, hold_seconds=5):
        """

        :param wait_timeout: 等待获取锁的超时时间,超过这个时间没有获取到锁,将抛出LockTimeOut异常
        :param hold_seconds: 获取到锁以后,要保持的最长时间。
                             程序在可以在这个时间点前可以主动放弃锁。
                             如果超过hold_seconds后,还没有主动放弃,那么锁将自动释放
                             以此来应对程序获得锁以后出错没有主动释放形成死锁的问题
        """

        t = 0
        while True:
            if t > wait_timeout:
                raise LockTimeOut()

            result = RedisDB.get().set(self.key, 1, ex=hold_seconds, nx=True)
            if result:
                # got the lock
                break

            time.sleep(self.INTERVAL)
            t += self.INTERVAL

        try:
            yield self
        finally:
            RedisDB.get().delete(self.key)
Beispiel #5
0
    def new(cls, account_id, value=None):
        key = LoginID.make_key(account_id)
        if not value:
            value = make_short_random_string()

        RedisDB.get(1).setex(key, value, cls.ID_EXPIRE)
        return value
Beispiel #6
0
    def set_forbidden(self, expire_at):
        key = make_forbidden_key(self.char_id)

        expire = expire_at - arrow.utcnow().timestamp
        if expire <= 0:
            return

        RedisDB.get(2).setex(key, 1, expire)
Beispiel #7
0
    def get(self):
        with RedisDB.get().pipeline() as p:
            p.lrange(self.key, 0, -1)
            p.delete(self.key)
            result = p.execute()

        return result[0]
Beispiel #8
0
    def get(self):
        with RedisDB.get().pipeline() as p:
            p.lrange(self.key, 0, -1)
            p.delete(self.key)
            result = p.execute()

        return result[0]
Beispiel #9
0
    def set(self, cd_seconds):
        key = self.make_key()

        result = RedisDB.get().set(key, 1, ex=cd_seconds, nx=True)
        if not result:
            # 是设置失败,cd还没有消失
            return False

        return True
Beispiel #10
0
    def set(self, cd_seconds):
        key = self.make_key()

        result = RedisDB.get().set(key, 1, ex=cd_seconds, nx=True)
        if not result:
            # 是设置失败,cd还没有消失
            return False

        return True
Beispiel #11
0
    def put(self, msg=None, data=None):
        # data is Serialized msg
        if msg is not None:
            data = MessageFactory.pack(msg)

        assert data is not None

        with RedisDB.get().pipeline() as p:
            p.rpush(self.key, data)
            p.expire(self.key, EXPIRE)
            p.execute()
Beispiel #12
0
    def put(self, msg=None, data=None):
        # data is Serialized msg
        if msg is not None:
            data = MessageFactory.pack(msg)

        assert data is not None

        with RedisDB.get().pipeline() as p:
            p.rpush(self.key, data)
            p.expire(self.key, EXPIRE)
            p.execute()
Beispiel #13
0
 def release(self):
     RedisDB.get().delete(self.key)
Beispiel #14
0
def delete(key):
    RedisDB.get().delete(key)
Beispiel #15
0
def delete(key):
    RedisDB.get().delete(key)
Beispiel #16
0
def remove_lock_key(key):
    RedisDB.get().delete(key)
Beispiel #17
0
 def clean(self):
     RedisDB.get().delete(self.make_key())
Beispiel #18
0
def set(key, obj, expire=CACHE_SECONDS):
    data = cPickle.dumps(obj, HIGHEST_PROTOCOL)
    if expire:
        RedisDB.get().setex(key, data, expire)
    else:
        RedisDB.get().set(key, data)
Beispiel #19
0
def teardown():
    from core.db import MongoDB, RedisDB
    mongo = MongoDB.get(1)
    mongo.client.drop_database(mongo.name)

    RedisDB.get().flushdb()
Beispiel #20
0
 def clean(self):
     RedisDB.get().delete(self.key)
Beispiel #21
0
 def update_expire(cls, account_id):
     key = LoginID.make_key(account_id)
     RedisDB.get(1).expire(key, cls.ID_EXPIRE)
Beispiel #22
0
 def delete(cls, account_id):
     key = LoginID.make_key(account_id)
     RedisDB.get(1).delete(key)
Beispiel #23
0
 def get(cls, account_id,):
     key = LoginID.make_key(account_id)
     return RedisDB.get(1).get(key)
Beispiel #24
0
def set(key, obj, expire=CACHE_SECONDS):
    data = cPickle.dumps(obj, HIGHEST_PROTOCOL)
    if expire:
        RedisDB.get().setex(key, data, expire)
    else:
        RedisDB.get().set(key, data)
Beispiel #25
0
def flush():
    RedisDB.get().flushdb()
Beispiel #26
0
 def remove_forbidden(self):
     key = make_forbidden_key(self.char_id)
     RedisDB.get(2).delete(key)
Beispiel #27
0
 def get_cd_seconds(self):
     ttl = RedisDB.get().ttl(self.make_key())
     if not ttl:
         return 0
     return ttl
Beispiel #28
0
 def _empty_cache(self):
     RedisDB.connect()
     RedisDB.get().flushall()
Beispiel #29
0
 def _empty_cache(self):
     RedisDB.connect()
     RedisDB.get().flushall()
Beispiel #30
0
 def get_cd_seconds(self):
     ttl = RedisDB.get().ttl(self.make_key())
     if not ttl:
         return 0
     return ttl
Beispiel #31
0
 def clean(self):
     RedisDB.get().delete(self.key)
Beispiel #32
0
def relogin(request):
    RedisDB.get(1).flushdb()
    return HttpResponse("Success!")
Beispiel #33
0
 def check_forbidden(self):
     key = make_forbidden_key(self.char_id)
     if RedisDB.get(2).get(key):
         raise GameException(ConfigErrorMessage.get_error_id("CHAT_FORBIDDEN"))
Beispiel #34
0
def get(key):
    data = RedisDB.get().get(key)
    if data:
        return cPickle.loads(data)
    return None
Beispiel #35
0
 def get(
     cls,
     account_id,
 ):
     key = LoginID.make_key(account_id)
     return RedisDB.get(1).get(key)
Beispiel #36
0
def flush():
    RedisDB.get().flushdb()
Beispiel #37
0
 def update_expire(cls, account_id):
     key = LoginID.make_key(account_id)
     RedisDB.get(1).expire(key, cls.ID_EXPIRE)
Beispiel #38
0
 def clean(self):
     RedisDB.get().delete(self.make_key())
Beispiel #39
0
 def delete(cls, account_id):
     key = LoginID.make_key(account_id)
     RedisDB.get(1).delete(key)
Beispiel #40
0
    def __call__(self, request):
        RedisDB.connect()
        MongoDB.connect()

        return self.get_response(request)
Beispiel #41
0
def get(key):
    data = RedisDB.get().get(key)
    if data:
        return cPickle.loads(data)
    return None