scala-redis-nb icon indicating copy to clipboard operation
scala-redis-nb copied to clipboard

Unrestrict Redis Key and String types

Open andyscott opened this issue 12 years ago • 15 comments

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

andyscott avatar Aug 29 '13 23:08 andyscott

I can head this up, assuming it's a wanted change.

andyscott avatar Aug 29 '13 23:08 andyscott

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.

guersam avatar Aug 30 '13 00:08 guersam

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.

andyscott avatar Aug 30 '13 01:08 andyscott

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.

guersam avatar Aug 30 '13 01:08 guersam

+1 .. we already have the machinery in place.

debasishg avatar Aug 30 '13 06:08 debasishg

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.

andyscott avatar Aug 30 '13 06:08 andyscott

Any update on this, @andyscott? It you don't have enough time I can handle this.

guersam avatar Sep 10 '13 05:09 guersam

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.

andyscott avatar Sep 10 '13 17:09 andyscott

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

danielkza avatar Nov 18 '13 09:11 danielkza

Hi Daniel -

Which version of scala-redis-nb are u using right now ?

Thanks.

debasishg avatar Nov 18 '13 10:11 debasishg

I'm using version 0.3.

danielkza avatar Nov 18 '13 10:11 danielkza

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 ?

debasishg avatar Nov 18 '13 10:11 debasishg

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.

danielkza avatar Nov 18 '13 10:11 danielkza

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.

danielkza avatar Nov 18 '13 11:11 danielkza

A Pull Request will be welcome :-)

debasishg avatar Nov 18 '13 12:11 debasishg