• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JedisClusterCRC16类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: run

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
public T run(int keyCount, String... keys) {
	if (keys == null || keys.length == 0) {
		throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
	}

	// For multiple keys, only execute if they all share the
	// same connection slot.
	if (keys.length > 1) {
		int slot = JedisClusterCRC16.getSlot(keys[0]);
		for (int i = 1; i < keyCount; i++) {
			int nextSlot = JedisClusterCRC16.getSlot(keys[i]);
			if (slot != nextSlot) {
				throw new JedisClusterException(
						"No way to dispatch this command to Redis Cluster " + "because keys have different slots.");
			}
		}
	}

	return runWithRetries(SafeEncoder.encode(keys[0]), this.maxAttempts, false, false);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:JedisClusterCommand.java


示例2: runBinary

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
public T runBinary(int keyCount, byte[]... keys) {
	if (keys == null || keys.length == 0) {
		throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
	}

	// For multiple keys, only execute if they all share the
	// same connection slot.
	if (keys.length > 1) {
		int slot = JedisClusterCRC16.getSlot(keys[0]);
		for (int i = 1; i < keyCount; i++) {
			int nextSlot = JedisClusterCRC16.getSlot(keys[i]);
			if (slot != nextSlot) {
				throw new JedisClusterException(
						"No way to dispatch this command to Redis Cluster " + "because keys have different slots.");
			}
		}
	}

	return runWithRetries(keys[0], this.maxAttempts, false, false);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:JedisClusterCommand.java


示例3: testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified

import redis.clients.util.JedisClusterCRC16; //导入依赖的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


示例4: getPoolKeyMap

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
private Map<JedisPool, List<String>> getPoolKeyMap(List<String> keys) {
    Map<JedisPool, List<String>> poolKeysMap = new LinkedHashMap<JedisPool, List<String>>();
    try {
        for (String key : keys) {
            JedisPool jedisPool;
            int slot = JedisClusterCRC16.getSlot(key);
            jedisPool = connectionHandler.getJedisPoolFromSlot(slot);
            if (poolKeysMap.containsKey(jedisPool)) {
                poolKeysMap.get(jedisPool).add(key);
            } else {
                List<String> subKeyList = new ArrayList<String>();
                subKeyList.add(key);
                poolKeysMap.put(jedisPool, subKeyList);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return poolKeysMap;
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:PipelineClusterCommand.java


示例5: run

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
public T run(int keyCount, String... keys) {
  if (keys == null || keys.length == 0) {
    throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
  }

  // For multiple keys, only execute if they all share the
  // same connection slot.
  if (keys.length > 1) {
    int slot = JedisClusterCRC16.getSlot(keys[0]);
    for (int i = 1; i < keyCount; i++) {
      int nextSlot = JedisClusterCRC16.getSlot(keys[i]);
      if (slot != nextSlot) {
        throw new JedisClusterException("No way to dispatch this command to Redis Cluster "
            + "because keys have different slots.");
      }
    }
  }

  return runWithRetries(SafeEncoder.encode(keys[0]), this.redirections, false, false);
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:JedisClusterCommand.java


示例6: runBinary

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
public T runBinary(int keyCount, byte[]... keys) {
  if (keys == null || keys.length == 0) {
    throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
  }

  // For multiple keys, only execute if they all share the
  // same connection slot.
  if (keys.length > 1) {
    int slot = JedisClusterCRC16.getSlot(keys[0]);
    for (int i = 1; i < keyCount; i++) {
      int nextSlot = JedisClusterCRC16.getSlot(keys[i]);
      if (slot != nextSlot) {
        throw new JedisClusterException("No way to dispatch this command to Redis Cluster "
            + "because keys have different slots.");
      }
    }
  }

  return runWithRetries(keys[0], this.redirections, false, false);
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:JedisClusterCommand.java


示例7: testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified

import redis.clients.util.JedisClusterCRC16; //导入依赖的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);

  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:sohutv,项目名称:cachecloud,代码行数:22,代码来源:JedisClusterTest.java


示例8: cleanUp

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@AfterClass
public static void cleanUp() {
  int slotTest = JedisClusterCRC16.getSlot("test");
  int slot51 = JedisClusterCRC16.getSlot("51");
  String node3Id = getNodeId(node3.clusterNodes());
  node2.clusterSetSlotNode(slotTest, node3Id);
  node2.clusterSetSlotNode(slot51, node3Id);
  node2.clusterDelSlots(slotTest, slot51);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:ClusterScriptingCommandsTest.java


示例9: testGetSlot

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testGetSlot() {
  assertEquals(JedisClusterCRC16.getSlot("{bar".getBytes()), JedisClusterCRC16.getSlot("{bar"));
  assertEquals(JedisClusterCRC16.getSlot("{user1000}.following".getBytes()),
    JedisClusterCRC16.getSlot("{user1000}.followers".getBytes()));
  assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}".getBytes()),
    JedisClusterCRC16.getSlot("bar".getBytes()));
  assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}".getBytes()),
    JedisClusterCRC16.getSlot("bar".getBytes()));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:11,代码来源:ClusterBinaryJedisCommandsTest.java


示例10: main

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
public static void main(String[] args) {
  long begin = Calendar.getInstance().getTimeInMillis();

  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    JedisClusterCRC16.getSlot(TEST_SET[n % TEST_SET.length]);
  }

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:CRC16Benchmark.java


示例11: testGetCRC16

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testGetCRC16() throws Exception {
  Map<String, Integer> solutions = prepareSolutionSet();

  for (Entry<String, Integer> entry : solutions.entrySet()) {
    // string version
    assertEquals(entry.getValue().intValue(), JedisClusterCRC16.getCRC16(entry.getKey()));

    // byte array version
    assertEquals(entry.getValue().intValue(),
      JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry.getKey())));
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:14,代码来源:JedisClusterCRC16Test.java


示例12: testThrowAskException

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test(expected = JedisAskDataException.class)
public void testThrowAskException() {
  int keySlot = JedisClusterCRC16.getSlot("test");
  String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes());
  node2.clusterSetSlotMigrating(keySlot, node3Id);
  node2.get("test");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:8,代码来源:JedisClusterTest.java


示例13: testRecalculateSlotsWhenMoved

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testRecalculateSlotsWhenMoved() throws InterruptedException {
  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);
  int slot51 = JedisClusterCRC16.getSlot("51");
  node2.clusterDelSlots(slot51);
  node3.clusterDelSlots(slot51);
  node3.clusterAddSlots(slot51);

  JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
  jc.set("51", "foo");
  assertEquals("foo", jc.get("51"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:15,代码来源:JedisClusterTest.java


示例14: testAskResponse

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testAskResponse() throws InterruptedException {
  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);
  int slot51 = JedisClusterCRC16.getSlot("51");
  node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  jc.set("51", "foo");
  assertEquals("foo", jc.get("51"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JedisClusterTest.java


示例15: testRedisClusterMaxRedirections

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test(expected = JedisClusterMaxRedirectionsException.class)
public void testRedisClusterMaxRedirections() {
  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);
  int slot51 = JedisClusterCRC16.getSlot("51");
  // This will cause an infinite redirection loop
  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  jc.set("51", "foo");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:11,代码来源:JedisClusterTest.java


示例16: testRedisHashtag

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testRedisHashtag() {
  assertEquals(JedisClusterCRC16.getSlot("{bar"), JedisClusterCRC16.getSlot("foo{{bar}}zap"));
  assertEquals(JedisClusterCRC16.getSlot("{user1000}.following"),
    JedisClusterCRC16.getSlot("{user1000}.followers"));
  assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}"), JedisClusterCRC16.getSlot("bar"));
  assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"), JedisClusterCRC16.getSlot("bar"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:9,代码来源:JedisClusterTest.java


示例17: testClusterKeySlot

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testClusterKeySlot() {
  // It assumes JedisClusterCRC16 is correctly implemented
  assertEquals(node1.clusterKeySlot("foo{bar}zap}").intValue(),
    JedisClusterCRC16.getSlot("foo{bar}zap"));
  assertEquals(node1.clusterKeySlot("{user1000}.following").intValue(),
    JedisClusterCRC16.getSlot("{user1000}.following"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:9,代码来源:JedisClusterTest.java


示例18: testClusterCountKeysInSlot

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testClusterCountKeysInSlot() {
  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);

  for (int index = 0; index < 5; index++) {
    jc.set("foo{bar}" + index, "hello");
  }

  int slot = JedisClusterCRC16.getSlot("foo{bar}");
  assertEquals(DEFAULT_REDIRECTIONS, node1.clusterCountKeysInSlot(slot).intValue());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:14,代码来源:JedisClusterTest.java


示例19: rename

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Override
public String rename(byte[] oldkey, byte[] newkey) {
  int slot = JedisClusterCRC16.getSlot(oldkey);
  int newSlot = JedisClusterCRC16.getSlot(newkey);
  // If slots are not same we need to apply move logic (get, set, delete).
  if (slot != newSlot) {
    return renameToDifferentSlots(oldkey, newkey);
  }
  return jedisCluster.rename(oldkey, newkey);
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:11,代码来源:JedisClusterFacade.java


示例20: testRecalculateSlotsWhenMoved

import redis.clients.util.JedisClusterCRC16; //导入依赖的package包/类
@Test
public void testRecalculateSlotsWhenMoved() throws InterruptedException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode);
  int slot51 = JedisClusterCRC16.getSlot("51");
  node2.clusterDelSlots(slot51);
  node3.clusterDelSlots(slot51);
  node3.clusterAddSlots(slot51);

  JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
  jc.set("51", "foo");
  assertEquals("foo", jc.get("51"));
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:15,代码来源:JedisClusterTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClusterSession类代码示例发布时间:2022-05-22
下一篇:
Java ByeEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap