zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    python3.5中的格式化输出
    关于IDE集成开发环境,Pycharm小技巧
    python3.5中的赋值运算符和逻辑运算符
    SecureCRT 使用技巧
    selenium-键盘和鼠标事件
    selenium-各种定位方法
    selenium-百度搜索框输入后,定位联想下拉框元素
    selenium
    mysql-client 与mysql-server的区别
    MySql8.0.15 window 初始化 修改密码
  • 原文地址:https://www.cnblogs.com/aknife/p/13912957.html
Copyright © 2011-2022 走看看