当前位置:网站首页>Redis insert data garbled solution

Redis insert data garbled solution

2022-07-06 20:39:00 xiao pan

1、key and value The statement

 

2、 New configuration class

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import javax.annotation.PostConstruct;

@Configuration
public class RedisUtils {

    @Autowired
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void init() {
        initRedisTemplate();
    }

    private void initRedisTemplate() {
        RedisSerializer stringSerializer = redisTemplate.getStringSerializer();
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(stringSerializer);
    }
}

3、 Perfect solution to garbled code

 

 

原网站

版权声明
本文为[xiao pan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131152307252.html