nosql--RedisTemplate定制化

nosql--RedisTemplate定制化

1、序列化

stringRedisTemplate

RedisTemplate<Object,Object> redisTemplate

2、如果使用redis中保存数据会使用默认的序列化机制,导致redis中保存的对象不可视

2.1将所有的对象以JSON的形式保存

默认序列化是JdkSerializationRedisSerializer

如果没有redisTemplate配置

2.2配置reids自定义配置

2.3转化成功

2.4配置文件代码

java 复制代码
package com.example.boot3.redis.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

/**
 * @author jitwxs
 * @date 2023年12月25日 22:23
 */
public class AppTedisConfiguration {
   /*
   允许Object类型的key-value,都可以转换成json进行存储
   @param redisConnecctionFactory 自动配置好连接工厂
   @return
   */
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> template = new RedisTemplate();
        template.setConnectionFactory(redisConnectionFactory);
//        把对象转为json字符串的序列化工具
        template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}

3redis客户端

RedisTemplate、StringRedisTemplae:操作redis的工具类

要从redis的连接厂获取连接才能操作redis

Redis 客户端:

jedis

Lettuce:默认

配置jedis、lettuce的底层参数

java 复制代码
#设置lettuce的底层参数
#spring.data.redis.client-type=lettuce
#spring.data.redis.lettuce.pool.enabled=true
##线程池
#spring.data.redis.lettuce.pool.max-active=8

#设置jedis的底层参数
spring.data.redis.client-type=jedis
spring.data.redis.jedis.pool.enabled=true
spring.data.redis.jedis.pool.max-active=8
相关推荐
m0_687399843 分钟前
QT combox 前缀匹配
开发语言·数据库·qt
计算机学姐11 分钟前
基于微信小程序的调查问卷管理系统
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
2401_857622667 小时前
SpringBoot框架下校园资料库的构建与优化
spring boot·后端·php
2402_857589367 小时前
“衣依”服装销售平台:Spring Boot框架的设计与实现
java·spring boot·后端
vvvae12348 小时前
分布式数据库
数据库
哎呦没8 小时前
大学生就业招聘:Spring Boot系统的架构分析
java·spring boot·后端
_.Switch9 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
雪域迷影9 小时前
PostgreSQL Docker Error – 5432: 地址已被占用
数据库·docker·postgresql
编程、小哥哥9 小时前
netty之Netty与SpringBoot整合
java·spring boot·spring
bug菌¹10 小时前
滚雪球学Oracle[4.2讲]:PL/SQL基础语法
数据库·oracle