cli.tcl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. proc rediscli_tls_config {testsdir} {
  2. set tlsdir [file join $testsdir tls]
  3. set cert [file join $tlsdir client.crt]
  4. set key [file join $tlsdir client.key]
  5. set cacert [file join $tlsdir ca.crt]
  6. if {$::tls} {
  7. return [list --tls --cert $cert --key $key --cacert $cacert]
  8. } else {
  9. return {}
  10. }
  11. }
  12. # Returns command line for executing redis-cli
  13. proc rediscli {host port {opts {}}} {
  14. set cmd [list src/redis-cli -h $host -p $port]
  15. lappend cmd {*}[rediscli_tls_config "tests"]
  16. lappend cmd {*}$opts
  17. return $cmd
  18. }
  19. # Returns command line for executing redis-cli with a unix socket address
  20. proc rediscli_unixsocket {unixsocket {opts {}}} {
  21. return [list src/redis-cli -s $unixsocket {*}$opts]
  22. }
  23. # Run redis-cli with specified args on the server of specified level.
  24. # Returns output broken down into individual lines.
  25. proc rediscli_exec {level args} {
  26. set cmd [rediscli_unixsocket [srv $level unixsocket] $args]
  27. set fd [open "|$cmd" "r"]
  28. set ret [lrange [split [read $fd] "\n"] 0 end-1]
  29. close $fd
  30. return $ret
  31. }