• Windows下 redis命令及配置


    查询密码
    config get requirepass
    
    设置密码
    config set requirepass mima
    
    输入密码
    auth mima
    #注册安装服务
    .
    edis-server --service-install redis.windows.conf --loglevel verbose
    #卸载服务 . edis
    -server --service-uninstall 开启服务 .redis-server --service-start 停止服务 .redis-server --service-stop 注册Windows服务 . edis-server.exe --service-install redis.windows.conf --service-name redis6380 --port 6380

    SpringBoot整合redis(yml版)

    1.application.yml配置
    
    集群配置:
    
    spring:
      redis:
        database: 0
        pool:
          max-active: 100 #连接池最大连接数(负值表示没有限制)
          max-wait: 3000 #连接池最大阻塞等待时间(负值表示没有限制)
          max-idle: 200 #连接池最大空闭连接数
          min-idle: 50 #连接汉最小空闲连接数
          timeout: 600 #连接超时时间(毫秒)
        cluster:
          nodes:
            - 192.168.75.132:6380
            - 192.168.75.132:6381
            - 192.168.75.132:6382
            - 192.168.75.132:6383
            - 192.168.75.132:6384
            - 192.168.75.132:6385
    
    单机版配置:
    
    spring:
      redis:
        host: 192.168.75.132
        port: 6379  #可不配,因为底层默认值为6379
    
    2.配置类(指定序列化器)
    
    这里对key值的处理推荐使用StringRedisSerializer序列化器,因为这样在redis中保存时就不用带""号了
    
    这里对value值的处理推荐使用GenericJackson2JsonRedisSerializer,因为jackson2序列化器需要指定泛型,jdk序列化占用内存空间较大
    
    @Configuration
    public class CacheConfig {
        @Bean
        public RedisTemplate<String, Object> empRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
            RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
            template.setConnectionFactory(redisConnectionFactory);
            template.setKeySerializer(new StringRedisSerializer());
            template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
            return template;
        }
    }
    
    3.使用测试
    
    注意:使用时key泛型必须和配置类中保持一致
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class RedisCacheApplicationTests {
        @Autowired
        private RedisTemplate<String,Object> redisTemplate;
        @Test
        public void contextLoads() {
            redisTemplate.opsForValue().set("date", new Date());
           Date date = (Date) redisTemplate.opsForValue().get("test7");
           System.out.println(date);
        }
    
    }

    SpringBoot整合redis(yml版) https://zhuanlan.zhihu.com/p/80388562

  • 相关阅读:
    git-【六】分支的创建与合并
    git-【五】远程仓库
    git-【四】撤销修改和删除文件操作
    git-【三】理解工作区与暂存区的区别
    git-【二】本地git操作提交、版本回退
    git-【一】概述安装
    java-基础-【四】实际编程中的对象
    博客园打赏、赞助功能
    js-template-art【四】通过helper方法注册,调用外部方法
    js-template-art【三】js api
  • 原文地址:https://www.cnblogs.com/aknife/p/13912957.html
Copyright © 2020-2023  润新知