集群测试代码

    Set<HostAndPort> set = new HashSet<>();
    set.add(new HostAndPort("127.0.0.1", 6001));
    set.add(new HostAndPort("127.0.0.1", 6002));
    set.add(new HostAndPort("127.0.0.1", 6003));
    set.add(new HostAndPort("127.0.0.1", 6004));
    set.add(new HostAndPort("127.0.0.1", 6005));
    set.add(new HostAndPort("127.0.0.1", 6006));

    JedisCluster cluster = new JedisCluster(set);
    List<String> list = cluster.lrange("list2", 0, -1);
    list.stream().forEach(System.out::print);

    cluster.close();

向业务逻辑中添加缓存

创建单机版和集群版的redis,提供一个公共的接口,并在shopping_content的spring文件中将其注入。
    <!--连接redis单机版-->
    <bean id="jedisClientPool" class="cs.hxr.jedis.JedisClientPool">
        <property name="JedisPool" ref="jedisPool"></property>
    </bean>
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="host" value="127.0.0.1"/>
        <constructor-arg name="port" value="6001"/>
    </bean>
    ApplicationContext context =
                new ClassPathXmlApplicationContext("classpath:spring/applicationContext-redis.xml");

    JedisClient jedisClient = (JedisClient) context.getBean("jedisClient");

results matching ""

    No results matching ""