perl-redis icon indicating copy to clipboard operation
perl-redis copied to clipboard

Redis URL scheme is not supported, redis://<user>:<password>@<host>:<port>

Open joshnatis opened this issue 3 years ago • 3 comments

Hello, I'm having trouble getting the client to connect to Redis. Here is a rough reproducer:

use Redis;
my $r = Redis->new(server => $ENV{REDIS_URL});

My Redis URL is in this format: redis://<user>:<password>@<host>:<port>. That's the same as the schema described here: http://www.iana.org/assignments/uri-schemes/prov/redis.

When I try to connect, I get the error "Could not connect to Redis server at <my url>: Invalid argument".

I was able to connect with this URL schema using py-redis:

r = redis.from_url(os.environ.get('REDIS_URL'))

Help please! :D

joshnatis avatar Nov 04 '22 00:11 joshnatis

If anybody else runs into this issue in the future, the workaround I went with was breaking the Redis URL up into parts using URI::redis, and then supplying each argument seperately to the constructor.

Like so:

use Redis;
use URI::redis;

my $uri = URI->new($ENV{REDIS_URL});
my $redis = Redis->new(
        server => $uri->host  . ':' . $uri->port,
        password => $uri->password,
);

I also brought up the idea of integrating the redis URL scheme into the base URI module: https://github.com/libwww-perl/URI/issues/119.

It would still be cool for perl-redis to natively understand this Redis URL scheme though.

joshnatis avatar Nov 13 '22 03:11 joshnatis

I like this idea and I'd like to try contributing to public Perl code for the first time, so I'm going to try to implement this. @joshnatis would you mind if I pinged you if I run into issues or to try it out when I think it's ready?

davmillar avatar Oct 17 '24 14:10 davmillar

@davmillar that's awesome! Sure thing, happy to help -- I'll await your comment

joshnatis avatar Oct 18 '24 02:10 joshnatis