腾讯RPC(tars)+Sprintboot+redis

本文介绍了如何将SpringBoot与Tars框架结合,通过Tars服务来管理和操作Redis,以实现对Redis的自动化使用。首先,讲解了在IDEA中搭建Tars服务的步骤,包括配置pom.xml、添加tars文件和属性配置文件。接着,展示了SpringBoot整合Redis的过程,包括创建配置管理类RedisConfig,实现对Redis的各种操作,并定义了RedisModel对象。最后,启动Tars服务,通过监听器AppStartListener在SpringBoot中初始化配置。
摘要由CSDN通过智能技术生成

1.  简介

springboot对常用的数据库支持外,对nosql 数据库也进行了封装自动化,为了方便其他应用程序快捷、方便的使用redis,而不用去管理连接,存储等,故把对redis逻辑操作如增、删、改、查放到tars(rpc框架)下,以达到上述目的。

2.  Tars服务搭建

2.1在IDEA开发工具中打开新建工程

2.2点击下一步后,在对话框中填写如图中的内容

点击下一步直到结束

2.3配置pom.xml

2.3.1     添加tars相关配置

 

2.3.2     添加springboot相关配置

2.3.3     添加redis相关配置

2.4添加tars文件,路径要与pom.xml中的一样

             

RedisTest.tars文件内容

  

2.5添加属性配置文件application.properties

2.6 利用tars文件生成对应代码

执行上述命令会增加下图红色部分代码

2.7 增加impl目录并创建RedisTestServantImpl类,实现上图中的接口

3.  Springboot整合Redis

添加下图红色标注的目录与文件

RedisConf主要是配置管理类,负责相关配置类的自动注入

package com.ancun.RedisTest.app.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serial

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值