add --pipe, fix bulkstring read error

master
Jordan Orelli 11 years ago
parent 7490afb48a
commit e1df1cdd83

@ -13,6 +13,7 @@ var options struct {
port int port int
password string password string
buffer int buffer int
pipe bool
} }
func usage(status int) { func usage(status int) {
@ -31,11 +32,6 @@ func randomString(n int) string {
func main() { func main() {
flag.Parse() flag.Parse()
args := flag.Args()
if len(args) < 1 {
usage(1)
}
fname := args[0]
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", options.host, options.port)) conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", options.host, options.port))
if err != nil { if err != nil {
@ -57,12 +53,25 @@ func main() {
} }
} }
infile, err := os.Open(fname) var infile *os.File
if err != nil {
fmt.Printf("unable to open file %s: %v\n", fname, err) if options.pipe {
os.Exit(1) infile = os.Stdin
} else {
args := flag.Args()
if len(args) < 1 {
usage(1)
}
fname := args[0]
var err error
infile, err = os.Open(fname)
if err != nil {
fmt.Printf("unable to open file %s: %v\n", fname, err)
os.Exit(1)
}
defer infile.Close()
} }
defer infile.Close()
c := make(chan maybe) c := make(chan maybe)
sent := make(chan value, options.buffer) sent := make(chan value, options.buffer)
@ -77,8 +86,8 @@ func main() {
r.val().Write(conn) r.val().Write(conn)
sent <- r.val() sent <- r.val()
} else { } else {
// this bad fmt.Fprintf(os.Stderr, "InputError: %v\n", r.err())
fmt.Println(r.err()) return
} }
} }
}() }()
@ -97,7 +106,7 @@ func main() {
replies++ replies++
} }
} else { } else {
fmt.Fprintln(os.Stderr, response.err()) fmt.Fprintf(os.Stderr, "ResponseError: %v\n", response.err())
} }
} }
fmt.Println("Last reply received from server.") fmt.Println("Last reply received from server.")
@ -109,6 +118,7 @@ func init() {
flag.IntVar(&options.port, "p", 6379, "port") flag.IntVar(&options.port, "p", 6379, "port")
flag.StringVar(&options.password, "a", "", "password") flag.StringVar(&options.password, "a", "", "password")
flag.IntVar(&options.buffer, "buffer", 0, "number of outstanding statements allowed before throttling") flag.IntVar(&options.buffer, "buffer", 0, "number of outstanding statements allowed before throttling")
flag.BoolVar(&options.pipe, "pipe", false, "transfers input from stdin to server")
} }
/* /*

@ -175,9 +175,12 @@ func readBulkString(prefix []byte, r io.Reader) (value, error) {
n += 2 n += 2
b := make([]byte, n) b := make([]byte, n)
n_read, err := r.Read(b) n_read, err := io.ReadFull(r, b)
switch err { switch err {
case io.EOF, nil: case io.EOF:
fmt.Printf("saw eof after %d bytes looking for %d bytes in bulkstring\n", n_read, n)
fmt.Println(string(b))
case nil:
break break
default: default:
return nil, fmt.Errorf("unable to read bulkstring in redis protocol: error on read: %v", err) return nil, fmt.Errorf("unable to read bulkstring in redis protocol: error on read: %v", err)

Loading…
Cancel
Save