Added auth flag
This commit is contained in:
parent
983e1bcb8e
commit
e47540ba09
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
@ -21,6 +22,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
hostname = "127.0.0.1"
|
hostname = "127.0.0.1"
|
||||||
port = 9851
|
port = 9851
|
||||||
|
auth = ""
|
||||||
clients = 50
|
clients = 50
|
||||||
requests = 100000
|
requests = 100000
|
||||||
quiet = false
|
quiet = false
|
||||||
@ -46,6 +48,7 @@ func showHelp() bool {
|
|||||||
|
|
||||||
fmt.Fprintf(os.Stdout, " -h <hostname> Server hostname (default: %s)\n", hostname)
|
fmt.Fprintf(os.Stdout, " -h <hostname> Server hostname (default: %s)\n", hostname)
|
||||||
fmt.Fprintf(os.Stdout, " -p <port> Server port (default: %d)\n", port)
|
fmt.Fprintf(os.Stdout, " -p <port> Server port (default: %d)\n", port)
|
||||||
|
fmt.Fprintf(os.Stdout, " -a <password> Password for Tile38 Auth\n")
|
||||||
fmt.Fprintf(os.Stdout, " -c <clients> Number of parallel connections (default %d)\n", clients)
|
fmt.Fprintf(os.Stdout, " -c <clients> Number of parallel connections (default %d)\n", clients)
|
||||||
fmt.Fprintf(os.Stdout, " -n <requests> Total number or requests (default %d)\n", requests)
|
fmt.Fprintf(os.Stdout, " -n <requests> Total number or requests (default %d)\n", requests)
|
||||||
fmt.Fprintf(os.Stdout, " -q Quiet. Just show query/sec values\n")
|
fmt.Fprintf(os.Stdout, " -q Quiet. Just show query/sec values\n")
|
||||||
@ -105,6 +108,8 @@ func parseArgs() bool {
|
|||||||
hostname = readArg(arg)
|
hostname = readArg(arg)
|
||||||
case "-p":
|
case "-p":
|
||||||
port = readIntArg(arg)
|
port = readIntArg(arg)
|
||||||
|
case "-a":
|
||||||
|
auth = readArg(arg)
|
||||||
case "-c":
|
case "-c":
|
||||||
clients = readIntArg(arg)
|
clients = readIntArg(arg)
|
||||||
if clients <= 0 {
|
if clients <= 0 {
|
||||||
@ -169,10 +174,31 @@ func randRect(meters float64) (minlat, minlon, maxlat, maxlon float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepFn(conn net.Conn) bool {
|
func prepFn(conn net.Conn) bool {
|
||||||
|
var resp [64]byte
|
||||||
|
conn.Write([]byte("CONFIG GET requirepass\r\n"))
|
||||||
|
n, err := conn.Read(resp[:])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if string(resp[:n]) == "-ERR authentication required\r\n" {
|
||||||
|
if auth == "" {
|
||||||
|
log.Fatal("invalid auth")
|
||||||
|
} else {
|
||||||
|
cmd := redcon.AppendArray(nil, 2)
|
||||||
|
cmd = redcon.AppendBulkString(cmd, "AUTH")
|
||||||
|
cmd = redcon.AppendBulkString(cmd, auth)
|
||||||
|
conn.Write(cmd)
|
||||||
|
n, err := conn.Read(resp[:])
|
||||||
|
if err != nil || string(resp[:n]) != "+OK\r\n" {
|
||||||
|
log.Fatal("invalid auth")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if auth != "" {
|
||||||
|
log.Fatal("invalid auth")
|
||||||
|
}
|
||||||
if json {
|
if json {
|
||||||
conn.Write([]byte("output json\r\n"))
|
conn.Write([]byte("output json\r\n"))
|
||||||
resp := make([]byte, 100)
|
conn.Read(make([]byte, 64))
|
||||||
conn.Read(resp)
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user