Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): add conn plugin api #2590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

monkey92t
Copy link
Collaborator

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:

  1. 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).
  2. It can execute commands related to network connections, such as Add support for CLIENT SETINFO #2553 and Add support for CLIENT NO-EVICT #2492. These commands are specifically associated with network connections.
  3. There are some requirements in special environments where customization of initialization operations is desired, such as Ignore error from CLIENT SETNAME? #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.

Signed-off-by: monkey92t <golang@88.com>
@monkey92t
Copy link
Collaborator Author

/cc @vmihailenco @elena-kolevska @chayim

@SoulPancake Are you interested? You can share your opinions.

😊

@monkey92t
Copy link
Collaborator Author

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.

@SoulPancake
Copy link
Contributor

SoulPancake commented May 15, 2023

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

@monkey92t
Copy link
Collaborator Author

We treat them as special API, distinct from regular commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants