X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/f99e660b44281cd6bd6c24c60f1ebfb5e0e994e1..dd3f505ff527be62f422bf164d5ef62932d0f06a:/tests/support/util.tcl diff --git a/tests/support/util.tcl b/tests/support/util.tcl index ae758f4c..26cf1dc1 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -224,3 +224,52 @@ proc formatCommand {args} { } set _ $cmd } + +proc csvdump r { + set o {} + foreach k [lsort [$r keys *]] { + set type [$r type $k] + append o [csvstring $k] , [csvstring $type] , + switch $type { + string { + append o [csvstring [$r get $k]] "\n" + } + list { + foreach e [$r lrange $k 0 -1] { + append o [csvstring $e] , + } + append o "\n" + } + set { + foreach e [lsort [$r smembers $k]] { + append o [csvstring $e] , + } + append o "\n" + } + zset { + foreach e [$r zrange $k 0 -1 withscores] { + append o [csvstring $e] , + } + append o "\n" + } + hash { + set fields [$r hgetall $k] + set newfields {} + foreach {k v} $fields { + lappend newfields [list $k $v] + } + set fields [lsort -index 0 $newfields] + foreach kv $fields { + append o [csvstring [lindex $kv 0]] , + append o [csvstring [lindex $kv 1]] , + } + append o "\n" + } + } + } + return $o +} + +proc csvstring s { + return "\"$s\"" +}