Rename remaining test procedures (#355)

Renamed below procedures and variables (missed in #287) as follows.

redis_cluster             ->     valkey_cluster
redis1                    ->     valkey1
redis2                    ->     valkey2
get_redis_dir             ->     get_valkey_dir
test_redis_cli_rdb_dump   ->     test_valkey_cli_rdb_dump
test_redis_cli_repl       ->     test_valkey_cli_repl
redis-cli                 ->     valkey-cli
redis_reset_state         ->     valkey_reset_state
redisHandle               ->     valkeyHandle
redis_safe_read           ->     valkey_safe_read
redis_safe_gets           ->     valkey_safe_gets
redis_write               ->     valkey_write
redis_read_reply          ->     valkey_read_reply
redis_readable            ->     valkey_readable
redis_readnl              ->     valkey_readnl
redis_writenl             ->     valkey_writenl
redis_read_map            ->     valkey_read_map
redis_read_line           ->     valkey_read_line
redis_read_null           ->     valkey_read_null
redis_read_bool           ->     valkey_read_bool
redis_read_double         ->     valkey_read_double
redis_read_verbatim_str   ->     valkey_read_verbatim_str
redis_call_callback       ->     valkey_call_callback

---------

Signed-off-by: Shivshankar-Reddy <shiva.sheri.github@gmail.com>
This commit is contained in:
Shivshankar 2024-04-24 12:01:33 -04:00 committed by GitHub
parent d09a59c3b1
commit 8baf322742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 188 additions and 188 deletions

View File

@ -171,7 +171,7 @@ proc set_cluster_node_timeout {to} {
proc cluster_write_test {id} { proc cluster_write_test {id} {
set prefix [randstring 20 20 alpha] set prefix [randstring 20 20 alpha]
set port [get_instance_attrib valkey $id port] set port [get_instance_attrib valkey $id port]
set cluster [redis_cluster 127.0.0.1:$port] set cluster [valkey_cluster 127.0.0.1:$port]
for {set j 0} {$j < 100} {incr j} { for {set j 0} {$j < 100} {incr j} {
$cluster set key.$j $prefix.$j $cluster set key.$j $prefix.$j
} }

View File

@ -14,7 +14,7 @@ test "Cluster is up" {
} }
set iterations 20 set iterations 20
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
while {[incr iterations -1]} { while {[incr iterations -1]} {
set tokill [randomInt 10] set tokill [randomInt 10]

View File

@ -55,11 +55,11 @@ proc process_is_running {pid} {
set numkeys 50000 set numkeys 50000
set numops 200000 set numops 200000
set start_node_port [get_instance_attrib valkey 0 port] set start_node_port [get_instance_attrib valkey 0 port]
set cluster [redis_cluster 127.0.0.1:$start_node_port] set cluster [valkey_cluster 127.0.0.1:$start_node_port]
if {$::tls} { if {$::tls} {
# setup a non-TLS cluster client to the TLS cluster # setup a non-TLS cluster client to the TLS cluster
set plaintext_port [get_instance_attrib valkey 0 plaintext-port] set plaintext_port [get_instance_attrib valkey 0 plaintext-port]
set cluster_plaintext [redis_cluster 127.0.0.1:$plaintext_port 0] set cluster_plaintext [valkey_cluster 127.0.0.1:$plaintext_port 0]
puts "Testing TLS cluster on start node 127.0.0.1:$start_node_port, plaintext port $plaintext_port" puts "Testing TLS cluster on start node 127.0.0.1:$start_node_port, plaintext port $plaintext_port"
} else { } else {
set cluster_plaintext $cluster set cluster_plaintext $cluster

View File

@ -48,7 +48,7 @@ test "Instance #5 and #10 synced with the master" {
} }
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
test "Slaves are both able to receive and acknowledge writes" { test "Slaves are both able to receive and acknowledge writes" {
for {set j 0} {$j < 100} {incr j} { for {set j 0} {$j < 100} {incr j} {

View File

@ -30,7 +30,7 @@ set current_epoch [CI 1 cluster_current_epoch]
set numkeys 50000 set numkeys 50000
set numops 10000 set numops 10000
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
catch {unset content} catch {unset content}
array set content {} array set content {}

View File

@ -38,7 +38,7 @@ proc get_one_of_my_replica {id} {
proc cluster_write_keys_with_expire {id ttl} { proc cluster_write_keys_with_expire {id ttl} {
set prefix [randstring 20 20 alpha] set prefix [randstring 20 20 alpha]
set port [get_instance_attrib valkey $id port] set port [get_instance_attrib valkey $id port]
set cluster [redis_cluster 127.0.0.1:$port] set cluster [valkey_cluster 127.0.0.1:$port]
for {set j 100} {$j < 200} {incr j} { for {set j 100} {$j < 200} {incr j} {
$cluster setex key_expire.$j $ttl $prefix.$j $cluster setex key_expire.$j $ttl $prefix.$j
} }

View File

@ -44,13 +44,13 @@ test "client do not break when cluster slot" {
} }
test "client can handle keys with hash tag" { test "client can handle keys with hash tag" {
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
$cluster set foo{tag} bar $cluster set foo{tag} bar
$cluster close $cluster close
} }
test "slot migration is valid from primary to another primary" { test "slot migration is valid from primary to another primary" {
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
set key order1 set key order1
set slot [$cluster cluster keyslot $key] set slot [$cluster cluster keyslot $key]
array set nodefrom [$cluster masternode_for_slot $slot] array set nodefrom [$cluster masternode_for_slot $slot]
@ -61,7 +61,7 @@ test "slot migration is valid from primary to another primary" {
} }
test "slot migration is invalid from primary to replica" { test "slot migration is invalid from primary to replica" {
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
set key order1 set key order1
set slot [$cluster cluster keyslot $key] set slot [$cluster cluster keyslot $key]
array set nodefrom [$cluster masternode_for_slot $slot] array set nodefrom [$cluster masternode_for_slot $slot]

View File

@ -21,7 +21,7 @@ test "Cluster is up" {
assert_cluster_state ok assert_cluster_state ok
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
catch {unset nodefrom} catch {unset nodefrom}
catch {unset nodeto} catch {unset nodeto}

View File

@ -21,7 +21,7 @@ test "Cluster is up" {
assert_cluster_state ok assert_cluster_state ok
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
catch {unset nodefrom} catch {unset nodefrom}
catch {unset nodeto} catch {unset nodeto}

View File

@ -8,10 +8,10 @@ test "Cluster is up" {
assert_cluster_state ok assert_cluster_state ok
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
proc get_addr_replica_serving_slot slot { proc get_addr_replica_serving_slot slot {
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
array set node [$cluster masternode_for_slot $slot] array set node [$cluster masternode_for_slot $slot]
set replicanodeinfo [$cluster cluster replicas $node(id)] set replicanodeinfo [$cluster cluster replicas $node(id)]

View File

@ -6,7 +6,7 @@ test "Create a 3 nodes cluster" {
cluster_create_with_continuous_slots 3 3 cluster_create_with_continuous_slots 3 3
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
test "Pub/Sub shard basics" { test "Pub/Sub shard basics" {
set slot [$cluster cluster keyslot "channel.0"] set slot [$cluster cluster keyslot "channel.0"]

View File

@ -12,7 +12,7 @@ test "Cluster is up" {
assert_cluster_state ok assert_cluster_state ok
} }
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]]
catch {unset nodefrom} catch {unset nodefrom}
catch {unset nodeto} catch {unset nodeto}

View File

@ -11,7 +11,7 @@ proc fix_cluster {addr} {
exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster fix $addr << yes exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster fix $addr << yes
} result] } result]
if {$code != 0} { if {$code != 0} {
puts "redis-cli --cluster fix returns non-zero exit code, output below:\n$result" puts "valkey-cli --cluster fix returns non-zero exit code, output below:\n$result"
} }
# Note: valkey-cli --cluster fix may return a non-zero exit code if nodes don't agree, # Note: valkey-cli --cluster fix may return a non-zero exit code if nodes don't agree,
# but we can ignore that and rely on the check below. # but we can ignore that and rely on the check below.
@ -19,7 +19,7 @@ proc fix_cluster {addr} {
wait_for_condition 100 100 { wait_for_condition 100 100 {
[catch {exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster check $addr} result] == 0 [catch {exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster check $addr} result] == 0
} else { } else {
puts "redis-cli --cluster check returns non-zero exit code, output below:\n$result" puts "valkey-cli --cluster check returns non-zero exit code, output below:\n$result"
fail "Cluster could not settle with configuration" fail "Cluster could not settle with configuration"
} }
} }

View File

@ -604,71 +604,71 @@ tags {"external:skip"} {
} }
start_server_aof [list dir $server_path] { start_server_aof [list dir $server_path] {
set redis1 [valkey [srv host] [srv port] 0 $::tls] set valkey1 [valkey [srv host] [srv port] 0 $::tls]
start_server [list overrides [list dir $server_path appendonly yes appendfilename appendonly.aof2]] { start_server [list overrides [list dir $server_path appendonly yes appendfilename appendonly.aof2]] {
set redis2 [valkey [srv host] [srv port] 0 $::tls] set valkey2 [valkey [srv host] [srv port] 0 $::tls]
test "Multi Part AOF can upgrade when when two servers share the same server dir (server1)" { test "Multi Part AOF can upgrade when when two servers share the same server dir (server1)" {
wait_done_loading $redis1 wait_done_loading $valkey1
assert_equal v1 [$redis1 get k1] assert_equal v1 [$valkey1 get k1]
assert_equal v2 [$redis1 get k2] assert_equal v2 [$valkey1 get k2]
assert_equal v3 [$redis1 get k3] assert_equal v3 [$valkey1 get k3]
assert_equal 0 [$redis1 exists k4] assert_equal 0 [$valkey1 exists k4]
assert_equal 0 [$redis1 exists k5] assert_equal 0 [$valkey1 exists k5]
assert_equal 0 [$redis1 exists k6] assert_equal 0 [$valkey1 exists k6]
assert_aof_manifest_content $aof_manifest_file { assert_aof_manifest_content $aof_manifest_file {
{file appendonly.aof seq 1 type b} {file appendonly.aof seq 1 type b}
{file appendonly.aof.1.incr.aof seq 1 type i} {file appendonly.aof.1.incr.aof seq 1 type i}
} }
$redis1 bgrewriteaof $valkey1 bgrewriteaof
waitForBgrewriteaof $redis1 waitForBgrewriteaof $valkey1
assert_equal OK [$redis1 set k v] assert_equal OK [$valkey1 set k v]
assert_aof_manifest_content $aof_manifest_file { assert_aof_manifest_content $aof_manifest_file {
{file appendonly.aof.2.base.rdb seq 2 type b} {file appendonly.aof.2.base.rdb seq 2 type b}
{file appendonly.aof.2.incr.aof seq 2 type i} {file appendonly.aof.2.incr.aof seq 2 type i}
} }
set d1 [$redis1 debug digest] set d1 [$valkey1 debug digest]
$redis1 debug loadaof $valkey1 debug loadaof
set d2 [$redis1 debug digest] set d2 [$valkey1 debug digest]
assert {$d1 eq $d2} assert {$d1 eq $d2}
} }
test "Multi Part AOF can upgrade when when two servers share the same server dir (server2)" { test "Multi Part AOF can upgrade when when two servers share the same server dir (server2)" {
wait_done_loading $redis2 wait_done_loading $valkey2
assert_equal 0 [$redis2 exists k1] assert_equal 0 [$valkey2 exists k1]
assert_equal 0 [$redis2 exists k2] assert_equal 0 [$valkey2 exists k2]
assert_equal 0 [$redis2 exists k3] assert_equal 0 [$valkey2 exists k3]
assert_equal v4 [$redis2 get k4] assert_equal v4 [$valkey2 get k4]
assert_equal v5 [$redis2 get k5] assert_equal v5 [$valkey2 get k5]
assert_equal v6 [$redis2 get k6] assert_equal v6 [$valkey2 get k6]
assert_aof_manifest_content $aof_manifest_file2 { assert_aof_manifest_content $aof_manifest_file2 {
{file appendonly.aof2 seq 1 type b} {file appendonly.aof2 seq 1 type b}
{file appendonly.aof2.1.incr.aof seq 1 type i} {file appendonly.aof2.1.incr.aof seq 1 type i}
} }
$redis2 bgrewriteaof $valkey2 bgrewriteaof
waitForBgrewriteaof $redis2 waitForBgrewriteaof $valkey2
assert_equal OK [$redis2 set k v] assert_equal OK [$valkey2 set k v]
assert_aof_manifest_content $aof_manifest_file2 { assert_aof_manifest_content $aof_manifest_file2 {
{file appendonly.aof2.2.base.rdb seq 2 type b} {file appendonly.aof2.2.base.rdb seq 2 type b}
{file appendonly.aof2.2.incr.aof seq 2 type i} {file appendonly.aof2.2.incr.aof seq 2 type i}
} }
set d1 [$redis2 debug digest] set d1 [$valkey2 debug digest]
$redis2 debug loadaof $valkey2 debug loadaof
set d2 [$redis2 debug digest] set d2 [$valkey2 debug digest]
assert {$d1 eq $d2} assert {$d1 eq $d2}
} }
} }
@ -677,7 +677,7 @@ tags {"external:skip"} {
test {Multi Part AOF can handle appendfilename contains whitespaces} { test {Multi Part AOF can handle appendfilename contains whitespaces} {
start_server [list overrides [list appendonly yes appendfilename "\" file seq \\n\\n.aof \""]] { start_server [list overrides [list appendonly yes appendfilename "\" file seq \\n\\n.aof \""]] {
set dir [get_redis_dir] set dir [get_valkey_dir]
set aof_manifest_name [format "%s/%s/%s%s" $dir "appendonlydir" " file seq \n\n.aof " $::manifest_suffix] set aof_manifest_name [format "%s/%s/%s%s" $dir "appendonlydir" " file seq \n\n.aof " $::manifest_suffix]
set valkey [valkey [srv host] [srv port] 0 $::tls] set valkey [valkey [srv host] [srv port] 0 $::tls]
@ -756,7 +756,7 @@ tags {"external:skip"} {
start_server {tags {"Multi Part AOF"} overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} { start_server {tags {"Multi Part AOF"} overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} {
set dir [get_redis_dir] set dir [get_valkey_dir]
set aof_basename "appendonly.aof" set aof_basename "appendonly.aof"
set aof_dirname "appendonlydir" set aof_dirname "appendonlydir"
set aof_dirpath "$dir/$aof_dirname" set aof_dirpath "$dir/$aof_dirname"
@ -1174,7 +1174,7 @@ tags {"external:skip"} {
} }
start_server {overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} { start_server {overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} {
set dir [get_redis_dir] set dir [get_valkey_dir]
set aof_basename "appendonly.aof" set aof_basename "appendonly.aof"
set aof_dirname "appendonlydir" set aof_dirname "appendonlydir"
set aof_dirpath "$dir/$aof_dirname" set aof_dirpath "$dir/$aof_dirname"

View File

@ -444,7 +444,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
r acl deluser clitest r acl deluser clitest
} }
proc test_redis_cli_rdb_dump {functions_only} { proc test_valkey_cli_rdb_dump {functions_only} {
r flushdb r flushdb
r function flush r function flush
@ -480,12 +480,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
test "Dumping an RDB - functions only: $functions_only" { test "Dumping an RDB - functions only: $functions_only" {
# Disk-based master # Disk-based master
assert_match "OK" [r config set repl-diskless-sync no] assert_match "OK" [r config set repl-diskless-sync no]
test_redis_cli_rdb_dump $functions_only test_valkey_cli_rdb_dump $functions_only
# Disk-less master # Disk-less master
assert_match "OK" [r config set repl-diskless-sync yes] assert_match "OK" [r config set repl-diskless-sync yes]
assert_match "OK" [r config set repl-diskless-sync-delay 0] assert_match "OK" [r config set repl-diskless-sync-delay 0]
test_redis_cli_rdb_dump $functions_only test_valkey_cli_rdb_dump $functions_only
} {} {needs:repl needs:debug} } {} {needs:repl needs:debug}
} ;# foreach functions_only } ;# foreach functions_only
@ -504,12 +504,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
assert_equal {key:2} [run_cli --scan --quoted-pattern {"*:\x32"}] assert_equal {key:2} [run_cli --scan --quoted-pattern {"*:\x32"}]
} }
proc test_redis_cli_repl {} { proc test_valkey_cli_repl {} {
set fd [open_cli "--replica"] set fd [open_cli "--replica"]
wait_for_condition 500 100 { wait_for_condition 500 100 {
[string match {*slave0:*state=online*} [r info]] [string match {*slave0:*state=online*} [r info]]
} else { } else {
fail "redis-cli --replica did not connect" fail "valkey-cli --replica did not connect"
} }
for {set i 0} {$i < 100} {incr i} { for {set i 0} {$i < 100} {incr i} {
@ -519,7 +519,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
wait_for_condition 500 100 { wait_for_condition 500 100 {
[string match {*test-value-99*} [read_cli $fd]] [string match {*test-value-99*} [read_cli $fd]]
} else { } else {
fail "redis-cli --replica didn't read commands" fail "valkey-cli --replica didn't read commands"
} }
fconfigure $fd -blocking true fconfigure $fd -blocking true
@ -531,12 +531,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
test "Connecting as a replica" { test "Connecting as a replica" {
# Disk-based master # Disk-based master
assert_match "OK" [r config set repl-diskless-sync no] assert_match "OK" [r config set repl-diskless-sync no]
test_redis_cli_repl test_valkey_cli_repl
# Disk-less master # Disk-less master
assert_match "OK" [r config set repl-diskless-sync yes] assert_match "OK" [r config set repl-diskless-sync yes]
assert_match "OK" [r config set repl-diskless-sync-delay 0] assert_match "OK" [r config set repl-diskless-sync-delay 0]
test_redis_cli_repl test_valkey_cli_repl
} {} {needs:repl} } {} {needs:repl}
test "Piping raw protocol" { test "Piping raw protocol" {

View File

@ -12,7 +12,7 @@ proc join_path {dir1 dir2} {
return [format "%s/%s" $dir1 $dir2] return [format "%s/%s" $dir1 $dir2]
} }
proc get_redis_dir {} { proc get_valkey_dir {} {
set config [srv config] set config [srv config]
set _ [dict get $config "dir"] set _ [dict get $config "dir"]
} }

View File

@ -4,25 +4,25 @@
# #
# Example usage: # Example usage:
# #
# set c [redis_cluster {127.0.0.1:6379 127.0.0.1:6380}] # set c [valkey_cluster {127.0.0.1:6379 127.0.0.1:6380}]
# $c set foo # $c set foo
# $c get foo # $c get foo
# $c close # $c close
package require Tcl 8.5 package require Tcl 8.5
package provide redis_cluster 0.1 package provide valkey_cluster 0.1
namespace eval redis_cluster {} namespace eval valkey_cluster {}
set ::redis_cluster::internal_id 0 set ::valkey_cluster::internal_id 0
set ::redis_cluster::id 0 set ::valkey_cluster::id 0
array set ::redis_cluster::startup_nodes {} array set ::valkey_cluster::startup_nodes {}
array set ::redis_cluster::nodes {} array set ::valkey_cluster::nodes {}
array set ::redis_cluster::slots {} array set ::valkey_cluster::slots {}
array set ::redis_cluster::tls {} array set ::valkey_cluster::tls {}
# List of "plain" commands, which are commands where the sole key is always # List of "plain" commands, which are commands where the sole key is always
# the first argument. # the first argument.
set ::redis_cluster::plain_commands { set ::valkey_cluster::plain_commands {
get set setnx setex psetex append strlen exists setbit getbit get set setnx setex psetex append strlen exists setbit getbit
setrange getrange substr incr decr rpush lpush rpushx lpushx setrange getrange substr incr decr rpush lpush rpushx lpushx
linsert rpop lpop brpop llen lindex lset lrange ltrim lrem linsert rpop lpop brpop llen lindex lset lrange ltrim lrem
@ -39,34 +39,34 @@ set ::redis_cluster::plain_commands {
# Create a cluster client. The nodes are given as a list of host:port. The TLS # Create a cluster client. The nodes are given as a list of host:port. The TLS
# parameter (1 or 0) is optional and defaults to the global $::tls. # parameter (1 or 0) is optional and defaults to the global $::tls.
proc redis_cluster {nodes {tls -1}} { proc valkey_cluster {nodes {tls -1}} {
set id [incr ::redis_cluster::id] set id [incr ::valkey_cluster::id]
set ::redis_cluster::startup_nodes($id) $nodes set ::valkey_cluster::startup_nodes($id) $nodes
set ::redis_cluster::nodes($id) {} set ::valkey_cluster::nodes($id) {}
set ::redis_cluster::slots($id) {} set ::valkey_cluster::slots($id) {}
set ::redis_cluster::tls($id) [expr $tls == -1 ? $::tls : $tls] set ::valkey_cluster::tls($id) [expr $tls == -1 ? $::tls : $tls]
set handle [interp alias {} ::redis_cluster::instance$id {} ::redis_cluster::__dispatch__ $id] set handle [interp alias {} ::valkey_cluster::instance$id {} ::valkey_cluster::__dispatch__ $id]
$handle refresh_nodes_map $handle refresh_nodes_map
return $handle return $handle
} }
# Totally reset the slots / nodes state for the client, calls # Totally reset the slots / nodes state for the client, calls
# CLUSTER NODES in the first startup node available, populates the # CLUSTER NODES in the first startup node available, populates the
# list of nodes ::redis_cluster::nodes($id) with an hash mapping node # list of nodes ::valkey_cluster::nodes($id) with an hash mapping node
# ip:port to a representation of the node (another hash), and finally # ip:port to a representation of the node (another hash), and finally
# maps ::redis_cluster::slots($id) with an hash mapping slot numbers # maps ::valkey_cluster::slots($id) with an hash mapping slot numbers
# to node IDs. # to node IDs.
# #
# This function is called when a new Cluster client is initialized # This function is called when a new Cluster client is initialized
# and every time we get a -MOVED redirection error. # and every time we get a -MOVED redirection error.
proc ::redis_cluster::__method__refresh_nodes_map {id} { proc ::valkey_cluster::__method__refresh_nodes_map {id} {
# Contact the first responding startup node. # Contact the first responding startup node.
set idx 0; # Index of the node that will respond. set idx 0; # Index of the node that will respond.
set errmsg {} set errmsg {}
foreach start_node $::redis_cluster::startup_nodes($id) { foreach start_node $::valkey_cluster::startup_nodes($id) {
set ip_port [lindex [split $start_node @] 0] set ip_port [lindex [split $start_node @] 0]
lassign [split $ip_port :] start_host start_port lassign [split $ip_port :] start_host start_port
set tls $::redis_cluster::tls($id) set tls $::valkey_cluster::tls($id)
if {[catch { if {[catch {
set r {} set r {}
set r [valkey $start_host $start_port 0 $tls] set r [valkey $start_host $start_port 0 $tls]
@ -84,18 +84,18 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
} }
} }
if {$idx == [llength $::redis_cluster::startup_nodes($id)]} { if {$idx == [llength $::valkey_cluster::startup_nodes($id)]} {
error "No good startup node found. $errmsg" error "No good startup node found. $errmsg"
} }
# Put the node that responded as first in the list if it is not # Put the node that responded as first in the list if it is not
# already the first. # already the first.
if {$idx != 0} { if {$idx != 0} {
set l $::redis_cluster::startup_nodes($id) set l $::valkey_cluster::startup_nodes($id)
set left [lrange $l 0 [expr {$idx-1}]] set left [lrange $l 0 [expr {$idx-1}]]
set right [lrange $l [expr {$idx+1}] end] set right [lrange $l [expr {$idx+1}] end]
set l [concat [lindex $l $idx] $left $right] set l [concat [lindex $l $idx] $left $right]
set ::redis_cluster::startup_nodes($id) $l set ::valkey_cluster::startup_nodes($id) $l
} }
# Parse CLUSTER NODES output to populate the nodes description. # Parse CLUSTER NODES output to populate the nodes description.
@ -114,7 +114,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
# Connect to the node # Connect to the node
set link {} set link {}
set tls $::redis_cluster::tls($id) set tls $::valkey_cluster::tls($id)
catch {set link [valkey $host $port 0 $tls]} catch {set link [valkey $host $port 0 $tls]}
# Build this node description as an hash. # Build this node description as an hash.
@ -130,17 +130,17 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
link $link \ link $link \
] ]
dict set nodes $addr $node dict set nodes $addr $node
lappend ::redis_cluster::startup_nodes($id) $addr lappend ::valkey_cluster::startup_nodes($id) $addr
} }
# Close all the existing links in the old nodes map, and set the new # Close all the existing links in the old nodes map, and set the new
# map as current. # map as current.
foreach n $::redis_cluster::nodes($id) { foreach n $::valkey_cluster::nodes($id) {
catch { catch {
[dict get $n link] close [dict get $n link] close
} }
} }
set ::redis_cluster::nodes($id) $nodes set ::valkey_cluster::nodes($id) $nodes
# Populates the slots -> nodes map. # Populates the slots -> nodes map.
dict for {addr node} $nodes { dict for {addr node} $nodes {
@ -148,47 +148,47 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
lassign [split $slotrange -] start end lassign [split $slotrange -] start end
if {$end == {}} {set end $start} if {$end == {}} {set end $start}
for {set j $start} {$j <= $end} {incr j} { for {set j $start} {$j <= $end} {incr j} {
dict set ::redis_cluster::slots($id) $j $addr dict set ::valkey_cluster::slots($id) $j $addr
} }
} }
} }
# Only retain unique entries in the startup nodes list # Only retain unique entries in the startup nodes list
set ::redis_cluster::startup_nodes($id) [lsort -unique $::redis_cluster::startup_nodes($id)] set ::valkey_cluster::startup_nodes($id) [lsort -unique $::valkey_cluster::startup_nodes($id)]
} }
# Free a redis_cluster handle. # Free a valkey_cluster handle.
proc ::redis_cluster::__method__close {id} { proc ::valkey_cluster::__method__close {id} {
catch { catch {
set nodes $::redis_cluster::nodes($id) set nodes $::valkey_cluster::nodes($id)
dict for {addr node} $nodes { dict for {addr node} $nodes {
catch { catch {
[dict get $node link] close [dict get $node link] close
} }
} }
} }
catch {unset ::redis_cluster::startup_nodes($id)} catch {unset ::valkey_cluster::startup_nodes($id)}
catch {unset ::redis_cluster::nodes($id)} catch {unset ::valkey_cluster::nodes($id)}
catch {unset ::redis_cluster::slots($id)} catch {unset ::valkey_cluster::slots($id)}
catch {unset ::redis_cluster::tls($id)} catch {unset ::valkey_cluster::tls($id)}
catch {interp alias {} ::redis_cluster::instance$id {}} catch {interp alias {} ::valkey_cluster::instance$id {}}
} }
proc ::redis_cluster::__method__masternode_for_slot {id slot} { proc ::valkey_cluster::__method__masternode_for_slot {id slot} {
# Get the node mapped to this slot. # Get the node mapped to this slot.
set node_addr [dict get $::redis_cluster::slots($id) $slot] set node_addr [dict get $::valkey_cluster::slots($id) $slot]
if {$node_addr eq {}} { if {$node_addr eq {}} {
error "No mapped node for slot $slot." error "No mapped node for slot $slot."
} }
return [dict get $::redis_cluster::nodes($id) $node_addr] return [dict get $::valkey_cluster::nodes($id) $node_addr]
} }
proc ::redis_cluster::__method__masternode_notfor_slot {id slot} { proc ::valkey_cluster::__method__masternode_notfor_slot {id slot} {
# Get a node that is not mapped to this slot. # Get a node that is not mapped to this slot.
set node_addr [dict get $::redis_cluster::slots($id) $slot] set node_addr [dict get $::valkey_cluster::slots($id) $slot]
set addrs [dict keys $::redis_cluster::nodes($id)] set addrs [dict keys $::valkey_cluster::nodes($id)]
foreach addr [lshuffle $addrs] { foreach addr [lshuffle $addrs] {
set node [dict get $::redis_cluster::nodes($id) $addr] set node [dict get $::valkey_cluster::nodes($id) $addr]
if {$node_addr ne $addr && [dict get $node slaveof] eq "-"} { if {$node_addr ne $addr && [dict get $node slaveof] eq "-"} {
return $node return $node
} }
@ -196,22 +196,22 @@ proc ::redis_cluster::__method__masternode_notfor_slot {id slot} {
error "Slot $slot is everywhere" error "Slot $slot is everywhere"
} }
proc ::redis_cluster::__dispatch__ {id method args} { proc ::valkey_cluster::__dispatch__ {id method args} {
if {[info command ::redis_cluster::__method__$method] eq {}} { if {[info command ::valkey_cluster::__method__$method] eq {}} {
# Get the keys from the command. # Get the keys from the command.
set keys [::redis_cluster::get_keys_from_command $method $args] set keys [::valkey_cluster::get_keys_from_command $method $args]
if {$keys eq {}} { if {$keys eq {}} {
error "Redis command '$method' is not supported by redis_cluster." error "Redis command '$method' is not supported by valkey_cluster."
} }
# Resolve the keys in the corresponding hash slot they hash to. # Resolve the keys in the corresponding hash slot they hash to.
set slot [::redis_cluster::get_slot_from_keys $keys] set slot [::valkey_cluster::get_slot_from_keys $keys]
if {$slot eq {}} { if {$slot eq {}} {
error "Invalid command: multiple keys not hashing to the same slot." error "Invalid command: multiple keys not hashing to the same slot."
} }
# Get the node mapped to this slot. # Get the node mapped to this slot.
set node_addr [dict get $::redis_cluster::slots($id) $slot] set node_addr [dict get $::valkey_cluster::slots($id) $slot]
if {$node_addr eq {}} { if {$node_addr eq {}} {
error "No mapped node for slot $slot." error "No mapped node for slot $slot."
} }
@ -221,7 +221,7 @@ proc ::redis_cluster::__dispatch__ {id method args} {
set asking 0 set asking 0
while {[incr retry -1]} { while {[incr retry -1]} {
if {$retry < 5} {after 100} if {$retry < 5} {after 100}
set node [dict get $::redis_cluster::nodes($id) $node_addr] set node [dict get $::valkey_cluster::nodes($id) $node_addr]
set link [dict get $node link] set link [dict get $node link]
if {$asking} { if {$asking} {
$link ASKING $link ASKING
@ -233,8 +233,8 @@ proc ::redis_cluster::__dispatch__ {id method args} {
[string range $e 0 2] eq {I/O} \ [string range $e 0 2] eq {I/O} \
} { } {
# MOVED redirection. # MOVED redirection.
::redis_cluster::__method__refresh_nodes_map $id ::valkey_cluster::__method__refresh_nodes_map $id
set node_addr [dict get $::redis_cluster::slots($id) $slot] set node_addr [dict get $::valkey_cluster::slots($id) $slot]
continue continue
} elseif {[string range $e 0 2] eq {ASK}} { } elseif {[string range $e 0 2] eq {ASK}} {
# ASK redirection. # ASK redirection.
@ -252,14 +252,14 @@ proc ::redis_cluster::__dispatch__ {id method args} {
} }
error "Too many redirections or failures contacting Redis Cluster." error "Too many redirections or failures contacting Redis Cluster."
} else { } else {
uplevel 1 [list ::redis_cluster::__method__$method $id] $args uplevel 1 [list ::valkey_cluster::__method__$method $id] $args
} }
} }
proc ::redis_cluster::get_keys_from_command {cmd argv} { proc ::valkey_cluster::get_keys_from_command {cmd argv} {
set cmd [string tolower $cmd] set cmd [string tolower $cmd]
# Most commands get just one key as first argument. # Most commands get just one key as first argument.
if {[lsearch -exact $::redis_cluster::plain_commands $cmd] != -1} { if {[lsearch -exact $::valkey_cluster::plain_commands $cmd] != -1} {
return [list [lindex $argv 0]] return [list [lindex $argv 0]]
} }
@ -277,7 +277,7 @@ proc ::redis_cluster::get_keys_from_command {cmd argv} {
# Returns the CRC16 of the specified string. # Returns the CRC16 of the specified string.
# The CRC parameters are described in the Cluster specification. # The CRC parameters are described in the Cluster specification.
set ::redis_cluster::XMODEMCRC16Lookup { set ::valkey_cluster::XMODEMCRC16Lookup {
0x0000 0x1021 0x2042 0x3063 0x4084 0x50a5 0x60c6 0x70e7 0x0000 0x1021 0x2042 0x3063 0x4084 0x50a5 0x60c6 0x70e7
0x8108 0x9129 0xa14a 0xb16b 0xc18c 0xd1ad 0xe1ce 0xf1ef 0x8108 0x9129 0xa14a 0xb16b 0xc18c 0xd1ad 0xe1ce 0xf1ef
0x1231 0x0210 0x3273 0x2252 0x52b5 0x4294 0x72f7 0x62d6 0x1231 0x0210 0x3273 0x2252 0x52b5 0x4294 0x72f7 0x62d6
@ -312,19 +312,19 @@ set ::redis_cluster::XMODEMCRC16Lookup {
0x6e17 0x7e36 0x4e55 0x5e74 0x2e93 0x3eb2 0x0ed1 0x1ef0 0x6e17 0x7e36 0x4e55 0x5e74 0x2e93 0x3eb2 0x0ed1 0x1ef0
} }
proc ::redis_cluster::crc16 {s} { proc ::valkey_cluster::crc16 {s} {
set s [encoding convertto ascii $s] set s [encoding convertto ascii $s]
set crc 0 set crc 0
foreach char [split $s {}] { foreach char [split $s {}] {
scan $char %c byte scan $char %c byte
set crc [expr {(($crc<<8)&0xffff) ^ [lindex $::redis_cluster::XMODEMCRC16Lookup [expr {(($crc>>8)^$byte) & 0xff}]]}] set crc [expr {(($crc<<8)&0xffff) ^ [lindex $::valkey_cluster::XMODEMCRC16Lookup [expr {(($crc>>8)^$byte) & 0xff}]]}]
} }
return $crc return $crc
} }
# Hash a single key returning the slot it belongs to, Implemented hash # Hash a single key returning the slot it belongs to, Implemented hash
# tags as described in the Cluster specification. # tags as described in the Cluster specification.
proc ::redis_cluster::hash {key} { proc ::valkey_cluster::hash {key} {
set keylen [string length $key] set keylen [string length $key]
set s {} set s {}
set e {} set e {}
@ -353,10 +353,10 @@ proc ::redis_cluster::hash {key} {
# Return the slot the specified keys hash to. # Return the slot the specified keys hash to.
# If the keys hash to multiple slots, an empty string is returned to # If the keys hash to multiple slots, an empty string is returned to
# signal that the command can't be run in Cluster. # signal that the command can't be run in Cluster.
proc ::redis_cluster::get_slot_from_keys {keys} { proc ::valkey_cluster::get_slot_from_keys {keys} {
set slot {} set slot {}
foreach k $keys { foreach k $keys {
set s [::redis_cluster::hash $k] set s [::valkey_cluster::hash $k]
if {$slot eq {}} { if {$slot eq {}} {
set slot $s set slot $s
} elseif {$slot != $s} { } elseif {$slot != $s} {

View File

@ -72,13 +72,13 @@ proc valkey {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}} {r
set ::valkey::curr_argv($id) 0 set ::valkey::curr_argv($id) 0
set ::valkey::testing_resp3($id) 0 set ::valkey::testing_resp3($id) 0
set ::valkey::tls($id) $tls set ::valkey::tls($id) $tls
::valkey::redis_reset_state $id ::valkey::valkey_reset_state $id
interp alias {} ::valkey::redisHandle$id {} ::valkey::__dispatch__ $id interp alias {} ::valkey::valkeyHandle$id {} ::valkey::__dispatch__ $id
} }
# On recent versions of tcl-tls/OpenSSL, reading from a dropped connection # On recent versions of tcl-tls/OpenSSL, reading from a dropped connection
# results with an error we need to catch and mimic the old behavior. # results with an error we need to catch and mimic the old behavior.
proc ::valkey::redis_safe_read {fd len} { proc ::valkey::valkey_safe_read {fd len} {
if {$len == -1} { if {$len == -1} {
set err [catch {set val [read $fd]} msg] set err [catch {set val [read $fd]} msg]
} else { } else {
@ -93,7 +93,7 @@ proc ::valkey::redis_safe_read {fd len} {
error $msg error $msg
} }
proc ::valkey::redis_safe_gets {fd} { proc ::valkey::valkey_safe_gets {fd} {
if {[catch {set val [gets $fd]} msg]} { if {[catch {set val [gets $fd]} msg]} {
if {[string match "*connection abort*" $msg]} { if {[string match "*connection abort*" $msg]} {
return {} return {}
@ -162,7 +162,7 @@ proc ::valkey::__dispatch__raw__ {id method argv} {
foreach a $argv { foreach a $argv {
append cmd "$[string length $a]\r\n$a\r\n" append cmd "$[string length $a]\r\n$a\r\n"
} }
::valkey::redis_write $fd $cmd ::valkey::valkey_write $fd $cmd
if {[catch {flush $fd}]} { if {[catch {flush $fd}]} {
catch {close $fd} catch {close $fd}
set ::valkey::fd($id) {} set ::valkey::fd($id) {}
@ -172,13 +172,13 @@ proc ::valkey::__dispatch__raw__ {id method argv} {
set ::valkey::curr_argv($id) [concat $method $argv] set ::valkey::curr_argv($id) [concat $method $argv]
if {!$deferred} { if {!$deferred} {
if {$blocking} { if {$blocking} {
::valkey::redis_read_reply $id $fd ::valkey::valkey_read_reply $id $fd
} else { } else {
# Every well formed reply read will pop an element from this # Every well formed reply read will pop an element from this
# list and use it as a callback. So pipelining is supported # list and use it as a callback. So pipelining is supported
# in non blocking mode. # in non blocking mode.
lappend ::valkey::callback($id) $callback lappend ::valkey::callback($id) $callback
fileevent $fd readable [list ::valkey::redis_readable $fd $id] fileevent $fd readable [list ::valkey::valkey_readable $fd $id]
} }
} }
} else { } else {
@ -196,15 +196,15 @@ proc ::valkey::__method__reconnect {id fd val} {
} }
proc ::valkey::__method__read {id fd} { proc ::valkey::__method__read {id fd} {
::valkey::redis_read_reply $id $fd ::valkey::valkey_read_reply $id $fd
} }
proc ::valkey::__method__rawread {id fd {len -1}} { proc ::valkey::__method__rawread {id fd {len -1}} {
return [redis_safe_read $fd $len] return [valkey_safe_read $fd $len]
} }
proc ::valkey::__method__write {id fd buf} { proc ::valkey::__method__write {id fd buf} {
::valkey::redis_write $fd $buf ::valkey::valkey_write $fd $buf
} }
proc ::valkey::__method__flush {id fd} { proc ::valkey::__method__flush {id fd} {
@ -226,7 +226,7 @@ proc ::valkey::__method__close {id fd} {
catch {unset ::valkey::callback($id)} catch {unset ::valkey::callback($id)}
catch {unset ::valkey::curr_argv($id)} catch {unset ::valkey::curr_argv($id)}
catch {unset ::valkey::testing_resp3($id)} catch {unset ::valkey::testing_resp3($id)}
catch {interp alias {} ::valkey::redisHandle$id {}} catch {interp alias {} ::valkey::valkeyHandle$id {}}
} }
proc ::valkey::__method__channel {id fd} { proc ::valkey::__method__channel {id fd} {
@ -249,37 +249,37 @@ proc ::valkey::__method__attributes {id fd} {
set _ $::valkey::attributes($id) set _ $::valkey::attributes($id)
} }
proc ::valkey::redis_write {fd buf} { proc ::valkey::valkey_write {fd buf} {
puts -nonewline $fd $buf puts -nonewline $fd $buf
} }
proc ::valkey::redis_writenl {fd buf} { proc ::valkey::valkey_writenl {fd buf} {
redis_write $fd $buf valkey_write $fd $buf
redis_write $fd "\r\n" valkey_write $fd "\r\n"
flush $fd flush $fd
} }
proc ::valkey::redis_readnl {fd len} { proc ::valkey::valkey_readnl {fd len} {
set buf [redis_safe_read $fd $len] set buf [valkey_safe_read $fd $len]
redis_safe_read $fd 2 ; # discard CR LF valkey_safe_read $fd 2 ; # discard CR LF
return $buf return $buf
} }
proc ::valkey::valkey_bulk_read {fd} { proc ::valkey::valkey_bulk_read {fd} {
set count [redis_read_line $fd] set count [valkey_read_line $fd]
if {$count == -1} return {} if {$count == -1} return {}
set buf [redis_readnl $fd $count] set buf [valkey_readnl $fd $count]
return $buf return $buf
} }
proc ::valkey::redis_multi_bulk_read {id fd} { proc ::valkey::redis_multi_bulk_read {id fd} {
set count [redis_read_line $fd] set count [valkey_read_line $fd]
if {$count == -1} return {} if {$count == -1} return {}
set l {} set l {}
set err {} set err {}
for {set i 0} {$i < $count} {incr i} { for {set i 0} {$i < $count} {incr i} {
if {[catch { if {[catch {
lappend l [redis_read_reply_logic $id $fd] lappend l [valkey_read_reply_logic $id $fd]
} e] && $err eq {}} { } e] && $err eq {}} {
set err $e set err $e
} }
@ -288,15 +288,15 @@ proc ::valkey::redis_multi_bulk_read {id fd} {
return $l return $l
} }
proc ::valkey::redis_read_map {id fd} { proc ::valkey::valkey_read_map {id fd} {
set count [redis_read_line $fd] set count [valkey_read_line $fd]
if {$count == -1} return {} if {$count == -1} return {}
set d {} set d {}
set err {} set err {}
for {set i 0} {$i < $count} {incr i} { for {set i 0} {$i < $count} {incr i} {
if {[catch { if {[catch {
set k [redis_read_reply_logic $id $fd] ; # key set k [valkey_read_reply_logic $id $fd] ; # key
set v [redis_read_reply_logic $id $fd] ; # value set v [valkey_read_reply_logic $id $fd] ; # value
dict set d $k $v dict set d $k $v
} e] && $err eq {}} { } e] && $err eq {}} {
set err $e set err $e
@ -306,24 +306,24 @@ proc ::valkey::redis_read_map {id fd} {
return $d return $d
} }
proc ::valkey::redis_read_line fd { proc ::valkey::valkey_read_line fd {
string trim [redis_safe_gets $fd] string trim [valkey_safe_gets $fd]
} }
proc ::valkey::redis_read_null fd { proc ::valkey::valkey_read_null fd {
redis_safe_gets $fd valkey_safe_gets $fd
return {} return {}
} }
proc ::valkey::redis_read_bool fd { proc ::valkey::valkey_read_bool fd {
set v [redis_read_line $fd] set v [valkey_read_line $fd]
if {$v == "t"} {return 1} if {$v == "t"} {return 1}
if {$v == "f"} {return 0} if {$v == "f"} {return 0}
return -code error "Bad protocol, '$v' as bool type" return -code error "Bad protocol, '$v' as bool type"
} }
proc ::valkey::redis_read_double {id fd} { proc ::valkey::valkey_read_double {id fd} {
set v [redis_read_line $fd] set v [valkey_read_line $fd]
# unlike many other DTs, there is a textual difference between double and a string with the same value, # unlike many other DTs, there is a textual difference between double and a string with the same value,
# so we need to transform to double if we are testing RESP3 (i.e. some tests check that a # so we need to transform to double if we are testing RESP3 (i.e. some tests check that a
# double reply is "1.0" and not "1") # double reply is "1.0" and not "1")
@ -334,35 +334,35 @@ proc ::valkey::redis_read_double {id fd} {
} }
} }
proc ::valkey::redis_read_verbatim_str fd { proc ::valkey::valkey_read_verbatim_str fd {
set v [valkey_bulk_read $fd] set v [valkey_bulk_read $fd]
# strip the first 4 chars ("txt:") # strip the first 4 chars ("txt:")
return [string range $v 4 end] return [string range $v 4 end]
} }
proc ::valkey::redis_read_reply_logic {id fd} { proc ::valkey::valkey_read_reply_logic {id fd} {
if {$::valkey::readraw($id)} { if {$::valkey::readraw($id)} {
return [redis_read_line $fd] return [valkey_read_line $fd]
} }
while {1} { while {1} {
set type [redis_safe_read $fd 1] set type [valkey_safe_read $fd 1]
switch -exact -- $type { switch -exact -- $type {
_ {return [redis_read_null $fd]} _ {return [valkey_read_null $fd]}
: - : -
( - ( -
+ {return [redis_read_line $fd]} + {return [valkey_read_line $fd]}
, {return [redis_read_double $id $fd]} , {return [valkey_read_double $id $fd]}
# {return [redis_read_bool $fd]} # {return [valkey_read_bool $fd]}
= {return [redis_read_verbatim_str $fd]} = {return [valkey_read_verbatim_str $fd]}
- {return -code error [redis_read_line $fd]} - {return -code error [valkey_read_line $fd]}
$ {return [valkey_bulk_read $fd]} $ {return [valkey_bulk_read $fd]}
> - > -
~ - ~ -
* {return [redis_multi_bulk_read $id $fd]} * {return [redis_multi_bulk_read $id $fd]}
% {return [redis_read_map $id $fd]} % {return [valkey_read_map $id $fd]}
| { | {
set attrib [redis_read_map $id $fd] set attrib [valkey_read_map $id $fd]
set ::valkey::attributes($id) $attrib set ::valkey::attributes($id) $attrib
continue continue
} }
@ -378,27 +378,27 @@ proc ::valkey::redis_read_reply_logic {id fd} {
} }
} }
proc ::valkey::redis_read_reply {id fd} { proc ::valkey::valkey_read_reply {id fd} {
set response [redis_read_reply_logic $id $fd] set response [valkey_read_reply_logic $id $fd]
::response_transformers::transform_response_if_needed $id $::valkey::curr_argv($id) $response ::response_transformers::transform_response_if_needed $id $::valkey::curr_argv($id) $response
} }
proc ::valkey::redis_reset_state id { proc ::valkey::valkey_reset_state id {
set ::valkey::state($id) [dict create buf {} mbulk -1 bulk -1 reply {}] set ::valkey::state($id) [dict create buf {} mbulk -1 bulk -1 reply {}]
set ::valkey::statestack($id) {} set ::valkey::statestack($id) {}
} }
proc ::valkey::redis_call_callback {id type reply} { proc ::valkey::valkey_call_callback {id type reply} {
set cb [lindex $::valkey::callback($id) 0] set cb [lindex $::valkey::callback($id) 0]
set ::valkey::callback($id) [lrange $::valkey::callback($id) 1 end] set ::valkey::callback($id) [lrange $::valkey::callback($id) 1 end]
uplevel #0 $cb [list ::valkey::redisHandle$id $type $reply] uplevel #0 $cb [list ::valkey::valkeyHandle$id $type $reply]
::valkey::redis_reset_state $id ::valkey::valkey_reset_state $id
} }
# Read a reply in non-blocking mode. # Read a reply in non-blocking mode.
proc ::valkey::redis_readable {fd id} { proc ::valkey::valkey_readable {fd id} {
if {[eof $fd]} { if {[eof $fd]} {
redis_call_callback $id eof {} valkey_call_callback $id eof {}
::valkey::__method__close $id $fd ::valkey::__method__close $id $fd
return return
} }
@ -407,9 +407,9 @@ proc ::valkey::redis_readable {fd id} {
if {$line eq {}} return ;# No complete line available, return if {$line eq {}} return ;# No complete line available, return
switch -exact -- [string index $line 0] { switch -exact -- [string index $line 0] {
: - : -
+ {redis_call_callback $id reply [string range $line 1 end-1]} + {valkey_call_callback $id reply [string range $line 1 end-1]}
- {redis_call_callback $id err [string range $line 1 end-1]} - {valkey_call_callback $id err [string range $line 1 end-1]}
( {redis_call_callback $id reply [string range $line 1 end-1]} ( {valkey_call_callback $id reply [string range $line 1 end-1]}
$ { $ {
dict set ::valkey::state($id) bulk \ dict set ::valkey::state($id) bulk \
[expr [string range $line 1 end-1]+2] [expr [string range $line 1 end-1]+2]
@ -417,18 +417,18 @@ proc ::valkey::redis_readable {fd id} {
# We got a $-1, hack the state to play well with this. # We got a $-1, hack the state to play well with this.
dict set ::valkey::state($id) bulk 2 dict set ::valkey::state($id) bulk 2
dict set ::valkey::state($id) buf "\r\n" dict set ::valkey::state($id) buf "\r\n"
::valkey::redis_readable $fd $id ::valkey::valkey_readable $fd $id
} }
} }
* { * {
dict set ::valkey::state($id) mbulk [string range $line 1 end-1] dict set ::valkey::state($id) mbulk [string range $line 1 end-1]
# Handle *-1 # Handle *-1
if {[dict get $::valkey::state($id) mbulk] == -1} { if {[dict get $::valkey::state($id) mbulk] == -1} {
redis_call_callback $id reply {} valkey_call_callback $id reply {}
} }
} }
default { default {
redis_call_callback $id err \ valkey_call_callback $id err \
"Bad protocol, $type as reply type byte" "Bad protocol, $type as reply type byte"
} }
} }
@ -443,7 +443,7 @@ proc ::valkey::redis_readable {fd id} {
if {[string length [dict get $::valkey::state($id) buf]] == if {[string length [dict get $::valkey::state($id) buf]] ==
[dict get $::valkey::state($id) bulk]} { [dict get $::valkey::state($id) bulk]} {
if {[dict get $::valkey::state($id) mbulk] == -1} { if {[dict get $::valkey::state($id) mbulk] == -1} {
redis_call_callback $id reply \ valkey_call_callback $id reply \
[string range [dict get $::valkey::state($id) buf] 0 end-2] [string range [dict get $::valkey::state($id) buf] 0 end-2]
} else { } else {
dict with ::valkey::state($id) { dict with ::valkey::state($id) {
@ -452,7 +452,7 @@ proc ::valkey::redis_readable {fd id} {
set bulk -1 set bulk -1
} }
if {[dict get $::valkey::state($id) mbulk] == 0} { if {[dict get $::valkey::state($id) mbulk] == 0} {
redis_call_callback $id reply \ valkey_call_callback $id reply \
[dict get $::valkey::state($id) reply] [dict get $::valkey::state($id) reply]
} }
} }

View File

@ -27,7 +27,7 @@ proc cluster_response_tls {tls_cluster} {
test "CLUSTER SLOTS with different connection type -- tls-cluster $tls_cluster" { test "CLUSTER SLOTS with different connection type -- tls-cluster $tls_cluster" {
set slots1 [R 0 cluster slots] set slots1 [R 0 cluster slots]
set pport [srv 0 pport] set pport [srv 0 pport]
set cluster_client [redis_cluster 127.0.0.1:$pport 0] set cluster_client [valkey_cluster 127.0.0.1:$pport 0]
set slots2 [$cluster_client cluster slots] set slots2 [$cluster_client cluster slots]
$cluster_client close $cluster_client close
# Compare the ports in the first row # Compare the ports in the first row
@ -38,15 +38,15 @@ proc cluster_response_tls {tls_cluster} {
set nodes [R 0 cluster nodes] set nodes [R 0 cluster nodes]
set port1 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]] set port1 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]]
set pport [srv 0 pport] set pport [srv 0 pport]
set cluster_client [redis_cluster 127.0.0.1:$pport 0] set cluster_client [valkey_cluster 127.0.0.1:$pport 0]
set nodes [$cluster_client cluster nodes] set nodes [$cluster_client cluster nodes]
set port2 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]] set port2 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]]
$cluster_client close $cluster_client close
assert_not_equal $port1 $port2 assert_not_equal $port1 $port2
} }
set cluster [redis_cluster 127.0.0.1:[srv 0 port]] set cluster [valkey_cluster 127.0.0.1:[srv 0 port]]
set cluster_pport [redis_cluster 127.0.0.1:[srv 0 pport] 0] set cluster_pport [valkey_cluster 127.0.0.1:[srv 0 pport] 0]
$cluster refresh_nodes_map $cluster refresh_nodes_map
test "Set many keys in the cluster -- tls-cluster $tls_cluster" { test "Set many keys in the cluster -- tls-cluster $tls_cluster" {