Skip to content

[Client Introspection] Client Count Command #1467

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

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from

Conversation

sarthakaggarwal97
Copy link
Contributor

With this PR, we would include a new subcommand called CLIENT COUNT.

This subcommand will be responsible for counting the number of clients, while supporting the existing filters and the newly added filters in #1466.

Sample Output:

127.0.0.1:6379> client list
id=8 addr=127.0.0.1:49924 laddr=127.0.0.1:6379 fd=8 name= age=1413 idle=933 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=0 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=1920 events=r cmd=client|count user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=380 tot-net-out=217586 tot-cmds=9
id=9 addr=127.0.0.1:49927 laddr=127.0.0.1:6379 fd=9 name= age=1411 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=10 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=1946 events=r cmd=client|list user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=79 tot-net-out=216501 tot-cmds=2
id=10 addr=127.0.0.1:49928 laddr=127.0.0.1:6379 fd=10 name= age=1409 idle=1409 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=0 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=1920 events=r cmd=command|docs user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=27 tot-net-out=215501 tot-cmds=1
127.0.0.1:6379> client count
(integer) 3
127.0.0.1:6379> client count id 8 9
(integer) 2
127.0.0.1:6379> client count id 8 9 addr 127.0.0.1:49927
(integer) 1
127.0.0.1:6379> client count id 8 9 flags N
(integer) 2
127.0.0.1:6379> 

Built on top of: #1401, #1466
Resolves: #668

@sarthakaggarwal97 sarthakaggarwal97 added the needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. label Dec 20, 2024
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 71.04%. Comparing base (be60586) to head (e94bc68).
Report is 8 commits behind head on unstable.

Files with missing lines Patch % Lines
src/networking.c 85.18% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1467      +/-   ##
============================================
+ Coverage     70.99%   71.04%   +0.04%     
============================================
  Files           123      123              
  Lines         65912    65964      +52     
============================================
+ Hits          46795    46861      +66     
+ Misses        19117    19103      -14     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/server.h 100.00% <ø> (ø)
src/networking.c 87.64% <85.18%> (+0.16%) ⬆️

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sarthakaggarwal97 sarthakaggarwal97 force-pushed the client-count-command branch 4 times, most recently from 039c38a to c3260f5 Compare April 15, 2025 03:10
Signed-off-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: Sarthak Aggarwal <[email protected]>
Copy link
Collaborator

@hpatro hpatro left a comment

Choose a reason for hiding this comment

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

I would like to understand if anyone will benefit out of this much. With the recently introduced filters, it's pretty convenient to reduce the CLIENT LIST output already. And without seeing the response, would anyone just filter and would like to see count?

I know it's not a lot of code addition to the server but want us to think through if we want to support this. Users could optionally just perform a wc -l on the CLIENT LIST <filter> output.

@sarthakaggarwal97
Copy link
Contributor Author

I think if there is an opportunity to provide count of the box, we should explore it. It could be better than depending on clients and users to have additional logic on their end. Also, we can save on additional compute when we convert clients into their readable info strings and save up network bandwidth. wdyt?

@sarthakaggarwal97
Copy link
Contributor Author

@valkey-io/valkey-committers requesting your feedback here! thank you

@hwware
Copy link
Member

hwware commented Apr 24, 2025

From my point of view, I do not understand the requirement for this command. I think users could implement this function on their side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extended Valkey client introspection functionality
3 participants