1.pom.xml引入对应数据文件

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
1
2
3
4
5
6
7
8
9
2.yml配置redis连接信息

redis:
database: 0
port: 7000
jedis:
pool:
max-idle: 20
min-idle: 2
max-active: 50
max-wait: 3000
host: 192.168.1.140
timeout: 5000
1
2
3
4
5
6
7
8
9
10
11
3.RedisConfig配置

RedisConfig
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig extends CachingConfigurerSupport {
// @Bean
// public RedisTemplate<Object,SendParameter> empRedisTemplate(RedisConnectionFactory redisConnectionFactory)
// throws UnknownHostException{
// RedisTemplate<Object,SendParameter> template = new RedisTemplate<Object, SendParameter>();
// template.setConnectionFactory(redisConnectionFactory);
// Jackson2JsonRedisSerializer<SendParameter> ser = new Jackson2JsonRedisSerializer<SendParameter>(SendParameter.class);
// template.setDefaultSerializer(ser);
// return template;
// }

@Bean
public RedisTemplate<String, List<Map<String, Object>>> redisTemplate(RedisConnectionFactory redisConnectionFactory) {

RedisTemplate<String, List<Map<String, Object>>> template = new RedisTemplate<String, List<Map<String, Object>>>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisObjectSerializer());
return template;
}
}
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
RedisObjectSerializer
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializingConverter;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

public class RedisObjectSerializer implements RedisSerializer<Object> {
private Converter<Object, byte[]> serializer = new SerializingConverter();
private Converter<byte[], Object> deserializer = new DeserializingConverter(http://www.my516.com);
static final byte[] EMPTY_ARRAY = new byte[0];

@Override
public Object deserialize(byte[] bytes) {
if (isEmpty(bytes)) {
return null;
}
try {
return deserializer.convert(bytes);
} catch (Exception ex) {
throw new SerializationException("Cannot deserialize", ex);
}
}

@Override
public byte[] serialize(Object object) {
if (object == null) {
return EMPTY_ARRAY;
}
try {
return serializer.convert(object);
} catch (Exception ex) {
return EMPTY_ARRAY;
}
}

private boolean isEmpty(byte[] data) {
return (data == null || data.length == 0);
}
}

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

---------------------

springboot-redis相关配置整理的更多相关文章

  1. Redis相关知识整理

    Redis相关知识整理 1. Redis和MySQL的区别?a).mysql是关系型数据库,而redis是NOSQL,非关系型数据库.mysql将数据持久化到硬盘,读取数据慢,而redis数据先存储在 ...

  2. redis相关配置

    redis相关配置1.yum 源码 rpm yum 快速,间接,高效,解决依赖关系,(自动安装到某个路径,不可控),通过yum安装的软件查询命令 rpm -ql nginx yum源的软件包可能版本非 ...

  3. SpringBoot数据源相关配置

    数据源配置 单数据源 配置步骤 引入依赖:H2数据库驱动.JDBC依赖.acturator(运维).web模块(用于测试).lambok(使用@Slf4j打印日志). 直接配置所需的Bean,注入容器 ...

  4. SpringBoot+Redis相关配置文件

    springboot整合redis配置类 package com.yalong.config; import com.fasterxml.jackson.annotation.JsonAutoDete ...

  5. SpringBoot Redis序列化配置

    Redis配置 #Redis spring.redis.host= spring.redis.port=6379 spring.redis.database=0 # Redis服务器连接密码(默认为空 ...

  6. Linux 安装redis 基本配置 发布订阅,安全配置,持久化 rdb ,aof

    redis redis相关配置1.yum  源码 rpm  yum 快速,间接,高效,解决依赖关系,(自动安装到某个路径,不可控),通过yum安装的软件查询命令 rpm -ql nginx  yum源 ...

  7. Maven + Springboot + redis 配置

    前言 刚进入到Java 开发的世界,对于小白Java的我来说,使用Maven + SpringBoot 的项目下启动redis: 第一步 本地安装Redis 服务 关于redis的教程链接 点击这里: ...

  8. springboot +redis配置

    springboot +redis配置 pom依赖 <dependency> <groupId>org.springframework.boot</groupId> ...

  9. springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息

    1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...

随机推荐

  1. VS2010MFC编程入门

    一.MFC编程入门教程之目录 第1部分:MFC编程入门教程之目录 1.MFC编程入门之前言  鸡啄米的C++编程入门系列给大家讲了C++的编程入门知识,大家对C++语言在语法和设计思想上应该有了一定的 ...

  2. element-ui中的loading的实际应用

    实际开发中,要如何指定loading在我们想要的区域加遮罩呢? 前提: 你已经引入element-ui,如下: import ElementUI from 'element-ui' import { ...

  3. AcWing 314. 低买 (线性DP)打卡

    题目:https://www.acwing.com/problem/content/316/ 题意:求一个最长单调递减子序列,然后并且求方案数,如果序列完全一样就不要了 思路:我们肯定时修改LIS,我 ...

  4. python中常用得字符串,列表函数汇总

    字符串函数: 1,replace函数,替换函数.s = s.replace(old,new),老得元素被新的元素替换.注意不能直接写s.replace(old,new).要写s=s.replace(o ...

  5. wndr4300刷任意系统及刷回官方原厂系统

    4300是目前性价比比较高的可玩路由器了,如果要买的话要买v1版本的,目前卖的都是v2,v2刷不了第三方系统. 注意:如果带宽低于50M,可以随便刷第三方系统玩,如果高于50M的带宽或者想组建千兆局域 ...

  6. Apache: No space left on device: Couldn’t create rewrite_map(XXXX)

    启动apache的时候 有时候会遇到这样的错误:No space left on device: Couldn’t create rewrite_map(XXXX) 第一眼看以为是磁盘没有空间了,其实 ...

  7. CodeForce-1196D1-RGB Substring (easy version)

    原题链接 题目大意: 给出一串由'R', 'G', 'B'组成的长度为n的字符串,在里面选出一个长度为k的子串,要求在改变最少字符的情况下同时也是"RGBRGBRGB…"的子串. ...

  8. maven导出工程pom文件中依赖的jar包

    在工程的pom文件里加上下面plugin, 然后执行mvn clean package -Dmaven.test.skip=true命令,就可以lib包收集起来了 <plugin> < ...

  9. HTML段落,换行,字符实体

    HTML段落,换行,字符实体 html段落 <p>标签定义一个文本段落,一个段落含有默认的上下间距,段落之间会用这种默认间距隔开,代码如下: <!DOCTYPE html> & ...

  10. linux 文件解压

    解压 tar -xvf file.tar //解压 tar包 tar -xzvf file.tar.gz //解压tar.gz tar -xjvf file.tar.bz2   //解压 tar.bz ...