首先可以参考github上jedis cluster相关部分的介绍:
Redis cluster specification (still under development) is implemented
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
//Jedis Cluster will attempt to discover cluster nodes automatically
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));
JedisCluster jc = new JedisCluster(jedisClusterNodes);
jc.set("foo", "bar");
String value = jc.get("foo");
Jedis客户端支持hash tag(关于hash tag可以参考redis官网手册),hash tag功能的实现和CRC16算法密切相关:
CRC16算法如下:
<span style="font-family:Microsoft YaHei;font-size:14px;">public class CRC16 {
public static int getCRC16(String key) {
int[] table = {
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00,