redis / rueidis

A fast Golang Redis client that supports Client Side Caching, Auto Pipelining, Generics OM, RedisJSON, RedisBloom, RediSearch, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rueidislock should use CoreClient instead of Client

Gobd opened this issue · comments

This make the below possible which I think works and would be nice. The Locker can share a client already created:

locker, _ := rueidislock.NewLocker(rueidislock.LockerOption{
	ClientBuilder: func(rueidis.ClientOption) (rueidis.CoreClient, error) {
		dc, _ := c.Redis.Dedicate()
		return dc, err
	},
})

Hi @Gobd,

Unfortunately, rueidislock requires some special configurations in rueidis.ClientOption to work correctly. When using the ClientBuilder, you must respect the rueidis.ClientOption passed in to build a rueidis.Client.

Generally, I don't recommend sharing rueidislock's client with other usages, but here is what you can do:

locker, _ := rueidislock.NewLocker(rueidislock.LockerOption{...})
client := locker.Client()

client.Do(ctx, client.B().Get().Key(..).Build()) // share the client created by rueidislock

Thanks for the response! I'll keep my code the way I have it. The lock is working great :)