Question

There is built in compression in spymemcached. While Jedis is the preferred java client for Redis, is there any built in compression api?

I did not find any API. Is there any other alternative compression technique for Redis?

Était-ce utile?

La solution

Jedis actually does some operations on String values as java uses UTF-16 and redis uses C-char 8 bit encoding. There is a class named SafeEncoder which ensures that everything is correct.

If you want to compress data, you have 2 options, you can edit some configuration on redis like ziplists and intsets or you can compress manually your values using an algorithm of your choice.

For instance, I have used kryo in java, which can gives you a byte array from an object, you compress it using deflate, and then you convert it to a base 64 String to persist it. To get your object back, you get the base 64 string, you get the byte array, you inflate it, and then deserialize it using kryo. And it is done :)

EDIT

You can also skip the base 64 operation and use Jedis with bytearray signatures that are implemented in BinaryJedis.java, it will be cleaner and quicker.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top