• 常用公共配置类——Redis配置


    @Configuration
    public class RedisConfig {
        @Autowired
        private RedisConnectionFactory factory;
    
        @Bean
        public RedisTemplate<String, Object> redisTemplate() {
            RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
            //StringRedisSerializer():进行序列化,防止SpringBoot整合Redis出现乱码问题
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashValueSerializer(new StringRedisSerializer());
            redisTemplate.setValueSerializer(new StringRedisSerializer());
            redisTemplate.setConnectionFactory(factory);
            return redisTemplate;
        }
    
        /**
         * 针对map类型的数据操作
         */
        @Bean
        public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
            return redisTemplate.opsForHash();
        }
    
        /**
         * valueOperations:简单K-V操作
         */
        @Bean
        public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
            return redisTemplate.opsForValue();
        }
    
        /**
         * 针对list类型的数据操作
         */
        @Bean
        public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
            return redisTemplate.opsForList();
        }
    
        /**
         * set类型数据操作
         */
        @Bean
        public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
            return redisTemplate.opsForSet();
        }
    
        /**
         * zset类型数据操作
         */
        @Bean
        public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
            return redisTemplate.opsForZSet();
        }
    }
    一个小小后端的爬行痕迹
  • 相关阅读:
    程序员应该看的书
    linux下grep命令详解
    apache基本配置
    shell脚本从windows下发送到linux下运行失败的问题
    nginx服务器的安装和配置基础
    linux下ps命令用法
    apache的python部署
    《我刀刻我心——关羽往事》新书发布会在京举行
    C++图书中的王者
    C++应用程序性能优化
  • 原文地址:https://www.cnblogs.com/heikedeblack/p/14980883.html
Copyright © 2020-2023  润新知