Exemple #1
0
    def __init__(self, server, params, backend):
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get("REVERSE_KEY_FUNCTION")
            or "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get("OPTIONS", {})
        self._slave_read_only = self._options.get('SLAVE_READ_ONLY', True)

        serializer_path = self._options.get(
            "SERIALIZER", "django_redis.serializers.pickle.PickleSerializer")
        serializer_cls = load_class(serializer_path)

        compressor_path = self._options.get(
            "COMPRESSOR",
            "django_redis.compressors.identity.IdentityCompressor")
        compressor_cls = load_class(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options)

        self.connection_factory = pool.get_connection_factory(
            options=self._options)
Exemple #2
0
    def __init__(self, server, params, backend):
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(params.get("REVERSE_KEY_FUNCTION") or
                                        "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get("OPTIONS", {})

        serializer_path = self._options.get("SERIALIZER", "django_redis.serializers.pickle.PickleSerializer")
        serializer_cls = load_class(serializer_path)

        compressor_path = self._options.get("COMPRESSOR", "django_redis.compressors.identity.IdentityCompressor")
        compressor_cls = load_class(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options);

        self.connection_factory = pool.get_connection_factory(options=self._options)
    def __init__(self, server, params: Dict[str, Any],
                 backend: BaseCache) -> None:
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get("REVERSE_KEY_FUNCTION")
            or "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(
            self._server)  # type: List[Optional[Redis]]
        self._options = params.get("OPTIONS", {})
        self._replica_read_only = self._options.get("REPLICA_READ_ONLY", True)

        serializer_path = self._options.get(
            "SERIALIZER", "django_redis.serializers.pickle.PickleSerializer")
        serializer_cls = import_string(serializer_path)

        compressor_path = self._options.get(
            "COMPRESSOR",
            "django_redis.compressors.identity.IdentityCompressor")
        compressor_cls = import_string(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options)

        self.connection_factory = pool.get_connection_factory(
            options=self._options)
 def __init__(self, server, params, backend):
     self._server = server # redis服务
     self._params = params
     self._backend = backend
     
     self.reverse_key = get_key_func(params.get('REVERS_KEY_FUNCTION') or
                                     'django_redis_cluster.utils.default_reverse_key')
     
     if not self._server:
         raise ImproperlyConfigured('Missing connections string')
     
     # 初始空clients
     if not isinstance(self._server, (list, tuple, set)):
         self._server = self._server.split(',')
     
     # 定义配置的压缩解压库
     self._options = params.get('OPTIONS', {})
     self._options.setdefault('COMPRESS_COMPRESSOR', zlib.compress)
     self._options.setdefault('COMPRESS_DECOMPRESSOR', zlib.decompress)
     self._options.setdefault('COMPRESS_DECOMPRESSOR_ERROR', zlib.error)
     
     # 序列化配置
     self._serializer = PickleSerializer(options=self._options)
     self._connect_factory = connection.get_connection_factory(server=self._server, options=self._options)
     self._client = self._connect_factory.connection
Exemple #5
0
    def __init__(self, server, params, backend):
        self._pickle_version = -1
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get("REVERSE_KEY_FUNCTION")
            or "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get("OPTIONS", {})
        self._options.setdefault("COMPRESS_COMPRESSOR", zlib.compress)
        self._options.setdefault("COMPRESS_DECOMPRESSOR", zlib.decompress)
        self._options.setdefault("COMPRESS_DECOMPRESSOR_ERROR", zlib.error)

        self.setup_pickle_version()
        self.connection_factory = pool.get_connection_factory(
            options=self._options)
    def __init__(self, server, params, backend):
        super(SentinelClient, self).__init__(server, params, backend)

        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(params.get("REVERSE_KEY_FUNCTION") or
                                        "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._options = params.get("OPTIONS", {})

        serializer_path = self._options.get("SERIALIZER", "django_redis.serializers.pickle.PickleSerializer")
        serializer_cls = import_string(serializer_path)

        compressor_path = self._options.get("COMPRESSOR", "django_redis.compressors.identity.IdentityCompressor")
        compressor_cls = import_string(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options)

        # Hack: Add sentinels servers as options, to break legacy pool code as less as possible
        self._options.update({"SENTINELS": self._server})
        # Create connection factory for Sentinels
        self.connection_factory = pool.get_connection_factory(options=self._options)
Exemple #7
0
    def __init__(self, server, params, backend):
        self._server = server  # redis服务
        self._params = params
        self._backend = backend

        self.reverse_key = get_key_func(
            params.get('REVERS_KEY_FUNCTION')
            or 'django_redis_cluster.utils.default_reverse_key')

        if not self._server:
            raise ImproperlyConfigured('Missing connections string')

        # 初始空clients
        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(',')

        # 定义配置的压缩解压库
        self._options = params.get('OPTIONS', {})
        self._options.setdefault('COMPRESS_COMPRESSOR', zlib.compress)
        self._options.setdefault('COMPRESS_DECOMPRESSOR', zlib.decompress)
        self._options.setdefault('COMPRESS_DECOMPRESSOR_ERROR', zlib.error)

        # 序列化配置
        self._serializer = PickleSerializer(options=self._options)
        self._connect_factory = connection.get_connection_factory(
            server=self._server, options=self._options)
        self._client = self._connect_factory.connection
    def __init__(self, server, params, backend):
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get("REVERSE_KEY_FUNCTION")
            or "django_redis.util.default_reverse_key")

        self._options = params.get("OPTIONS", {})

        if self._options.get('USE_CONSUL', False) and consulate is not None:
            sentinel_port = self._options.get('SENTINEL_PORT', '26379')
            consul = consulate.Consul(
                host=self._options.get('CONSUL_IP_ADDR', 'localhost'))
            self._server = [(node['Address'], sentinel_port)
                            for node in consul.catalog.nodes()
                            if node['Meta'].get('consul_role') == 'server']
        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        # In Redis Sentinel (not Redis Cluster) all slaves in read-only mode
        self._slave_read_only = True

        serializer_path = self._options.get(
            "SERIALIZER", "django_redis.serializers.pickle.PickleSerializer")
        serializer_cls = load_class(serializer_path)

        compressor_path = self._options.get(
            "COMPRESSOR",
            "django_redis.compressors.identity.IdentityCompressor")
        compressor_cls = load_class(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options)

        # Hack: Add sentinels servers as options, to break legacy pool code as less as possible
        self._options.update({"SENTINELS": self._server})
        # Create connection factory for Sentinels
        self.connection_factory = pool.get_connection_factory(
            options=self._options)
    def __init__(self, server, params, backend):
        self._pickle_version = -1
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(params.get('REVERSE_KEY_FUNCTION') or 'redis_cache.util.default_reverse_key')

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get('OPTIONS', {})

        self.setup_pickle_version()
        self.connection_factory = pool.get_connection_factory(options=self._options)
Exemple #10
0
    def __init__(self, server, params, backend):
        self._pickle_version = -1
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get('REVERSE_KEY_FUNCTION')
            or 'redis_cache.util.default_reverse_key')

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get('OPTIONS', {})

        self.setup_pickle_version()
        self.connection_factory = pool.get_connection_factory(
            options=self._options)
    def __init__(self, server, params, backend):
        super(SentinelClient, self).__init__(server, params, backend)

        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(
            params.get('REVERSE_KEY_FUNCTION')
            or 'django_redis.util.default_reverse_key', )

        if not self._server:
            raise ImproperlyConfigured('Missing connections string')

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(',')

        self._options = params.get('OPTIONS', {})

        serializer_path = self._options.get(
            'SERIALIZER',
            'django_redis.serializers.pickle.PickleSerializer',
        )
        serializer_cls = load_class(serializer_path)

        compressor_path = self._options.get(
            'COMPRESSOR',
            'django_redis.compressors.identity.IdentityCompressor',
        )
        compressor_cls = load_class(compressor_path)

        self._serializer = serializer_cls(options=self._options)
        self._compressor = compressor_cls(options=self._options)

        # Hack: Add sentinels servers as options, to break legacy pool code as less as possible
        self._options.update({'SENTINELS': self._server})
        # Create connection factory for Sentinels
        self.connection_factory = pool.get_connection_factory(
            options=self._options)
Exemple #12
0
    def __init__(self, server, params, backend):
        self._pickle_version = -1
        self._backend = backend
        self._server = server
        self._params = params

        self.reverse_key = get_key_func(params.get("REVERSE_KEY_FUNCTION") or
                                        "django_redis.util.default_reverse_key")

        if not self._server:
            raise ImproperlyConfigured("Missing connections string")

        if not isinstance(self._server, (list, tuple, set)):
            self._server = self._server.split(",")

        self._clients = [None] * len(self._server)
        self._options = params.get("OPTIONS", {})
        self._options.setdefault("COMPRESS_COMPRESSOR", zlib.compress)
        self._options.setdefault("COMPRESS_DECOMPRESSOR", zlib.decompress)
        self._options.setdefault("COMPRESS_DECOMPRESSOR_ERROR", zlib.error)

        self.setup_pickle_version()
        self.connection_factory = pool.get_connection_factory(options=self._options)