{"record":{"id":"f48747b4badcc2fa","repo":"HumanSignal/label-studio","slug":"can-t-connect-to-redis-server","errorCode":null,"errorMessage":"Can't connect to Redis server.","messagePattern":"Can't connect to Redis server\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/io_storages/redis/serializers.py","lineNumber":29,"sourceCode":"    type = StorageTypeField(default=os.path.basename(os.path.dirname(__file__)))\n\n    class Meta:\n        model = RedisImportStorage\n        fields = '__all__'\n\n    def to_representation(self, instance):\n        result = super().to_representation(instance)\n        result.pop('password')\n        return result\n\n    def validate(self, data):\n        data = super(RedisImportStorageSerializer, self).validate(data)\n\n        storage = RedisImportStorage(**data)\n        try:\n            storage.validate_connection()\n        except:  # noqa: E722\n            raise ValidationError(\"Can't connect to Redis server.\")\n        return data\n\n\nclass RedisExportStorageSerializer(ExportStorageSerializer):\n    type = StorageTypeField(default=os.path.basename(os.path.dirname(__file__)))\n\n    def to_representation(self, instance):\n        result = super().to_representation(instance)\n        result.pop('password')\n        return result\n\n    class Meta:\n        model = RedisExportStorage\n        fields = '__all__'\n","sourceCodeStart":11,"sourceCodeEnd":44,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/redis/serializers.py#L11-L44","documentation":"RedisImportStorageSerializer.validate() instantiates the storage and calls storage.validate_connection(); any exception raised (connection refused, auth failure, timeout, or even the missing-db ValueError) is swallowed and re-raised as this generic DRF ValidationError. It tells you the Redis server was unreachable with the given settings but hides the underlying reason.","triggerScenarios":"POST/PUT to the storage API creating a Redis import storage whose host/port/password/db do not allow a working redis connection; validate_connection() raising inside the serializer's validate().","commonSituations":"Redis not running or wrong port; password required but not supplied (NOAUTH); TLS endpoint configured without ssl=True; firewall/Docker networking blocking the host; the `db` field missing so even get_redis_connection's ValueError lands here.","solutions":["Check the server logs / temporarily reproduce with redis-cli -h <host> -p <port> -a <password> -n <db> ping to see the real error.","Verify host, port, password, ssl and db fields in the storage payload are correct.","Confirm network reachability (Docker network, security groups, firewall) between Label Studio and Redis.","If auth is the cause, set the correct password/sentinel settings and retry."],"exampleFix":"// before (failing payload)\n{\"type\": \"redis\", \"host\": \"redis.internal\", \"path\": \"\"}\n\n// after\n{\"type\": \"redis\", \"host\": \"redis.internal\", \"port\": 6379, \"password\": \"secret\", \"db\": 1}","handlingStrategy":"try-catch","validationCode":"import redis\n\ndef redis_reachable(host: str, port: int, password: str | None, db: int) -> bool:\n    try:\n        r = redis.StrictRedis(host=host, port=port, password=password, db=db,\n                              socket_connect_timeout=3, decode_responses=True)\n        return r.ping()\n    except redis.RedisError:\n        return False","typeGuard":"def is_valid_redis_config(cfg: dict) -> bool:\n    return bool(cfg.get('host')) and isinstance(cfg.get('port', 6379), int) and bool(cfg.get('db'))","tryCatchPattern":"try:\n    serializer.is_valid(raise_exception=True)\nexcept ValidationError:\n    # inspect host/port/password/db, then probe with redis-cli or redis.ping()\n    logger.exception('Redis storage validation failed; check host/port/auth/db')","preventionTips":["Probe the Redis server with a ping before creating the storage.","Include password and ssl settings when the server requires them.","Verify Docker/K8s networking and security groups between Label Studio and Redis.","Set a short socket_connect_timeout in your probe to fail fast."],"tags":["redis","network","connection","serializer"],"backgroundTag":"connection-refused","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}