Redis has been widely used, but redis itself does not have a method to directly store objects. We can store objects by converting them.
A rough summary of the following options: (Recommended learning: Redis video tutorial)
Option 1: The serialized object is Binary
Use redis interface:
jedis.get(byte[] key) jedis.set(byte[] key, byte[] value)
As for the serialization method, we have many choices, such as: Java serialize, Protobuf, or manual serialization by yourself
public byte[] serialize(Object obj); public Object unSerialize(byte[] bytes);
Option 2: Serialize to string
Use redis interface:
jedis.get(String key); jedis.set(String key, String value);
Serialize to string, we also have many choices : Json (Jackson, FastJson),
For more Redis-related technical articles, please visit theIntroduction Tutorial on Using Redis Database column to learn!
The above is the detailed content of Can redis store objects?. For more information, please follow other related articles on the PHP Chinese website!