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

added client change server event #182

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sachinvmurthy
Copy link

@sachinvmurthy sachinvmurthy commented Mar 4, 2025

This PR enhances the server_events module by adding support for handling client change events.
Specifically, it introduces the ClientChangeSubevent enum to represent client connection and disconnection events, adds a new event handler function client_change_event_callback to process these events, and updates the register_server_events function to include the registration of client change events. This allows the module to track and respond to client connection state changes, improving observability and control over client interactions.

@dmitrypol
Copy link
Collaborator

interesting PR, let's chat this week. Also please remove .DS_store file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this file

Copy link
Collaborator

@dmitrypol dmitrypol Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sachinvmurthy - please remove the .lock file in the macros but add back the one in the root

@@ -30,6 +32,21 @@ fn cron_event_handler(_ctx: &Context, _hz: u64) {
NUM_CRONS.fetch_add(1, Ordering::SeqCst);
}

#[client_changed_event_handler]
fn client_changed_event_handler(ctx: &Context, client_event: ClientChangeSubevent){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this to the example module. Could you add a test case for this as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :D! will add the test case.

@@ -30,6 +32,21 @@ fn cron_event_handler(_ctx: &Context, _hz: u64) {
NUM_CRONS.fetch_add(1, Ordering::SeqCst);
}

#[client_changed_event_handler]
fn client_changed_event_handler(ctx: &Context, client_event: ClientChangeSubevent){
if let ClientChangeSubevent::Connected = client_event {
Copy link
Member

@KarthikSubbarao KarthikSubbarao Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also check and handle the disconnects in this example - by decrementing the counter for example. We can then validate disconnection handling as well from the integration test

@KarthikSubbarao
Copy link
Member

KarthikSubbarao commented Mar 6, 2025

@sachinvmurthy Looks like you forgot to signoff on the commit. You can follow the instructions here: https://github.com/valkey-io/valkeymodule-rs/pull/182/checks?check_run_id=38259568280

Also, Could we please add some details to the PR description when you get time?

@@ -44,6 +44,12 @@ impl Context {
ValkeyString::from_redis_module_string(self.ctx, client_username)
}

pub fn get_client_username_by_id(&self, client_id: u64) -> ValkeyString {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrypol added this as an additional functionality to get username just by id.

Copy link
Collaborator

@dmitrypol dmitrypol Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reasonable feature

let res: i64 = redis::cmd("num_connects").query(&mut con)?;

assert_eq!(res, 0);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test for num_disconnects?

) {
let client_change_sub_event = if subevent == raw::REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED {
ClientChangeSubevent::Connected
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED as well?

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.

3 participants