Skip to content

Make command replies consistent with requests - #24

Open
macvenez wants to merge 3 commits into
antirez:mainfrom
macvenez:consistent-message-reply
Open

Make command replies consistent with requests#24
macvenez wants to merge 3 commits into
antirez:mainfrom
macvenez:consistent-message-reply

Conversation

@macvenez

Copy link
Copy Markdown
Contributor

resolves #22

I added $ character to each command reply.
It might be unnecessary in some conditions like replies to commands with wrong number of arguments.
In general I think it's good anyway to easily distiguish between messages

@antirez

antirez commented Oct 16, 2024

Copy link
Copy Markdown
Owner

Hello @macvenez, checking your PR I think we could go the Redis protocol route. What about:

Starting the reply with "+" in case of successful reply. "-" in case of errors?
Also, please note that there is a small problem in the PR in the case of the .join() call when generating the command list.

@macvenez

Copy link
Copy Markdown
Contributor Author

Yes! That's an even better idea, I'll edit it accordingly.

Can you illustrate what's going to happen with .join?

That's an example code:

LoRaPresets = ['preset1', 'preset2', 'preset3']
result = "-Valid presets: " + ", ".join(x for x in LoRaPresets)
print(result)

Shouldn't the output be:
-Valid presets: preset1, preset2, preset3 ? I think that's a correct output, right? Am I missing something (maybe in micropython something different occurs)?
Thanks!

@antirez

antirez commented Oct 16, 2024

Copy link
Copy Markdown
Owner

Great. Thanks. The problem with join is only here AFAIK:

    send_reply("$, ".join(self.fw.keychain.list_keys()))
>>> "$, ".join(["a","b","c"])
'a$, b$, c'

@macvenez

Copy link
Copy Markdown
Contributor Author

Alright, now I see it, that should be easily fixable with:
send_reply("$"+", ".join(self.fw.keychain.list_keys()))

of course that $ should be a +

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.

Make command replies consistent with requests

2 participants