示例#1
0
文件: redis.py 项目: pipex/gitbot
    def deleteall(cls):
        if not hasattr(cls, '__prefix__'):
            raise AttributeError("Models must define the attribute: __prefix__ or define one of the model keys as primary")

        keys = redis.keys(cls.__prefix__ + '*')
        if len(keys) > 0:
            for key in cls.__indexes__:
                cls.__indexes__[key].deleteall()

            return redis.delete(*keys)

        return 0
示例#2
0
def set_user():
    animals = open('app/animals').read().splitlines()
    modifiers = open('app/modifiers').read().splitlines()
    user = "******" % (random.choice(modifiers),random.choice(animals))
    while r.keys("activeuser:%s" % (user)): # let's be sure there are no active sessions
	user = "******" % (random.choice(modifiers),random.choice(animals))
    activeuser = "******" % user     
    r.hset(activeuser, "name", user)
    r.hset(activeuser, "firstview", "1")    # not currently used, for changing welcome message text, etc.
    session['username'] = user
    r.expire(activeuser, 600)               # set user to timeout after 10 mins 
    return
示例#3
0
文件: redis.py 项目: pipex/gitbot
    def all(cls, *args, **kwargs):
        """Return an iterator over the objects matching the model in the database

        It performs the query by calling redis.keys() using the defined prefix.
        If extra arguments are given, they are passed to the contructor of the model.
        """
        if not hasattr(cls, '__prefix__'):
            raise AttributeError("Models must define the attribute: __prefix__ or define one of the model keys as primary")

        keys = redis.keys(cls.__prefix__ + '*')
        for key in keys:
            yield cls(key.decode(), *args, **kwargs)
示例#4
0
def scrub_scrubs():
    """Randomly culls single-user lists."""
    scrub_limit = app.config.get("BT_SCRUB_LIMIT")

    users_keys = r.keys("listings.*.users")

    # Preserve at least 5000, scrubbing half the remainder
    scrub_count = max(len(users_keys) - scrub_limit, 0) / 2

    for key in random.sample(users_keys, scrub_count):
        if r.scard(key) < 2:
            _, listing_id, _ = key.split(".")
            purge_data(listing_id)
示例#5
0
def set_user():
    animals = open('app/animals').read().splitlines()
    modifiers = open('app/modifiers').read().splitlines()
    user = "******" % (random.choice(modifiers), random.choice(animals))
    while r.keys("activeuser:%s" %
                 (user)):  # let's be sure there are no active sessions
        user = "******" % (random.choice(modifiers), random.choice(animals))
    activeuser = "******" % user
    r.hset(activeuser, "name", user)
    r.hset(activeuser, "firstview",
           "1")  # not currently used, for changing welcome message text, etc.
    session['username'] = user
    r.expire(activeuser, 600)  # set user to timeout after 10 mins
    return
示例#6
0
文件: redis.py 项目: pipex/gitbot
    def deleteall(cls):
        if not hasattr(cls, '__prefix__'):
            raise AttributeError(
                "Models must define the attribute: __prefix__ or define one of the model keys as primary"
            )

        keys = redis.keys(cls.__prefix__ + '*')
        if len(keys) > 0:
            for key in cls.__indexes__:
                cls.__indexes__[key].deleteall()

            return redis.delete(*keys)

        return 0
示例#7
0
文件: redis.py 项目: pipex/gitbot
    def all(cls, *args, **kwargs):
        """Return an iterator over the objects matching the model in the database

        It performs the query by calling redis.keys() using the defined prefix.
        If extra arguments are given, they are passed to the contructor of the model.
        """
        if not hasattr(cls, '__prefix__'):
            raise AttributeError(
                "Models must define the attribute: __prefix__ or define one of the model keys as primary"
            )

        keys = redis.keys(cls.__prefix__ + '*')
        for key in keys:
            yield cls(key.decode(), *args, **kwargs)
示例#8
0
    def test_scrub_scrubs(self):
        """Should randomly cull user lists of one user."""
        for i in range(50):
            r.sadd('listings.%s.users' % i, '1', '2')

        for i in range(50, 6000):
            r.sadd('listings.%s.users' % i, '1')

        scrub_scrubs()

        # All of the 2 or more lists should be there
        for i in range(50):
            assert r.scard('listings.%s.users' % i) == 2

        # Should leave at least 5000, taking about half of the remainder
        remaining_keys = r.keys('listings.*.users')
        assert len(remaining_keys) <= 5550
        assert len(remaining_keys) >= 5000
示例#9
0
文件: redis.py 项目: pipex/gitbot
    def deleteall(self):
        keys = redis.keys(self.__prefix__ + '*')
        if len(keys) > 0:
            return redis.delete(*keys)

        return 0
示例#10
0
文件: redis.py 项目: pipex/gitbot
 def __len__(self):
     return len(redis.keys(self.__prefix__ + '*'))
示例#11
0
文件: redis.py 项目: pipex/gitbot
 def __iter__(self):
     return iter(map(lambda s: s.decode('utf-8')[len(self.__prefix__):], redis.keys(self.__prefix__ + '*')))
示例#12
0
文件: redis.py 项目: pipex/gitbot
    def deleteall(self):
        keys = redis.keys(self.__prefix__ + '*')
        if len(keys) > 0:
            return redis.delete(*keys)

        return 0
示例#13
0
文件: redis.py 项目: pipex/gitbot
 def __len__(self):
     return len(redis.keys(self.__prefix__ + '*'))
示例#14
0
文件: redis.py 项目: pipex/gitbot
 def __iter__(self):
     return iter(
         map(lambda s: s.decode('utf-8')[len(self.__prefix__):],
             redis.keys(self.__prefix__ + '*')))