scala-redis-nb
scala-redis-nb copied to clipboard
Unrestrict Redis Key and String types
Changes in c7bedc5 restrict Redis string ops to Scala strings. Redis strings and keys are "binary safe, [... and] can contain any kind of data".
Passing in serializable objects as keys was super useful.
See http://redis.io/topics/data-types-intro and http://redis.io/topics/data-types
I can head this up, assuming it's a wanted change.
It makes sense.
Fortunately #41 accepts raw bytes input/output without modification, so it can be easily fixed by just replacing key type from String to Stringified basically.
To support for arbitrary objects out-of-box, additional changes in formats are needed though.
The Stringified front end looks nice. However, looking through the serialization package is seems everything that gets sent over the wire is still round tripped through toString and wrapped in a new ByteString using the UTF-8 string constructor. Binary data (at least Array[Byte]) can be directly wrapped in a ByteString.
We already have that kind of reader and writer here and here.
Required changes are to make it more explicit (such as BinaryReader/Writer and BinaryFormat) and optionally to provide a delegation logic to (un)marshal complex data types based on existing readers/writers.
+1 .. we already have the machinery in place.
Looks like you guys do. This would be a welcomed addition.
I've taken an initial stab at part of it, but I don't know the code base very well yet.
Any update on this, @andyscott? It you don't have enough time I can handle this.
I haven't gotten around to it. Eventually I will, but it you have time and want to do it go ahead!
/ sent via phone / Andy G. Scott /
On Sep 9, 2013, at 22:33, guersam [email protected] wrote:
Any update on this, @andyscott? It you don't have enough time I can handle this.
— Reply to this email directly or view it on GitHub.
I'm trying to use scala-redis-nb to serialize arbitrary Serializable objects, and currently I have to convert them to Base64 strings because a) scala-redis-nb routes everything to strings and b) The interfaces that can bypass that and read and write bytes are private. I would really appreciate, even if nobody has the time to change everything that is needed, at least consider providing a way to use Format with arbitrary byte content.
Thanks, Daniel
Hi Daniel -
Which version of scala-redis-nb are u using right now ?
Thanks.
I'm using version 0.3.
0.3 supports raw bytes in send/receive. Here's an example .. https://github.com/debasishg/scala-redis-nb/blob/master/src/test/scala/com/redis/serialization/SerializationSpec.scala#L71 .. Could u give a sample test case of the requirement ?
How can I use that to write a Format object that can take a Serializable and process it then, since it only has read and write methods returning strings? Sorry if I misspoke on it not being possible, I just looked around for a way and had not found any. Does the manual conversion handle null bytes properly?
Edit: sorry for being a little silly, I think I have it figured out by now, I just have to override the to/fromByteString methods. But it would be better to refactor things a bit somehow because there is no enforced guarantee that read/write can be safely bypassed in all cases.
What about using Akka's Serialization library? It's an already tested codebase, is very configurable, and already has all the dynamic dispatch work done, which I actually happen to be very interested in.
A Pull Request will be welcome :-)