-4

After I compressed data by Snappy, and then stored it to Redis. But When I took it out of Redis, I found the data is different. I don't know why it is

totti
  • 9
  • 4
  • 1
    When you have "not working" code, then please provide a full [mcve]. Your question is simply not answerable "I did something, and then something happened. Now explain to me". Sorry, impossible. – GhostCat Jul 09 '18 at 09:06

2 Answers2

3

Yes, Snappy compression algorithm can be used with Redis. In fact, you can use any compression algorithm. As far as Redis is concerned, it is just bytes. What redis calls as "Strings" is more traditionally called as "byte array" in programming languages.

If you are seeing different values, it is most likely a problem with the way you are reading values. Some redis client libraries try to decode the response as UTF-8, and that isn't what you want it to do. Look at your client library documentation, and use the method that lets you set and get values as byte arrays.

Sripathi Krishnan
  • 30,948
  • 4
  • 76
  • 83
-1

Yes is the answer. If your problem is on java. You can check this repo here, with what i had done for compression and serialization java-spring-redis-compression-snappy-kryo

java-spring-redis-compression-snappy-kryo

Here is a sample of a Java Spring Boot Redis Cluster Data configuration.

It is an implementation with Redis Cluster and Redis Cache Manager.

  1. Snappy Compression

  2. Kryo Serialization

  3. Support ttl per cache key

Gradle configuration

  1. spring-data-redis
  2. lettuce-core
  3. snappy-java
  4. kryo
  5. commons-codec

Application Properties

data.rediscluster.nodes=redis1.foo.com:6379,redis2.foo.com:6379,redis3.foo.com:6379,redis4.foo.com:6379,redis5.foo.com:6379,redis6.foo.com:6379

data.rediscluster.ttl=2700

data.rediscluster.redirects=3

How to use it

 RedisCacheConfiguration.defaultCacheConfig()
.disableKeyPrefix()
.disableCachingNullValues()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericSnappyRedisSerializer()))
.entryTtl(Duration.ofSeconds(ttl));
Cbour
  • 49
  • 2
  • 9