zoukankan      html  css  js  c++  java
  • 客户端连接Codis集群

    新建maven webapp项目

    添加相关依赖:

    <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>2.9.0</version>
            </dependency>
    <dependency>
                <groupId>org.redisson</groupId>
                <artifactId>redisson</artifactId>
                <version>3.3.2</version>
            </dependency>

    编写测试类:

    package com.czhappy.redis_test;
    
    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.JedisPool;
    import redis.clients.jedis.JedisPoolConfig;
    
    public class JedisTest {
    
        public static void main(String[] args) {
            // 开启Jedis连接池
            JedisPoolConfig jpc = new JedisPoolConfig();
            jpc.setMaxTotal(50);
            jpc.setMinIdle(10);
            JedisPool jp = new JedisPool(jpc,"192.168.84.128",19000);
    
            // 开启Jedis客户端
            Jedis jedis = jp.getResource();
    
            jedis.set("k1","v1");
            System.out.println(jedis.get("k1"));
    
            jedis.close();
        }
    
    
    }
    package com.czhappy.redis_test;
    
    import org.redisson.Redisson;
    import org.redisson.api.RBucket;
    import org.redisson.api.RedissonClient;
    import org.redisson.config.Config;
    
    public class RedissonTest {
    
        public static void main(String[] args) {
    
            Config config = new Config();
            config.setCodec(new org.redisson.client.codec.StringCodec());
            config. useSingleServer().setAddress("192.168.84.128:19000");
    
            RedissonClient redisson = Redisson.create(config);
            RBucket<String> keyObject = redisson.getBucket("k2");
    
            keyObject.set("v2");
    
            System.out.println(keyObject.get());
    
            redisson.shutdown();
        }
    
    }

    运行上面的两个Main方法,观察数据是否保存成功

    6831为主节点,6832为从节点

    进入redis的bin目录下,启动redis命令行窗口:

      

  • 相关阅读:
    POJ2182Lost Cows
    BZOJ4003: [JLOI2015]城池攻占
    POJ1635Subway tree systems
    BZOJ1005: [HNOI2008]明明的烦恼
    POJ1182 NOI2001 食物链
    栈的链式实现
    栈的数组实现
    链表ADT的实现
    #ifndef的用法
    using namespace std
  • 原文地址:https://www.cnblogs.com/chenzheng8975/p/9553282.html
Copyright © 2011-2022 走看看