Add support for redis cluster hashtags
This commit is contained in:
@@ -3,8 +3,20 @@ package redis.clients.util;
|
||||
public class JedisClusterCRC16 {
|
||||
public final static int polynomial = 0x1021; // Represents x^16+x^12+x^5+1
|
||||
static int crc;
|
||||
|
||||
|
||||
public static int getSlot(String key) {
|
||||
int s = key.indexOf("{");
|
||||
if (s > -1) {
|
||||
int e = key.indexOf("}", s+1);
|
||||
if (e > -1 && e != s+1) {
|
||||
key = key.substring(s+1, e);
|
||||
}
|
||||
}
|
||||
return getCRC16(key) % 16384;
|
||||
}
|
||||
|
||||
private static int getCRC16(String key) {
|
||||
crc = 0x0000;
|
||||
for (byte b : key.getBytes()) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
@@ -18,6 +30,6 @@ public class JedisClusterCRC16 {
|
||||
}
|
||||
}
|
||||
|
||||
return crc &= 0xffff % 16384;
|
||||
return crc &= 0xffff ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user