Skip to content

AsyncRedisCluster.from_url() raises TypeError when cluster=true is passed via URL or kwargs due to unsupported argument in redis.asyncio.RedisClient #346

Open
@mprostko

Description

@mprostko

Description

When using redis-vl with redis-py, the AsyncRedisCluster.from_url() method raises a TypeError if the cluster=true setting is passed either via the URL query string or as a keyword argument.

**kwargs: Any argument was removed in redis.asyncio.RedisCluster.__init__() function in the following PR: redis/redis-py#2217

Example:

from redis import Redis, RedisCluster
from redis.asyncio import Redis as AsyncRedis
from redis.asyncio.cluster import RedisCluster as AsyncRedisCluster
from redisvl.redis.utils import is_cluster_url

# --- Passing cluster setting via url query
url = 'redis://<user>:<password>@<cluster_host>:6379/?cluster=true'
print(f"Is cluster url? {str(is_cluster_url(url))}") # True

r = Redis.from_url(url) 		# OK
rc = RedisCluster.from_url(url) 	# OK
ar = AsyncRedis.from_url(url) 		# OK
arc = AsyncRedisCluster.from_url(url) 	# TypeError: RedisCluster.__init__() got an unexpected keyword argument 'cluster'

# --- Passing cluster setting via kwargs
url = 'redis://<user>:<password>@<cluster_host>:6379'
kwargs = { "cluster": True }
print(f"Is cluster url? {str(is_cluster_url(url, **kwargs))}") # True

r = Redis.from_url(url, **kwargs) 		# OK
rc = RedisCluster.from_url(url, **kwargs) 	# OK
ar = AsyncRedis.from_url(url, **kwargs) 	# OK
arc = AsyncRedisCluster.from_url(url, **kwargs) # TypeError: RedisCluster.__init__() got an unexpected keyword argument 'cluster'

Suggested Fix:

Before calling AsyncRedisCluster.from_url(), the cluster parameter should be stripped from both the URL and kwargs, as those are currently not supported (https://github.com/redis/redis-py/blob/master/redis/asyncio/cluster.py#L263-L310).

This change should be implemented here:

if is_cluster_url(url, **kwargs):
client = AsyncRedisCluster.from_url(url, **kwargs)

It would also make sense to align the redis.asyncio.RedisClient.__init__() on the redis-py repository too with other client implementations that accept **kwargs and modify/clean them if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions