go-redis
go-redis copied to clipboard
feat(plugin): add conn plugin api
This PR added the plugin functionality for network connection. Currently, it supports three plugin hook points: PreInitConnPlugin, InitConnPlugin, and PostInitConnPlugin.
Its functions are as follows:
- It is necessary to customize the connection authentication. There are some third-party proxies and Redis-compatible storage repositories that do not have complete support for certain Redis functionalities and commands. For example, many proxies do not support the HELLO command (which is used for authentication in version 9 by default).
- It can execute commands related to network connections, such as #2553 and #2492. These commands are specifically associated with network connections.
- There are some requirements in special environments where customization of initialization operations is desired, such as #2537.
Currently, only the basic functionalities have been implemented, and there is no support for client features like cluster/sentinel/ring. Testing and documentation have not been added either. After receiving feedback from everyone, further improvements will be made.
Additionally, this may be influenced by #2586.
/cc @vmihailenco @elena-kolevska @chayim
@SoulPancake Are you interested? You can share your opinions.
😊
This is a simple usage example:
func TestRedisPlugin(t *testing.T) {
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
})
ctx := context.Background()
client.RegistryPostInitConnPlugin(func(ctx context.Context, conn *redis.Conn) error {
conn.ClientSetName(ctx, "test-client")
return nil
})
client.RegistryInitConnPlugin(func(ctx context.Context, conn *redis.Conn) error {
username, auth := awsAuth(token)
return conn.AuthACL(ctx, username, auth).Err()
})
t.Log(client.Ping(ctx).Err())
}
In this example, the issue described in #2537 has been addressed.
The Redis authentication process has been customized by dynamically retrieving AWS authentication information.
Based off of this,
Where will we implement methods for the connection commands ? Are we planning to add a new directory for the conn commands for the commands themselves and the tests.
Such as CLIENT NO EVICT
PostInitConnPlugin -> this hook is executed after the connection initialization, and the Redis authentication has been completed So we can use that for this right.
@monkey92t
We treat them as special API, distinct from regular commands.
Hello @monkey92t , do you plan to work on this or we can close it? I am trying to clean up the PRs and the issues.
I assume this can be closed for now. @monkey92t let me know if you would like to continue the work, I would suggest a new branch based of the current state of master. Thank you!