We use Redis on Spark to cache our key-value pairs.This is the code:
But compiler gave me feedback like this:
Could somebody tell me how to serialize the data get from Redis.Thanks a lot. |
||
In Spark, the functions on The Redis connection here is not serializable as it opens TCP connections to the target DB that are bound to the machine where it's created. The solution is to create those connections on the executors, in the local execution context. There're few ways to do that. Two that pop to mind are:
A singleton connection manager can be modeled with an object that holds a lazy reference to a connection (note: a mutable ref will also work).
This object can then be used to instantiate 1 connection per worker JVM and is used as a
The advantage of using the singleton object is less overhead as connections are created only once by JVM (as opposed to 1 per RDD partition) There're also some disadvantages:
(*) code provided for illustration purposes. Not compiled or tested. |
|||||||||||||
|
You're trying to serialize the client. You have one |
|||||||||||||
|