Does Riak support Range Queries over binary safe strings?

339 Views Asked by At

Coming from Redis, I love that you can just put any binary blob in Redis which is just treated as a string. This is possible because Redis strings are what they call 'binary safe'. This makes it possible to do stuff like rangequeries on top of string-encoded binary data, which is super useful for bitset-operations, etc.

I'm investigating Riak and I like it so far. Riak seems to have range queries, but I'm not sure if strings in Riak are "Binary safe" in the above sense. If not, is there another way to store binary data in Riak and still do range queries over them quickly?

Thanks

1

There are 1 best solutions below

1
On

Since you mention "range queries" I'm assuming you mean 2i (secondary indexes) when talking about Riak.

A _bin secondary index key in Riak is stored as plain old bytes and sorting (for ranges) is a byte-by-byte comparison.

Most people use UTF-8/ISO-8859-1 strings for keys in _bin indexes, but that's not a requirement.

Note, however, that the HTTP API is somewhat clumsy in this regard at the moment. This SO question covers that in detail: URL-unsafe Secondary Index names in Riak do not work

With protocol buffers you can just throw bytes at it and it doesn't care.

That said, our current clients are fairly UTF-8 centric at the moment. Specifically the Java client expects the index value to be a UTF-8 string. That's going to be addressed in the 2.0 version.