当前位置: 首页>>代码示例>>Java>>正文


Java JedisCluster类代码示例

本文整理汇总了Java中redis.clients.jedis.JedisCluster的典型用法代码示例。如果您正苦于以下问题:Java JedisCluster类的具体用法?Java JedisCluster怎么用?Java JedisCluster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JedisCluster类属于redis.clients.jedis包,在下文中一共展示了JedisCluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@SuppressWarnings("resource")
public static void main(String[] args) {
	
	Set<HostAndPort> nodes = new HashSet<HostAndPort>();
	nodes.add(new HostAndPort("127.0.0.1", 7000));
	nodes.add(new HostAndPort("127.0.0.1", 7001));
	nodes.add(new HostAndPort("127.0.0.1", 7002));
	nodes.add(new HostAndPort("127.0.0.1", 7003));
	nodes.add(new HostAndPort("127.0.0.1", 7004));
	nodes.add(new HostAndPort("127.0.0.1", 7005));
	
	JedisCluster cluster = new JedisCluster(nodes, 5000);
	
	System.out.println(cluster.get("foo"));
	
	cluster.set("test", "6379");
	System.out.println(cluster.get("test"));
	
	Map<String, String> inviteePhone = new HashMap<String, String>();
	inviteePhone.put("inviterID", "1001");
	inviteePhone.put("status", "0");
	cluster.hmset("inviteePhone", inviteePhone);
	
	System.out.println(cluster.hget("inviteePhone", "inviterID"));
	System.out.println(cluster.hget("inviteePhone", "status"));
}
 
开发者ID:colddew,项目名称:mix-web,代码行数:27,代码来源:RedisClusterClient.java

示例2: getJedisCluster

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**
 * 注意:
 * 这里返回的JedisCluster是单例的,并且可以直接注入到其他类中去使用
 * @return
 */
@Bean
public JedisCluster getJedisCluster() {
    //获取服务器数组(这里要相信自己的输入,所以没有考虑空指针问题)
    String[] serverArray = redisProperties.getClusterNodes().split(",");
    Set<HostAndPort> nodes = new HashSet<>();

    for (String ipPort : serverArray) {
        String[] ipPortPair = ipPort.split(":");
        nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
    }

    return new JedisCluster(nodes,10000,
            1000,1,redisProperties.getPassword() ,
            new GenericObjectPoolConfig());
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:21,代码来源:JedisClusterConfig.java

示例3: testCalculateConnectionPerSlot

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void testCalculateConnectionPerSlot() {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  jc.set("foo", "bar");
  jc.set("test", "test");
  assertEquals("bar", node3.get("foo"));
  assertEquals("test", node2.get("test"));
  
  JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  jc2.set("foo", "bar");
  jc2.set("test", "test");
  assertEquals("bar", node3.get("foo"));
  assertEquals("test", node2.get("test"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:JedisClusterTest.java

示例4: testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified()
    throws InterruptedException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);

  int slot51 = JedisClusterCRC16.getSlot("51");
  jc.set("51", "foo");
  // node2 is responsible of taking care of slot51 (7186)

  node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
  assertEquals("foo", jc.get("51"));
  node3.clusterSetSlotStable(slot51);
  assertEquals("foo", jc.get("51"));

  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  // assertEquals("foo", jc.get("51")); // it leads Max Redirections
  node2.clusterSetSlotStable(slot51);
  assertEquals("foo", jc.get("51"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:JedisClusterTest.java

示例5: getJedisCluster

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean//bean
public JedisCluster getJedisCluster() {
    //解析字符串
    Set<HostAndPort> nodes = new HashSet<>();
    try {
        String[] cNodes = clusterNodes.split(",");
        for (String cNode : cNodes) {
            //192.168.123.1:7001
            String[] hp = cNode.split(":");
            nodes.add(new HostAndPort(hp[0], Integer.parseInt(hp[1])));

        }
        return new JedisCluster(nodes);
    } catch (ArrayIndexOutOfBoundsException | PatternSyntaxException | NullPointerException e) {
        e.printStackTrace();
    }
    return null;


}
 
开发者ID:mmdsyl,项目名称:BLOG-Microservice,代码行数:21,代码来源:RedisClusterConfig.java

示例6: init

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**
 * This method is called by PDI during transformation startup. 
 *
 * @param smi 	step meta interface implementation, containing the step settings
 * @param sdi	step data interface implementation, used to store runtime information
 * 
 * @return true if initialization completed successfully, false if there was an error preventing the step from working. 
 *  
 */
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
	// Casting to step-specific implementation classes is safe
	RedisOutputStepMeta meta = (RedisOutputStepMeta) smi;
	RedisOutputStepData data = (RedisOutputStepData) sdi;
       String url = environmentSubstitute(meta.getUrl());
       logBasic("creating redis session factory, addresses=" + url);
       if (url == null || url.isEmpty()) {
       	throw new IllegalArgumentException("redis cluster url set configured");
	}
	String[] redisNodes = url.split(",");
	Set<HostAndPort> jedisClusterNodes = new HashSet<>();
	try {
           for (String redisNode: redisNodes) {
               String[] config = redisNode.split(":");
               jedisClusterNodes.add(new HostAndPort(config[0], Integer.parseInt(config[1])));
           }
	} catch (IllegalArgumentException ex) {
		throw new IllegalArgumentException("redis cluster url not configured correctly");
	}
       client = new JedisCluster(jedisClusterNodes, REDIS_TIMEOUT, new GenericObjectPoolConfig());
	return super.init(meta, data);
}
 
开发者ID:DanielYWoo,项目名称:pentaho-di-redis-plugin,代码行数:32,代码来源:RedisOutputStep.java

示例7: getJedisCluster

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean
public JedisCluster getJedisCluster() {
    List<String> serverArray = redisProperties.getNodes();
    Set<HostAndPort> nodes = new HashSet<>();

    for (String ipPort : serverArray) {
        String[] ipPortPair = ipPort.split(":");
        nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
    }
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(500);
    config.setMaxIdle(1000 * 60);
    config.setMaxWaitMillis(1000 * 10);
    config.setTestOnBorrow(true);
    return new JedisCluster(nodes, config);
}
 
开发者ID:Evan1120,项目名称:springboot-sample,代码行数:17,代码来源:JedisClusterConfig.java

示例8: exist

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
private ScanPage exist(String cluster, ScanPage scanPage) throws Exception {
	scanPage.setHasMore(false);
	List<D_RedisClusterNode> nodes = clusterNodeService.getAllClusterNodes(cluster);
	Set<HostAndPort> masters = new HashSet<HostAndPort>();
	nodes.forEach(node->{
		masters.add(new HostAndPort(node.getHost(), node.getPort()));
	});
	JedisCluster jedis = new JedisCluster(masters);
	try {
		if(jedis.exists(scanPage.getQuery())){
			scanPage.setKeys(new HashSet<String>());
			scanPage.getKeys().add(scanPage.getQuery());
		}
	} finally {
		jedis.close();
	}
	return scanPage;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:19,代码来源:QueryService.java

示例9: testCluster

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**测试redis集群方案*/
@Test
public void testCluster(){

    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    //Jedis Cluster will attempt to discover cluster nodes automatically
    jedisClusterNodes.add(new HostAndPort("192.168.12.90", 7001));
    JedisCluster jc = new JedisCluster(jedisClusterNodes);
    jc.set("foo", "bar");
    String value = jc.get("foo");

    System.out.println(value);
    try {
        jc.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:19,代码来源:SpringRedis.java

示例10: getRedisCluster

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean
public JedisCluster getRedisCluster(){
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes1"), Integer.parseInt(environment.getProperty("redis.cluster.port1"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes2"), Integer.parseInt(environment.getProperty("redis.cluster.port2"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes3"), Integer.parseInt(environment.getProperty("redis.cluster.port3"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes4"), Integer.parseInt(environment.getProperty("redis.cluster.port4"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes5"), Integer.parseInt(environment.getProperty("redis.cluster.port5"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes6"), Integer.parseInt(environment.getProperty("redis.cluster.port6"))));
    JedisPoolConfig cfg = new JedisPoolConfig();
    cfg.setMaxTotal(Integer.parseInt(environment.getProperty("redis.cluster.config.max-total")));
    cfg.setMaxIdle(Integer.parseInt(environment.getProperty("redis.cluster.config.max-idle")));
    cfg.setMaxWaitMillis(Integer.parseInt(environment.getProperty("redis.cluster.config.max-waitmillis")));
    cfg.setTestOnBorrow(Boolean.parseBoolean(environment.getProperty("redis.cluster.config.onborrow"))); 
    JedisCluster jc = new JedisCluster(jedisClusterNode, Integer.parseInt(environment.getProperty("redis.cluster.timeout")), Integer.parseInt(environment.getProperty("redis.cluster.max-redirections")), cfg);
    return jc;
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:18,代码来源:ClusterConfig.java

示例11: RedisDelayQueue

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
public RedisDelayQueue(String redisKeyPrefix, String queueName, JedisCluster jedisCluster, int unackTime,
		DelayQueueProcessListener delayQueueProcessListener) {
	om = new ObjectMapper();
	om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
	om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
	om.setSerializationInclusion(Include.NON_NULL);
	om.setSerializationInclusion(Include.NON_EMPTY);
	om.disable(SerializationFeature.INDENT_OUTPUT);
	this.redisKeyPrefix = redisKeyPrefix;
	this.messageStoreKey = redisKeyPrefix + ".MESSAGE." + queueName;
	this.unackTime = unackTime;
	this.jedisCluster = jedisCluster;
	realQueueName = redisKeyPrefix + ".QUEUE." + queueName;
	this.delayQueueProcessListener = delayQueueProcessListener;
}
 
开发者ID:MeiPian,项目名称:delay-queue,代码行数:17,代码来源:RedisDelayQueue.java

示例12: stop

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Override
public boolean stop() {

    // 清除出集群集合
    JedisCluster removeRedisCluster = RedisCluster.removeCache(clusterName);

    // 关闭集群链接
    try {
        removeRedisCluster.close();
    } catch (IOException e) {
        logger.error(e.getMessage());
    }

    return false;

}
 
开发者ID:T-baby,项目名称:ICERest-plugin,代码行数:17,代码来源:RedisClusterPlugin.java

示例13: init

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@PostConstruct
public void init(){
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    String[] split = redisClusterConfig.getJedisClusterNodesIps().split(";");
    for(String one:split){
        String[] ipPort = one.split(":");
        jedisClusterNodes.add(new HostAndPort(ipPort[0], Integer.valueOf(ipPort[1])));
    }
    
    
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); 
    poolConfig.setMaxIdle(redisClusterConfig.getMaxIdle());
    poolConfig.setMaxTotal(redisClusterConfig.getMaxTotal());
    poolConfig.setMaxWaitMillis(redisClusterConfig.getMaxWaitMillis());
    // poolConfig.setMinIdle(minIdle);
    poolConfig.setTestOnBorrow(redisClusterConfig.isTestOnBorrow());
    poolConfig.setTestOnReturn(redisClusterConfig.isTestOnReturn());
    jc = new JedisCluster(jedisClusterNodes,60000,10,poolConfig);
}
 
开发者ID:cpusoft,项目名称:common,代码行数:20,代码来源:RedisClusterServiceImpl.java

示例14: setJedisPool

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
void setJedisPool() {
	final String clusters = this.redisConfig.getClusters();
	if (StringUtils.isBlank(clusters)) {
		throw new IllegalArgumentException("redis.clusters must not be blank");
	}

	final int connectionTimeout = this.redisConfig.getConnectionTimeout();
	final int soTimeout = this.redisConfig.getSoTimeout();
	final int maxRedirections = this.redisConfig.getMaxRedirections();

	Set<HostAndPort> nodes = new HashSet<HostAndPort>();
	for (String str : clusters.split("[,\\s\\t]+")) {
		final String[] arr = str.split(":");

		nodes.add(new HostAndPort(arr[0], Integer.parseInt(arr[1])));
	}

	this.jedisCluster = new JedisCluster(nodes, connectionTimeout, soTimeout, maxRedirections, this.poolConfig);
	if (logger.isInfoEnabled()) {
		logger.info("connect to Redis Cluster {}", clusters);
	}
}
 
开发者ID:5waynewang,项目名称:commons-jkit,代码行数:23,代码来源:JedisClusterFacade.java

示例15: test

import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void test() throws Exception {

    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    jedisClusterNodes.add(new HostAndPort(RedisConfig.DEFAULT_HOST, RedisConfig.DEFAULT_PORT));
    RedisClusterConnPool pool = new RedisClusterConnPool(jedisClusterNodes);

    JedisCluster cluster = pool.getConnection();
    Assert.assertNotNull(cluster);

    pool.returnConnection(cluster);
    pool.invalidateConnection(cluster);

    Properties properties = new Properties();
    properties.setProperty(RedisConfig.CLUSTER_PROPERTY, RedisConfig.DEFAULT_HOST + ":" + RedisConfig.DEFAULT_PORT);
    pool = new RedisClusterConnPool(properties);
    cluster = pool.getConnection();
    Assert.assertNotNull(cluster);

    pool.close();

    pool = new RedisClusterConnPool(new PoolConfig(), jedisClusterNodes);

    pool.close();

}
 
开发者ID:DarkPhoenixs,项目名称:connection-pool-client,代码行数:27,代码来源:RedisClusterConnPoolTest.java


注:本文中的redis.clients.jedis.JedisCluster类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。