栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Redis(九) 用java操作集群

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Redis(九) 用java操作集群

一. 依赖
  
        
            redis.clients
            jedis
            3.7.0
        
        
            com.redislabs
            jrebloom
            1.2.0
        
        
            org.redisson
            redisson
            3.17.5
        
        
            io.lettuce
            lettuce-core
            6.2.0.RELEASE
        
二 . 操作类
 Set nodes = new HashSet<>();
        nodes.add(new HostAndPort("1.12.235.192", 7016));
        nodes.add(new HostAndPort("1.12.235.192", 7017));
        nodes.add(new HostAndPort("1.12.235.192", 7018));
        nodes.add(new HostAndPort("1.12.235.192", 7019));
        nodes.add(new HostAndPort("1.12.235.192", 7020));
        nodes.add(new HostAndPort("1.12.235.192", 7021));

        JedisPoolConfig config = new JedisPoolConfig();
        //连接池最大连接数
        config.setMaxIdle(300);
        //最大连接数
        config.setMaxTotal(1000);
        //连接最大等待时间,若是-1没有限制
        config.setMaxWaitMillis(30000);
        //在空闲时检查有效性
        config.setTestOnBorrow(true);
        JedisCluster cluster = new JedisCluster(nodes,15000,15000, 5, "123", config);
        String set = cluster.set("k1", "v1");
        System.out.println(set);
        String k1 = cluster.get("k1");
        System.out.println(k1);
三.application配置
spring.redis.host=1.12.235.192
spring.redis.password=123
spring.redis.port=7016

server.port=8080

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1040882.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号