File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,7 +81,35 @@ uint16_t crc16(const char *buf, int len)
8181
8282unsigned int redisHash (redis_con * con , str * key )
8383{
84- return crc16 (key -> s ,key -> len ) & con -> slots_assigned ;
84+ int s , e ;
85+ char * k ;
86+ int klen ;
87+
88+ if (!key || !key -> s || key -> len <= 0 ) {
89+ LM_ERR ("redisHash called with invalid key\n" );
90+ return 0 ;
91+ }
92+
93+ k = key -> s ;
94+ klen = key -> len ;
95+
96+ /* Hash tag extraction per Redis cluster spec:
97+ * If key contains {substring}, hash only the substring */
98+ for (s = 0 ; s < klen ; s ++ )
99+ if (k [s ] == '{' ) break ;
100+
101+ if (s < klen ) {
102+ for (e = s + 1 ; e < klen ; e ++ )
103+ if (k [e ] == '}' ) break ;
104+
105+ if (e < klen && e != s + 1 ) {
106+ LM_DBG ("hash tag detected: hashing '%.*s' from key '%.*s'\n" ,
107+ e - s - 1 , k + s + 1 , klen , k );
108+ return crc16 (k + s + 1 , e - s - 1 ) & 16383 ;
109+ }
110+ }
111+
112+ return crc16 (k , klen ) & 16383 ;
85113}
86114
87115cluster_node * get_redis_connection (redis_con * con ,str * key )
You can’t perform that action at this time.
0 commit comments