add a command which can return the dbnumber that the client selected#8000
Conversation
|
@631086083 thanks for the suggestion. A few initial comments:
|
|
Current documentation for
@oranagra: If this is really required (clients indeed must track this themselves, in worst case can be extracted from |
I agree with @tporadowski , BTW, |
|
CLIENT LIST is an admin introspection command, so it's OK that it shows things about the internals that are not normally the business of the application. I do agree that we want to add a CLIENT INFO command that will show the same info CLIENT list shows, on a single client. current client by default, and maybe others if a specific ID(s) is provided. But I don't think as want to add a specific CLIENT subcommand to get the selected db. |
|
hi @oranagra @soloestoy for the client info one, how about instead of providing a separate command, we extend the CLIENT LIST command for multiple arguments? which is like CLIENT LIST [myself / id ].. user can specify the id or myself for the specific client information which they want. just not sure whether that brings extra compleity. for CLIENT DBNUM, not sure we need this or not, since everytime before we do something we do a select db first in order to avoid any surprise. or am i missing something? |
|
@hwware at first I wanna that too, but maybe it's a little complex, since now |
|
@soloestoy I think the type option hit the argc == 4 case, but if we can provide CLIENT LIST [myself / id ] that should be a argc == 3 case right? If we return multiple ids that will definitely hit the complexity, but for a single argument to specify id/myself, IMHO the implementation should be trivial and shouldn't break the backward compatability.. how do you think? But maybe we need to refresh the documentation a bit if we do that. |
As @tporadowski said, this should be tracked by the client. I'm not sure what would this be used for other than in development and from redis-cli. @631086083 - can you share the motivation for adding this? Anyway, if needed, this could belong in the |
I'm very sorry, this is the second time I submit PR on GitHub. I'm not very proficient. Thank you very much for your advice. I will do better next time. |
At present, there is no command that can return the database selected by our client, which requires the user or the language used to record; therefore, we should be very careful in the interactive programming and program development, and we need to use selectdb command to confirm when doing some special operations. If you forget which databases are currently used, you need to go through it again and find some keys to determine the current databases,Moreover, the implementation of this command is relatively simple, and can return the required information in O (1) time complexity |
|
@631086083 doing SELECT command to confirm the desired db is selected is better, and faster than running a command to query that (SELECT can be used in a pipeline, no need to wait for a round trip and wait for the result). unless maybe some script changed the selected DB, or maybe it is needed before using a command such as MOVE that takes a DB number as argument. @itamarhaber I like your idea of SELECT taking a special argument to return the selected DB instead, but it's not ideal that it changes the response type. but since the response type is explicitly controlled by the user input, i guess we can do that. can you come up with an example of another command that does such a thing? @hwware i don't like to mess with the already complicated CLIENT LIST. i think the best approach is add CLIENT INFO, with or without an optional list of input IDs. |
|
@631086083 thanks for confirming my suspicions - this is a developer's tool and not a "real" command. Like
@oranagra Basically all(most?) commands with subcommands are like that, but the most quirky is That said, with RESP3, clients aren't expected to know the reply's type beforehand, so that's kind of ok. |
|
@itamarhaber i don't consider sub-commands to be an example for that (a command that returns different types based on arguments). i consider each sub-command to be a command of it's own. so to sum up my opinion:
|
So I agree with 1. WRT 2 it would be an ACL nightmare to restrict a client to call only its info and not others, so maybe two subcommands (e.g. variadic INFO and MYINFO). |
|
Thank you very much, I have learned a lot here, and I have a deeper understanding of the redis source code, especially the new mechanism of ACL. Next, I will read the redis source code in depth (^▽^ ) |
|
@631086083 do you want to suggest PRs for the two commands (together with tests and documentation)? or should someone else pick it up? |
|
@oranagra I see a tiny problem with modifying the SELECT command behaviour. For CLIENT INFO definitely makes a lot of sense. |
|
i think the ACL attempt to block |
I’m very sorry, I’m not very familiar with github, I closed the issue by mistake and missed this message.It looks like this order has been completed, thank you for your trust |
Add a command to redis, which can return the database currently used by the redis client, and call it through dbpos