How to use java object as a value in Redis
You can easily do it with Redis based framework for Java - Redisson:
RBucket<AnyObject> bucket = redisson.getBucket("anyObject");
// set an object
bucket.set(new AnyObject());
// get an object
AnyObject myObject = bucket.get();
// supports some useful functions like:
bucket.trySet(object);
bucket.compareAndSet(oldObject, newObject);
AnyObject prevObject = bucket.getAndSet(new AnyObject());
It handles serialization and maintains internal connection pool so you don't need to deal with it each time when you need to send an object to Redis. Redisson does it for you. Work with Redis as you used to work with Java objects.
It supports many popular codecs (Jackson JSON
, Avro
, Smile
, CBOR
, MsgPack
, Kryo
, FST
, LZ4
, Snappy
and JDK Serialization
).
DISCLAMER: I'm a lead developer of Redisson
There is no direct means - it can be done only via serialization and storing resultant byte-array. Please refer http://static.springsource.org/spring-data/redis/docs/1.0.x/api/org/springframework/data/redis/serializer/package-summary.html if you want to use spring.