예제 #1
0
 def __init__(
     self, key, max_len=100, serializer=json.dumps, deserializer=json.loads
 ):
     self.red = redis.StrictRedis(connection_pool=get_redis_pool())
     self.max_len = max_len
     self.serializer = serializer
     self.deserializer = deserializer
     self.key = key
예제 #2
0
def clear_cache(request):
    res = RedisCached.clear_all_caches(get_redis_pool())
    return JsonResponse({
        "result": res,
        "command": "clear_cache",
        "arguments": None,
        "failed": res is None
    })
예제 #3
0
def _red():
    # poor man's singleton
    red = get_redis_pool()
    global RED_POOL
    if not RED_POOL:
        RED_POOL = BlockingConnectionPool(max_connections=4)

    return Redis(connection_pool=red)
예제 #4
0
def get_votes_status():
    try:
        red = redis.StrictRedis(connection_pool=get_redis_pool())
        data = red.get("votes")
        if data:
            return json.loads(data)
    except:
        logger.exception("Unable to retrieve votes")
    return {'total_votes': 0, "winning_maps": []}
예제 #5
0
def run():
    rcon = Rcon(SERVER_INFO)
    red = Client(connection_pool=get_redis_pool())
    registered_series = [PlayerCount(red)]
    for series in registered_series:
        series.migrate()

    while True:
        for series in registered_series:
            series.run_on_time(rcon)
        time.sleep(LOOP_FREQUENCY_SEC)
예제 #6
0
 def __init__(self,
              client=None,
              min_resolution_ms=30000,
              retention_days=60,
              max_fails=5,
              slices=None):
     self.client = client or Client(connection_pool=get_redis_pool())
     self.slices = slices or {
         'minute': (f'{self.NAME}avgRuleMinute', 'avg', 1000 * 60),
         'hour': (f'{self.NAME}avgRuleHour', 'avg', 1000 * 60 * 60),
         'day': (f'{self.NAME}avgRuleDay', 'avg', 1000 * 60 * 60 * 24)
     }
     self.retention_msecs = 1000 * 60 * 60 * 24 * retention_days
     self.min_resolution_ms = min_resolution_ms / 1000
     self.last_run_time = 0
     self.fails = 0
     self.max_fails = max_fails
예제 #7
0
def get_current_selection():
    red = redis.StrictRedis(connection_pool=get_redis_pool())
    selection = red.get("votemap_selection")
    if selection:
        selection = json.loads(selection)
    return selection
예제 #8
0
 def __init__(self, rcon: RecordedRcon):
     self.rcon = rcon
     self.red = redis.Redis(connection_pool=get_redis_pool())
     self.maps_history = MapsHistory()
     self.prev_map = None
     self._restore_state()
예제 #9
0
def clear():
    RedisCached.clear_all_caches(get_redis_pool())
예제 #10
0
            if self.fails > self.max_fails:
                raise
            return
        self.last_run_time = now
        return now


class PlayerCount(Series):
    NAME = 'player_count'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def snapshot(self, rcon):
        slots = rcon.get_slots()
        nb, _ = slots.split('/')

        self.client.add(self.NAME, '*', float(nb))


if __name__ == '__main__':
    rcon = Rcon(SERVER_INFO)
    red = Client(connection_pool=get_redis_pool())
    registered_series = [PlayerCount(red)]
    for series in registered_series:
        series.migrate()

    while True:
        for series in registered_series:
            series.run_on_time(rcon)
        time.sleep(LOOP_FREQUENCY_SEC)
예제 #11
0
def _red():
    red = get_redis_pool()
    red = Redis(connection_pool=red)
    return red