Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
9fba05f7
Unverified
Commit
9fba05f7
authored
May 19, 2020
by
Salvatore Sanfilippo
Committed by
GitHub
May 19, 2020
Browse files
Merge pull request #7232 from trevor211/handleHashTagWhenComputingHashSlot
Tcl client support hash tagged keys.
parents
bf3a67be
70c4851f
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/cluster/tests/15-cluster-slots.tcl
View file @
9fba05f7
...
...
@@ -41,4 +41,10 @@ test "client do not break when cluster slot" {
if
{
[
catch
{
R 0 cluster slots
}]
}
{
fail
"output overflow when cluster slots"
}
}
\ No newline at end of file
}
test
"client can handle keys with hash tag"
{
set cluster
[
redis_cluster 127.0.0.1:
[
get_instance_attrib redis 0 port
]]
$cluster set foo
{
tag
}
bar
$cluster close
}
tests/support/cluster.tcl
View file @
9fba05f7
...
...
@@ -286,8 +286,29 @@ proc ::redis_cluster::crc16 {s} {
# Hash a single key returning the slot it belongs to, Implemented hash
# tags as described in the Redis Cluster specification.
proc ::redis_cluster::hash
{
key
}
{
# TODO: Handle hash slots.
expr
{[
::redis_cluster::crc16 $key
]
& 16383
}
set keylen
[
string length $key
]
set s
{}
set e
{}
for
{
set s 0
}
{
$s
< $keylen
}
{
incr s
}
{
if
{[
string index $key $s
]
eq
"
\{
"
}
break
}
if
{[
expr
{
$s
== $keylen
}]}
{
set res
[
expr
{[
crc16 $key
]
& 16383
}]
return $res
}
for
{
set e
[
expr
{
$s
+1
}]}
{
$e
< $keylen
}
{
incr e
}
{
if
{[
string index $key $e
]
==
"
\}
"
}
break
}
if
{
$e
== $keylen || $e ==
[
expr
{
$s
+1
}]}
{
set res
[
expr
{[
crc16 $key
]
& 16383
}]
return $res
}
set key_sub
[
string range $key
[
expr
{
$s
+1
}]
[
expr
{
$e-1
}]]
return
[
expr
{[
crc16 $key_sub
]
& 16383
}]
}
# Return the slot the specified keys hash to.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment