nvim-dbee icon indicating copy to clipboard operation
nvim-dbee copied to clipboard

Use ParseURL in Redis adapter to properly parse complex URLs

Open sollymay opened this issue 9 months ago • 1 comments

Motivation

When you try to use redis with nvim-dbee and the Redis URL is not a “simple” redis://username:password@host you get an error err = dial tcp: address redis://username:password@host: too many colons in address. This has been documented in https://github.com/redis/go-redis/issues/864 if you look at the third and fourth comment.

This means you can’t really use the adapter with more “complex” type of connections which require additional parameters

Implementation

Instead of just passing the raw URL, use the https://godoc.org/github.com/go-redis/redis#ParseURL method to avoid this issue

sollymay avatar May 03 '24 15:05 sollymay

I think if you replace:

func (r *Redis) Connect(url string) (core.Driver, error) {
	c := redis.NewClient(&redis.Options{
		Addr:     url,
		Password: "",
		DB:       0,
	})

	return &redisDriver{
		redis: c,
	}, nil
}

with something like:

func (r *Redis) Connect(url string) (core.Driver, error) {
        opt, err := redis.ParseURL(url)
	if err != nil {
		panic(err)
	}
	c := redis.NewClient(&redis.Options{
		Addr:     opt.Addr,
		Password: opt.Password,
		DB:       opt.DB,
	})

	return &redisDriver{
		redis: c,
	}, nil
}

it would work. I tried to clone the repo and use the plugin locally to test and potentially doing a pull request, however, I can't seem to be able to set it up correclty using lazyvim and lazy.

sollymay avatar May 03 '24 23:05 sollymay