In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article uses easy-to-understand examples to introduce the method of redisson serialization, the code is very detailed, interested friends can refer to, hope to be helpful to you.
Redisson
Is a Java resident memory data grid (In-Memory Data Grid) based on Redis.
Based on the Netty framework based on NIO, Redisson makes full use of a series of advantages provided by Redis key-value database, and provides a series of common tool classes with distributed characteristics for users on the basis of the interfaces commonly used in the Java utility kit. As a result, the toolkit, which was originally used to coordinate single-machine multithreaded concurrent programs, obtains the ability to coordinate distributed multi-threaded concurrent systems, which greatly reduces the difficulty of designing and developing large-scale distributed systems. At the same time, combined with the unique distributed services, it further simplifies the cooperation between programs in the distributed environment.
Compatible with Redis 2.6 + and JDK 1.6 license, use Apache License 2.0 license protocol, read wiki for more usage information
Serialization
The object coding class of Redisson is used to serialize and deserialize the object to read and store the object in Redis.
The default encoder by Redisson is JsonJacksonCodec,JsonJackson. An infinite loop exception occurs when serializing objects with bidirectional references. On the other hand, fastjson will automatically replace it with the reference $ref after checking out the two-way reference, terminating the loop.
In my case, I serialize a service that is managed by spring and injected into another service, serializing to redis normally with fastjson, while JsonJackson throws an infinite loop exception.
In order to make the serialized content visible, you can implement your own encoder instead of other binary encoders that come with redission:
Import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.serializer.SerializerFeature;import io.netty.buffer.ByteBuf;import io.netty.buffer.ByteBufAllocator;import io.netty.buffer.ByteBufInputStream;import io.netty.buffer.ByteBufOutputStream;import org.redisson.client.codec.BaseCodec;import org.redisson.client.protocol.Decoder;import org.redisson.client.protocol.Encoder;import java.io.IOException;public class FastjsonCodec extends BaseCodec {private final Encoder encoder = in-> {ByteBuf out = ByteBufAllocator.DEFAULT.buffer () Try {ByteBufOutputStream os = new ByteBufOutputStream (out); JSON.writeJSONString (os, in,SerializerFeature.WriteClassName); return os.buffer ();} catch (IOException e) {out.release (); throw e;} catch (Exception e) {out.release (); throw new IOException (e);}}; private final Decoder decoder = (buf, state)-> JSON.parseObject (new ByteBufInputStream (buf), Object.class); @ Override public Decoder getValueDecoder () {return decoder;} @ Override public Encoder getValueEncoder () {return encoder }} on redisson serialization methods to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
MySQL5.7+keepalive+ enhanced semi-synchronous build document
© 2024 shulou.com SLNews company. All rights reserved.