redis.clients.jedis.util.JedisClusterCRC16 Java Examples
The following examples show how to use
redis.clients.jedis.util.JedisClusterCRC16.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisSlotToHash.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public static String correlateRange(long start, long end) { Preconditions.checkState(start >= 0 && end < HASHSLOTS); long hashNumber = 0; int slotNumber = JedisClusterCRC16.getSlot(Long.toString(hashNumber)); while (slotNumber < start || slotNumber > end) { hashNumber++; slotNumber = JedisClusterCRC16.getSlot(Long.toString(hashNumber)); } return Long.toString(hashNumber); }
Example #2
Source File: RedisSlotToHashTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Test public void correlateCorrectForEverySlot() throws Exception { for (int i = 0; i < HASHSLOTS; ++i) { // convert to hashtag String hashtag = RedisSlotToHash.correlate(i); // convert hashtag back to slot int slotNumber = JedisClusterCRC16.getSlot(hashtag); // check correct correlation assertThat(i).isEqualTo(slotNumber); } }
Example #3
Source File: RedisSlotToHashTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Test public void correlateRangeCorrectHashtagFoundForSlotRange() throws Exception { // convert to hashtag String hashtag = RedisSlotToHash.correlateRange(100, 200); // convert hashtag back to slot int slotNumber = JedisClusterCRC16.getSlot(hashtag); // check correct correlation assertThat(slotNumber >= 100 && slotNumber <= 200).isTrue(); }
Example #4
Source File: JedisClusterPipeline.java From AutoLoadCache with Apache License 2.0 | 4 votes |
@Override protected Client getClient(byte[] key) { Client client = getClient(JedisClusterCRC16.getSlot(key)); clients.add(client); return client; }
Example #5
Source File: RedisUtil.java From RCT with Apache License 2.0 | 2 votes |
/** * 计算key所在slot * * @param key * @return */ public static int getSlotByKey(String key) { return JedisClusterCRC16.getSlot(key); }