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

  • 相关阅读:
    转载集合
    TYVJ P1053 字符串的展开 Label:字符 水
    划分数系列问题
    关于inf的问题
    TYVJ P1031 热浪 Label:dijkstra 最短路
    TYVJ P1032 零用钱 Label:贪心
    如何简单形象又有趣地讲解神经网络是什么?知乎
    CString
    利用afxDump来调试自己的程序
    mfc 调试 弹消息
  • 原文地址:https://www.cnblogs.com/aknife/p/13912957.html
Copyright © 2011-2022 走看看