I am pretty new to Redis.
I downloaded Jedis and added that to my classpath. But, it doesnt provide a way to store java object as "value"
Am i missing something or Jedis doesn't provide the way to store java object as value?
Thanks, -Venkat
Object Storing Procedure. In the Redis, Everything can be stored as only key-value pair format. Key must be unique and storing an object in a string format is not a good practice anyway. Objects are usually stored in a binary array format in the databases.
Redisson is a Redis-based framework that provides a wrapper and interface for working with Redis in Java. Redisson includes implementations of many familiar Java classes, including distributed objects, distributed services, distributed locks and synchronizers, and distributed collections.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With