Example #1
0
func writeBulkArg(w io.Writer, arg []byte) error {
	sw := ioutils.SimpleWriter(w)
	sw.Write([]byte{'$'})
	sw.Write(Itoa(len(arg)))
	sw.Write(NEW_LINE)
	sw.Write(arg)
	_, err := sw.Write(NEW_LINE)
	return errors.Trace(err)
}
Example #2
0
func WriteCmdKeys(w io.Writer, op string, keys [][]byte) error {
	sw := ioutils.SimpleWriter(w)

	sw.Write([]byte{'*'})
	sw.Write(Itoa(len(keys) + 1))
	sw.Write(NEW_LINE)

	err := writeBulkArg(sw, []byte(op))

	for _, key := range keys {
		err = writeBulkArg(sw, key)
	}

	return errors.Trace(err)
}
Example #3
0
func WriteCommand(w io.Writer, cmd string, args ...interface{}) error {
	sw := ioutils.SimpleWriter(w)

	sw.Write([]byte{'*'})
	sw.Write(Itoa(len(args) + 1))
	sw.Write(NEW_LINE)

	err := writeBulkArg(sw, []byte(cmd))

	for _, arg := range args {
		err = writeBulkArg(sw, formatCommandArg(arg))
	}

	return errors.Trace(err)
}