Redisson is a Java memory-resident data grid implemented on the basis of Redis. Compared with Jedis, which exposes underlying operations, Redisson provides a series of distributed Java common objects and also provides many distributed services. (Recommended learning: Redis video tutorial)
Serialization
Redisson’s object encoding class is used to convert objects Perform serialization and deserialization to read and store the object in Redis.
The default encoder by Redisson is JsonJacksonCodec. When JsonJackson serializes objects with bidirectional references, an infinite loop exception will occur. After fastjson checks out the double reference, it will automatically replace it with the reference character $ref and terminate the cycle.
In my case, I serialized a service. This service has been hosted by spring, and it is also injected into another service. Fastjson can be used to serialize to redis normally, while JsonJackson can Throws infinite loop exception.
In order to make the serialized content visible, there is no need to use redission’s other built-in binary encoders and implement the encoder by yourself:
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<Object> decoder = (buf, state) -> JSON.parseObject(new ByteBufInputStream(buf), Object.class); @Override public Decoder<Object> getValueDecoder() { return decoder; } @Override public Encoder getValueEncoder() { return encoder; } }
More Redis related technical articles, Please visit the Redis Getting Started Tutorial column to learn!
The above is the detailed content of How to serialize redisson. For more information, please follow other related articles on the PHP Chinese website!

使用场景1、下单成功,30分钟未支付。支付超时,自动取消订单2、订单签收,签收后7天未进行评价。订单超时未评价,系统默认好评3、下单成功,商家5分钟未接单,订单取消4、配送超时,推送短信提醒……对于延时比较长的场景、实时性不高的场景,我们可以采用任务调度的方式定时轮询处理。如:xxl-job今天我们采

需要的Mavenorg.springframework.bootspring-boot-starter-data-redisio.lettucelettuce-coreredis.clientsjedisorg.springframework.sessionspring-session-data-redisorg.redissonredisson3.17.5application-redis.ymlspring:redis:host:106.12.174.220port:6379password

如果你之前是在用 Redis 的话,那使用 Redisson 的话将会事半功倍,Redisson 提供了使用 Redis的最简单和最便捷的方法。Redisson的宗旨是促进使用者对 Redis 的关注分离(Separation of Concern),从而让使用者能够将精力更集中地放在处理业务逻辑上。

Redisson是一种基于Redis的Java应用程序缓存解决方案。它提供了许多有用功能,使得在Java应用中使用Redis作为缓存变得更加方便和高效。Redisson提供的缓存功能包括:1.分布式映射(Map):Redisson提供了一些用于创建分布式映射的API。这些映射可以包含键值对、哈希表项或对象,它们可以支持在多个节点之间共

Redis和Redisson是现代化的内存数据存储和分布式数据存储中重要的两个工具。Redis是一个开源的内存数据库,它支持不同的数据结构,例如字符串、列表、哈希表、集合等。而Redisson是一个用Java语言编写的分布式数据服务框架,它可以轻松地将Java对象映射到分布式存储中。Redis和Redisson有一些相同的使用场景,例如:缓存:Redis和R

随着互联网应用的不断增多和用户量的不断增大,分布式系统的需求越来越高。为了保证分布式系统的稳定性和数据一致性,锁的使用是必不可少的。然而,在分布式系统中,锁的实现具有一定的难度和复杂性。传统的锁实现方式难以满足高并发和高可用的需求。因此,本文将介绍如何使用Redisson实现分布式API锁,以解决分布式系统中的锁问题。Redisson是一个基于Redis实现

前置Java-Redis-Redisson配置基础上我们进行了改造,让锁的使用更加方便基础设施RedissonLockimportjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;@Target(ElementType.METHOD)@Retention(

随着互联网技术的不断发展和应用场景的多样化,分布式应用成为了现代互联网应用的标配。在分布式应用中,为了协调各个节点之间的数据同步和协作,需要使用分布式锁机制。而Redisson是一款基于Redis技术实现的分布式锁框架,它提供了简单易用的API,方便Java开发者在开发中使用分布式锁。本文主要介绍JavaAPI开发中使用Redisson进行分布式锁处


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
