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

Fixed PubSubMessage having to contain UTF-8 String as payload #10

Merged
merged 3 commits into from
Jan 7, 2024

Conversation

fdgogogo
Copy link
Contributor

@fdgogogo fdgogogo commented Dec 26, 2023

Like #9 , current implementation of PubSubMessage can only support UTF8 String.

This PR enables PubSubMessage to support binary data.

Additionally, the pattern and channel fields in PubSubMessage might also contain binary data. However, in most usage scenarios, this is unlikely to be the case, which is why I haven't modified them alongside the payload. Nonetheless, there's still a possibility that binary data might be used in these fields, and we might need to consider our implementation approach regarding this?

Also, I adjusted a line of code that seemed incorrect: pattern should not be the same as channel.

type = try .message(pattern: channel, payload: String(actual_payload))

@michaelvanstraten
Copy link
Owner

Hey thank you for this PR and sorry for my late response.

I will take a look at this tomorrow, over the holidays my time was limited to work on stuff so now I have to work on the backlog.

Comment on lines -163 to -168
case "message", "pmessage", "smessage":
let payload = try String(array.popLast())

if let actual_payload = array.popLast() {
channel = payload
type = try .message(pattern: channel, payload: String(actual_payload))

Choose a reason for hiding this comment

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

I was kind of trying to make this as covering as possible, so "message", "pmessage", "smessage" all in one case, but I could admit that this is somewhat hard to read/understand.

Sources/SwiftyRedis/PubSub.swift Outdated Show resolved Hide resolved
@michaelvanstraten michaelvanstraten merged commit 58e8134 into michaelvanstraten:main Jan 7, 2024
1 check passed
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.

2 participants