1、添加redis依赖
<!-- 添加redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
2、增加配置application.properties
#redis配置 spring.redis.host=127.0.0.1 spring.redis.port=6379 #最大连接数 spring.redis.pool.max-active=10000 #最大控件连接数 spring.redis.pool.max-idle=5
3、工具类
package com.zzstxx.redis; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; /** * redis工具类 * @author zxf * */ @Component public class RedisDao { @Autowired private StringRedisTemplate stringRedisTemplate; public void set(String key, String value) { this.stringRedisTemplate.opsForValue().set(key, value); } public String get(String key) { return this.stringRedisTemplate.opsForValue().get(key); } public void delete(String key) { this.stringRedisTemplate.delete(key); } }
4、测试类
package com.zzstxx.sysuser; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import com.zzstxx.redis.RedisDao; @RunWith(SpringRunner.class) @SpringBootTest public class Springboot08CrudJarApplicationTests { @Autowired private RedisDao redisDao; @Test public void testSet() { String key = "name"; String value = "zhangsan"; this.redisDao.set(key, value); String value1 = this.redisDao.get(key); System.out.println(value1); } /*@Test public void testGet() { String key = "name"; String value = this.redisDao.get(key); System.out.println(value); } @Test public void testDelete() { String key = "name"; this.redisDao.delete(key); }*/ }
相关推荐
Springboot整合Redis集群,零配置方式;另外用AOP实现了操作缓存的三套自定义注解,有兴趣的小伙伴可以试试看.
springboot整合redis.算是比较全面的一种整合方式了. springboot整合redis.算是比较全面的一种整合方式了.
springboot集成redis集群,redis安装包配置,参考文章:https://blog.csdn.net/zhizhuodewo6/article/details/82316164
主要介绍了SpringBoot Redis配置Fastjson进行序列化和反序列化实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
springboot整合redis选用 `Lettuce` 作为redis框架,选用 `Protobuf` 作为序列化框架
SpringBoot集成Redis应用配置(附完整配置文件)
通过配置文件实现连接单机redis或集群redis demo,实现开发时使用单机redis,线上使用集群redis
SpringBoot基于redis的分布式锁,有word使用文档,根据文档配置即可使用
springboot整合redis集群(三种方式)源码
基于Springboot+Redis+Mysql+Kafka开发的高并发限时的商品秒杀系统.zip 毕业设计 基于springboot mysql Vue的系统开发,供参考,提供说明材料+源代码 毕业设计 基于springboot mysql Vue的系统开发,供参考,提供...
基于springboot下对mysql,mongodb,redis支持ipv6的改造(csdn)————程序
基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。
本资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。有任何...
springboot集成redis、mybatis...5、springboot实现初始化加载配置(实现缓存预热)的两种方式 6、二级缓存联合使用 方式一:redis原生方法工具类(RedisService)+redis+mybatis 方式二:CacheManager+redis+mybatis
Spring Boot为Redis, MongoDB, Elasticsearch, Solr和Gemfire提供自动配置。本文详细介绍了springboot配置多个redis连接,有兴趣的可以了解一下。
主要介绍了详解SpringBoot Redis自适应配置(Cluster Standalone Sentinel),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
使用springboot整合redis,使用默认的序列化配置,然后使用redis-client去查询时查询不到相应的key.问题出在哪,怎么解决呢?下面小编给大家带来了springboot整合spring-data-redis遇到的坑,需要的的朋友参考下吧
SpringBoot整合Redis,包括整合单机版Redis、redis-cluster集群、redis哨兵模式
SpringBoot集成Redis集群
springboot2配置Lettuce连接池完整代码,采用common2-pool连接池,Lettuce为redis高级客户端,由于阅读官网文档太简单,无法完成配置,所有本示例是通过阅读源码后编写的