-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Initialize help when using redis-cli help or redis-cli ? #10382
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
Conversation
The following usage will output an empty newline: ``` > redis-cli help set empty line ``` The reason is that in interactive mode, we have called `cliInitHelp`, which initializes help. When using `redis-cli help xxx` or `redis-cli help ? xxx`, we can't match the command due to empty `helpEntries`, so we output an empty newline. In this commit, we will call `cliInitHelp` to init the help. Note that in this case, we need to call `cliInitHelp` (COMMAND DOCS) every time, which i think is acceptable. So now the output will look like: ``` [redis]# src/redis-cli help get GET key summary: Get the value of a key since: 1.0.0 group: string [redis]# ``` Fixes redis#10378
oranagra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enjoy-binbin forgive me for the trivial questions, I'm AFK and not too familiar with this code.
I have two concerns:
- I don't like to call COMMAND DOCS when someone does a plain
redis-cli set X yor any other usage of the non interactive mode, excepthelp. I suppose this PR is ok in that respect. - Please checj what happens when this is used against an old redis version (without support for DOCS)
|
@oranagra sure, no problem. I also did not describe it very clearly, my bad
yes, i also dont like it. so i did check the code, we only call COMMAND DOCS when using
In #10043, if |
|
what about a case where redis isn't running at all? p.s. as far as i could tell this whole feature (help from non-interactive) is not something that was recently broken. |
|
interesting idea, i made a quick commit, with this commit, we can do this: Note that in this case, help won't be able to sense the connection status like (unless we do a |
before: ``` 127.0.0.1:6379> ping Error: Server closed the connection 127.0.0.1:6379> ``` after: ``` 127.0.0.1:6379> ping Error: Server closed the connection not connected> ```
oranagra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.. minor change request.
```
[root]# src/redis-cli --ldb --eval test.lua test 1
Lua debugging session started, please use:
quit -- End the session.
restart -- Restart the script in debug mode again.
help -- Show Lua script debugging commands.
* Stopped at 1, stop reason = step over
-> 1 local num = redis.call('GET', KEYS[1]);
redis-cli: redis-cli.c:718: cliCountCommands: Assertion
`commandTable->element[i]->type == 1' failed.
Aborted
```
Because in ldb mode, `COMMAND DOCS` or `COMMAND` will
return an array, only with one element, and the type
is REDIS_REPLY_STATUS, the result is `<error> Unknown
Redis Lua debugger command or wrong number of arguments`.
So if we in the ldb mode, and init the Redis HELP, we
will get the wrong response and crash the redis-cli
|
merged. thank you! |
Use exit code 1 if redis-cli fails to connect. Before #10382, on a connection failure, exit code would be 1. After this PR, whether connection is established or not, `noninteractive()` return value is used as the exit code. On a failure, this function returns `REDIS_ERR` which is `-1`. It becomes `255` as exit codes are between `0-255`. There is nothing wrong by returning 1 or 255 on failure as far as I know but it'll break things that expect to see 1 as exit code on a connection failure. This is also how we realized the issue. With this PR, changing behavior back to using 1 as exit code to preserve backward compatibility.
The following usage will output an empty newline:
The reason is that in interactive mode, we have called
cliInitHelp, which initializes help.When using
redis-cli help xxxorredis-cli help ? xxx,we can't match the command due to empty
helpEntries,so we output an empty newline.
In this commit, we will call
cliInitHelpto init the help.Note that in this case, we need to call
cliInitHelp(COMMAND DOCS)every time, which i think is acceptable.
So now the output will look like:
Fixes #10378
This PR also fix a redis-cli crash when using
--ldb --eval:Because in ldb mode,
COMMAND DOCSorCOMMANDwillreturn an array, only with one element, and the type
is
REDIS_REPLY_STATUS, the result is<error> Unknown Redis Lua debugger command or wrong number of arguments.So if we are in the ldb mode, and init the Redis HELP, we
will get the wrong response and crash the redis-cli.
In ldb mode we don't initialize HELP, help is only initialized
after the lua debugging session ends.
It was broken in #10043