# springboot-08-redis **Repository Path**: mjkapps/springboot-08-redis ## Basic Information - **Project Name**: springboot-08-redis - **Description**: redis的简单整合 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-02-15 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springboot-08-redis #### 介绍 redis的简单整合 #### 操作步骤 1. 引入依赖 ``` org.springframework.boot spring-boot-starter-data-redis ``` 2. application.yml配置redis连接地址 3. 使用StringRestTemplate操作字符串,RestTemplate操作对象 - (1).redisTemplate.opsForValue();//操作字符串 - (2).redisTemplate.opsForHash();//操作hash - (3).redisTemplate.opsForList();//操作list - (4).redisTemplate.opsForSet();//操作set - (5).redisTemplate.opsForZSet();//操作有序set 4.自定义RedisTemplate来防止序列化引发的乱码 ``` @Bean public RedisTemplate usRedisTemplate( RedisConnectionFactory redisConnectionFactory) throws UnknownHostException { RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory); /** * 设置Jackson2JsonRedisSerializer * 使用setDefaultSerializer方法 */ Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(User.class); template.setDefaultSerializer(serializer); return template; } ```