redismodule-rs
redismodule-rs copied to clipboard
How to use binary/bytes/stringbuffer type
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.
@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)
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)
I was also working on it 😅
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...
Maybe we could add a trait that can convert rust types into RedisString and let these functions accept this (so &str will keep working) :thinking:
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