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

How to use binary/bytes/stringbuffer type #246

Open
thomas9911 opened this issue Oct 24, 2022 · 6 comments · May be fixed by #247
Open

How to use binary/bytes/stringbuffer type #246

thomas9911 opened this issue Oct 24, 2022 · 6 comments · May be fixed by #247
Labels
enhancement New feature or request

Comments

@thomas9911
Copy link

I'm making a module that wants to read/write non-utf8 bytes to Redis. However the RedisKeyWritable read / write function only accept &str and also the higher level call function only accepts strings.

Is there a way to do this currently (without using the raw C bindings) ?

Currently i worked around this by creating my own type and using the set_value / get_value functions.

@gkorland gkorland added the enhancement New feature or request label Oct 25, 2022
@gkorland
Copy link
Contributor

@thomas9911 you're right it seems like a left over from the original API.
The original API didn't work with byte safe RedisString but with String/str.
We should update the API to support RedisString (PR is welcome)

@tBuLi12 tBuLi12 linked a pull request Oct 25, 2022 that will close this issue
@tBuLi12
Copy link

tBuLi12 commented Oct 25, 2022

Since I also bumped into this missing functionality the other day I sketched a quick draft that just adds byte-slice-accepting versions of the original methods.

Although that might work, perhaps a more generic interface should be implemented (tho even then something like
T: Into<Vec<u8>> cannot replace &str in the existing api, since &str accepts &&str and T: Into<Vec<u8>> does not)

@thomas9911
Copy link
Author

I was also working on it 😅

@tBuLi12
Copy link

tBuLi12 commented Oct 25, 2022

Oh damn, sorry - well, mine was just a sketch and I see your version accepts RedisStrings rather than byte slices (as it should) so nvm that 😅

Idk about breaking the public API, but keeping the default read & write with plain old strings as arguments does not seem like good long-term choice either...

@thomas9911
Copy link
Author

Maybe we could add a trait that can convert rust types into RedisString and let these functions accept this (so &str will keep working) 🤔

@tBuLi12
Copy link

tBuLi12 commented Oct 26, 2022

Well we could make the api accept T: Into<RedisString> (at least in places where the underlying string is cloned anyway), and also add an impl Into<RedisString> for &str, but I'm not sure if that keeps it completely backwards compatible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants