<commit_before># TODO # test pipelining

source client-libraries/tcl/redis.tcl

set ::passed 0
set ::failed 0

proc test {name code okpattern} {
    puts -nonewline [format "%-70s " $name]
    flush stdout
    set retval [uplevel 1 $code]
    if {$okpattern eq $retval || [string match $okpattern $retval]} {
        puts "PASSED"
        incr ::passed
    } else {
        puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
        incr ::failed
    }
}

proc randstring {min max {type binary}} {
    set len [expr {$min+int(rand()*($max-$min+1))}]
    set output {}
    if {$type eq {binary}} {
        set minval 0
        set maxval 255
    } elseif {$type eq {alpha}} {
        set minval 48
        set maxval 122
    } elseif {$type eq {compr}} {
        set minval 48
        set maxval 52
    }
    while {$len} {
        append output [format "%c" [expr {$minval+int(rand()*($maxval-$minval+1))}]]
        incr len -1
    }
    return $output
}

proc main {server port} {
    set r [redis $server $port]
    set err ""

    # The following AUTH test should be enabled only when requirepass
    # <PASSWORD> is set in redis.conf and redis-server was started with
    # redis.conf as the first argument.  

    #test {AUTH with requirepass in redis.conf} {
    #    $r auth foobared
    #} {OK}

    test {DEL all keys to start with a clean DB} {
        foreach key [$r keys *] {$r del $key}
        $r dbsize
    } {0}

    test {SET and GET an item} {
        $r set x foobar
        $r get x
    } {foobar}

    test {DEL against a single item} {
        $r del x
        $r get x
    } {}

    test {KEYS with pattern} {
        foreach key {key_x key_y key_z foo_a foo_b foo_c} {
            $r set $key hello
        }
        lsort [$r keys foo*]
    } {foo_a foo_b foo_c}

    test {KEYS to get all keys} {
        lsort [$r keys *]
    } {foo_a foo_b foo_c key_x key_y key_z}

    test {DBSIZE} {
        $r dbsize
    } {6}

    test {DEL all keys} {
        foreach key [$r keys *] {$r del $key}
        $r dbsize
    } {0}

    test {Very big payload in GET/SET} {
        set buf [string repeat "abcd" 1000000]
        $r set foo $buf
        $r get foo
    } [string repeat "abcd" 1000000]

    test {SET 10000 numeric keys and access all them in reverse order} {
        for {set x 0} {$x < 10000} {incr x} {
            $r set $x $x
        }<commit_msg>added tests for vararg DEL<commit_after># TODO # test pipelining

source client-libraries/tcl/redis.tcl

set ::passed 0
set ::failed 0

proc test {name code okpattern} {
    puts -nonewline [format "%-70s " $name]
    flush stdout
    set retval [uplevel 1 $code]
    if {$okpattern eq $retval || [string match $okpattern $retval]} {
        puts "PASSED"
        incr ::passed
    } else {
        puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
        incr ::failed
    }
}

proc randstring {min max {type binary}} {
    set len [expr {$min+int(rand()*($max-$min+1))}]
    set output {}
    if {$type eq {binary}} {
        set minval 0
        set maxval 255
    } elseif {$type eq {alpha}} {
        set minval 48
        set maxval 122
    } elseif {$type eq {compr}} {
        set minval 48
        set maxval 52
    }
    while {$len} {
        append output [format "%c" [expr {$minval+int(rand()*($maxval-$minval+1))}]]
        incr len -1
    }
    return $output
}

proc main {server port} {
    set r [redis $server $port]
    set err ""

    # The following AUTH test should be enabled only when requirepass
    # <PASSWORD> is set in redis.conf and redis-server was started with
    # redis.conf as the first argument.  

    #test {AUTH with requirepass in redis.conf} {
    #    $r auth foobared
    #} {OK}

    test {DEL all keys to start with a clean DB} {
        foreach key [$r keys *] {$r del $key}
        $r dbsize
    } {0}

    test {SET and GET an item} {
        $r set x foobar
        $r get x
    } {foobar}

    test {DEL against a single item} {
        $r del x
        $r get x
    } {}

    test {Vararg DEL} {
        $r set foo1 a
        $r set foo2 b
        $r set foo3 c
        list [$r del foo1 foo2 foo3 foo4] [$r mget foo1 foo2 foo3]
    } {3 {{} {} {}}}

    test {KEYS with pattern} {
        foreach key {key_x key_y key_z foo_a foo_b foo_c} {
            $r set $key hello
        }
        lsort [$r keys foo*]
    } {foo_a foo_b foo_c}

    test {KEYS to get all keys} {
        lsort [$r keys *]
    } {foo_a foo_b foo_c key_x key_y key_z}

    test {DBSIZE} {
        $r dbsize
    } {6}

    test {DEL all keys} {
        foreach key [$r keys *] {$r del $key}
        $r dbsize
    } {0}

    test {Very big payload in GET/SET} {
        set buf [string repeat "abcd" 1000000]
        $r set foo $buf
        $r get foo
    } [string repeat "abcd" 1000000]

    test {SET 10000 numeric keys and access all them in reverse order} {
        for {set x 0} {$x < 10000} {incr x} {
            $r set $x $x
        }
{'fraction_non_alphanumeric': 0.1157873540072493, 'fraction_numerical': 0.021949254933548126, 'mean_word_length': 1.9029807130333138, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1015063', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1697, 'n_words': 630}