首页 > 数据库 >redis配置(不全)

redis配置(不全)

时间:2024-08-02 17:51:28浏览次数:8  
标签:配置 redis 不全 springframework StringRedisSerializer template org import

1、pom 添加依赖

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

2、Redis 配置类

package com.exam.config;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
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 {

    @Bean
//    @SuppressWarnings(value = {"sf","sdf"})  // ‌SuppressWarnings注解的作用是用于抑制‌编译器产生某些类型的警告
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<Object, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);

        FastJsonRedisSerializer serializer = new FastJsonRedisSerializer(Object.class);

        // 使用 StringRedisSerializer 来序列化与发序列化 redis 的 key 值
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(serializer);

        // Hash 的 key 也采用 StringRedisSerializer 的序列方式
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setHashValueSerializer(serializer);

        template.afterPropertiesSet();

        return template;
    }
}

 

标签:配置,redis,不全,springframework,StringRedisSerializer,template,org,import
From: https://www.cnblogs.com/wangdch/p/18339285

相关文章

  • HarmonyOS:如何实现自定义的Tabs,TabContent内部实现如何动态配置
    前言:最近做开发任务的时候,想把Tabs自定义了,并且动态配置TabContent里面的内容,不是写死一样的,这个问题困扰了很长时间,试过**@BuilderParam**(类似于vue的插槽)传组件方式的,但是**@BuilderParam只能传一个,我想要传递的是一个数组,找了很多Api最后找到了WrappedBuilder[]**这种方......
  • Jenkins 配置 docker 容器
    Jenkins配置docker容器 搭建时打开代理。  1. 搭建dockerpulljenkins/jenkinsdockerrun-d-p10004:8080-p10005:50000-vD:\DockerVolume\jenkins\jenkins_mount:/var/jenkins_home-v/etc/localtime:/etc/localtime--restart=always--namejenkinsj......
  • 网络分组(Team)和网络绑定(bonding)的配置和区别
    一.网络分组(Team)的配置网络分组(Team)的运行模式,如下所示:运行模式描述循环(roundrobin)依次通过所有端口传输数据。活动备份(activebackup)通过一个端口传输数据,而其他端口则作为备份保留。负载均衡(loadbalance)使用主动Tx负载均衡和基于Berkeley数据包过......
  • Springboot Docker Redis Mysql集成
    尽管网上关于SpringbootDockerRedisMysql集成的文档很多,但是很多都是老文档,问题不少,所以我专门整理了这份文档。我家里的笔记本是mac,所以我就在mac上详细说明下我的搭建过程。首先我们需要安装docker,mac上本来就有docker的安装包,因此对于mac来说,安装docker就是一件比较轻松的......
  • 使用Redisson和分库分表技术实现海量请求注册功能
    文章目录1.海量注册的常见问题和解决方案概述2.布隆过滤器判断用户唯一性3.通过分布式锁和快速失败策略对同一时间的某一个账号进行锁定4.数据库唯一索引兜底5.通过水平分库水平分表配置分片规则6.通过自定义线程池和异步初始化配置线程池操作异步化1.海量......
  • redis-学习笔记一
    redis的常见数据类型及其使用场景常见的数据类型有五种:String字符串、List列表、Hash哈希、Set集合、Zset有序集合String字符串字符串是Redis中最基本的数据结构,可以存储任意类型的数据,包括文字、数字(整型、浮点等)等.它具有高效的读写操作和丰富的字符串处理函数,使用......
  • VMware虚拟机网络模式配置详解【原理,功能,特点层面】
    VMware虚拟机网络模式配置详解【原理,功能,特点层面】文章目录VMware虚拟机网络模式配置详解【原理,功能,特点层面】桥接模式(Bridged)原理功能点介绍虚拟网络编辑器配置虚拟机配置配置教程编辑-虚拟网络编辑器虚拟机网络配置特点NAT模式概念功能点介绍编辑-虚拟网络编......
  • Linux设备树配置指南:ES8388音频编解码器集成
    在嵌入式Linux开发中,设备树对于硬件集成至关重要。本文详细介绍了如何在设备树中配置ES8388音频编解码器,包括耳机检测、扬声器控制和音频路由。在嵌入式系统设计中,音频功能是一个常见需求。ES8388是一款流行的音频编解码器,支持多种音频输入输出功能。本文将指导您如何在Linux......
  • phpstudy配置SSL CA证书
    本地Windows环境,phpstudy集成php7后,出现错误提示:URLerror60:SSLcertificateproblem:unabletogetlocalissuercertificate查询问题:SSLCA证书配置缺失导致。1、从CURL官网下载CA证书(cacert.pem)可选择下载:https://curl.haxx.se/docs/caextract.html或直接下......
  • mybatis配置自动填充时间拦截器
    1.Annotation:①FillOnInsertimportjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;@Retention(RetentionPolicy.RUNTIME)@Target......