Exemplo n.º 1
0
def handler_redis():
    from backend.utils.cache import rd_client

    if rd_client.set("__healthz__", 1) is False:
        raise HealthzError("redis set command failed")
    if rd_client.get("__healthz__") != b'1':
        raise HealthzError("redis get command failed")
Exemplo n.º 2
0
    def iter_client(cls):
        for key in rd_client.scan_iter(f'{cls.CACHE_KEY_PREFIX}:*'):
            key = smart_text(key)
            data = rd_client.get(key)
            try:
                ctx = json.loads(data)
            except Exception as error:
                logger.info("get k8s context error, %s", error)
                continue

            k8s_client = cls.get_api_client(
                ctx['admin_server_address'], ctx['admin_cluster_identifier'], ctx['admin_user_token'], ctx)
            v1 = client.CoreV1Api(k8s_client)
            yield (v1, ctx['cluster_id'])
Exemplo n.º 3
0
    def get(self, session_id):
        key = self.CACHE_KEY.format(project_id=self.project_id, cluster_id=self.cluster_id, session_id=session_id)
        raw_ctx = rd_client.get(key)
        if not raw_ctx:
            logger.info("session_id 不正确或者已经过期, %s", session_id)
            return None

        try:
            ctx = json.loads(raw_ctx)
        except Exception as error:
            logger.info("bcs_context 格式不是json, %s, %s", raw_ctx, error)
            ctx = None

        return ctx
Exemplo n.º 4
0
 def exists(self):
     value = rd_client.get(self.key)
     if value:
         return True
     return False