Skip to content
Advertisement

Read data saved by spark redis using Java

I using spark-redis to save Dataset to Redis. Then I read this data by using Spring data redis:

This object I save to redis:

JavaScript

Save object by using spark-redis:

JavaScript

Repository:

JavaScript

I can’t read this data have been saved in Redis by using Spring data redis because structure data saved by spark-redis and spring data redis not same (I checked value of keys created by spark-redis and spring data redis are different by using command: redis-cli -p 6379 keys * and redis-cli hgetall $key)

So how to read this data have been saved using Java or by any library in Java?

Advertisement

Answer

The following works for me.

Writing data from spark-redis.

I use Scala here, but it’s essentially the same as you do in Java. The only thing I changed is I added a .option("key.column", "id") to specify the hash id.

JavaScript

In spring-data-redis I have the following:

JavaScript

I use CrudRepository instead of JPA:

JavaScript

Querying:

JavaScript

The output:

JavaScript

You may notice that the id field was not populated because the spark-redis stored has a hash id and not as a hash attribute.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement