@@ -32,9 +32,9 @@ class RedisAccessConfig(AccessConfig):
3232 default = None , description = "If not anonymous, use this uri, if specified."
3333 )
3434 password : Optional [str ] = Field (
35- default = None ,
35+ default = None ,
3636 description = "Password used to connect to database if uri is "
37- "not specified and connection is not anonymous."
37+ "not specified and connection is not anonymous." ,
3838 )
3939
4040
@@ -45,7 +45,7 @@ class RedisConnectionConfig(ConnectionConfig):
4545 host : Optional [str ] = Field (
4646 default = None ,
4747 description = "Hostname or IP address of a Redis instance to connect to "
48- "if uri is not specified." ,
48+ "if uri is not specified." ,
4949 )
5050 database : int = Field (default = 0 , description = "Database index to connect to." )
5151 port : Optional [int ] = Field (
@@ -126,6 +126,20 @@ class RedisUploaderConfig(UploaderConfig):
126126 key_prefix : str = Field (default = "" , description = "Prefix for Redis keys" )
127127
128128
129+ def _form_redis_pipeline_error_message (error : str ) -> str :
130+ """
131+ Form a user-friendly error message for Redis pipeline errors.
132+ The error message has `$` character at the beginning and `) of pipeline` at the end.
133+ Everything between these two strings is the value an should be removed.
134+ """
135+ start = error .find ("$" )
136+ end = error .find (") of pipeline" )
137+ if start != - 1 and end != - 1 :
138+ return error [: start + 1 ] + "<value>" + error [end :]
139+ else :
140+ return error
141+
142+
129143@dataclass
130144class RedisUploader (Uploader ):
131145 upload_config : RedisUploaderConfig
@@ -182,14 +196,14 @@ async def _check_redis_stack(self, element: dict) -> bool:
182196 # Redis with stack extension supports JSON type
183197 await pipe .json ().set (key_with_prefix , "$" , element ).execute ()
184198 except redis_exceptions .ResponseError as e :
185- message = str (e )
199+ message = _form_redis_pipeline_error_message ( str (e ) )
186200 if "unknown command `JSON.SET`" in message :
187201 # if this error occurs, Redis server doesn't support JSON type,
188202 # so save as string type instead
189203 await pipe .set (key_with_prefix , json .dumps (element )).execute ()
190204 redis_stack = False
191205 else :
192- raise e
206+ raise redis_exceptions . ResponseError ( message ) from e
193207 return redis_stack
194208
195209
0 commit comments