*/@BeanpublicRedisTemplate<String,Object>redisTemplate(RedisConnectionFactory redisConnectionFactory)throws UnknownHostException{RedisTemplate<String,Object>template=newRedisTemplate();template.setConnectionFactory(redisConnectionFactory);template.setKeySerializer(newStringRedisSerializer());template.setValueSerializer(v...
spring: # redis 配置 redis: # 地址 host: 127.0.0.1 # 端口,默认为6379 port: 6379 # 密码,没有不填 password: '' # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # ...
由于配置后,连接池也需要自行设置,因此Redis的配置文件修改为如下设置 RedisConfig.java 代码语言:javascript 复制 packagecom.quison.test.config;importorg.apache.commons.pool2.impl.GenericObjectPoolConfig;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.beans.factory.annotation....
redisTemplate.setKeySerializer(new StringRedisSerializer()); // 设置value用jackjson进行处理 redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); // hash也要进行修改 redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); /...
SpringBoot整合Redis--RedisTemplate 1、导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> 2、编写配置文件 spring:redis:host:192.168.27.132port:6379password:lzyredisdatabase:1jedis:pool:max-active:10max-wait:3000mi...
2、配置连接信息 spring.redis.host=172.30.3.157 spring.redis.port=6379 spring.redis.password= 3、配置Config 配置类,修改序列化方式,实体类需要实现 java.io.Serializable 接口 @ConfigurationpublicclassRedisConfig { @BeanpublicRedisTemplate<String, Object>redisTemplate(RedisConnectionFactory redisConnectionFactory...
1.x的配置可以直接new即可 会少很多代码//RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);@Beanpublic RedisCacheManager redisCacheManager(RedisConnectionFactory factory,ResourceLoader resourceLoader) {RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); // 生成一...
local-redis: host: 127.0.0.1 port: 6379 database: 0 password: lettuce: pool: max-active: 16 max-wait: 100 max-idle: 8 min-idle: 4 对应的配置类,采用Lettuce,基本设置如下,套路都差不多,先读取配置,初始化ConnectionFactory,然后创建RedisTemplate实例,设置连接工厂 ...
class) public StringRedisTemplate stringRedisTemplate( RedisConnectionFactory redisConnectionFactory) { StringRedisTemplate template = new StringRedisTemplate(); template.setConnectionFactory(redisConnectionFactory); return template; } } 直接用redisTemplate操作redis,需要很多行代码,因此直接封装好一个redisutils...
spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.password=123 上述两个步骤完成后,SpringBoot自动在Spring容器中配置一个redisTemplate的Bean,所以可以直接使用redisTemplate 3、实现Redis @AutowiredprivateRedisTemplate<String,Object>redisTemplate; ...