redisson如何序列化


当前第2页 返回上一页

为了序列化后的内容可见,所以不用redission其他自带的二进制编码器,自行实现编码器:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

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;

 }

}

更多Redis相关技术文章,请访问Redis入门教程栏目进行学习!

以上就是redisson如何序列化的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

redisson如何序列化

更多相关阅读请进入《redisson》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...