Beispiel #1
0
func (b BinProt) Set(rw *bufio.ReadWriter, key, value []byte) error {
	// set packet contains the req header, flags, and expiration
	// flags are irrelevant, and are thus zero.
	// expiration could be important, so hammer with random values from 1 sec up to 1 hour

	return b.SetE(rw, key, value, common.Exp())
}
Beispiel #2
0
func (b BinProt) GAT(rw *bufio.ReadWriter, key []byte) ([]byte, error) {
	// Header
	writeReq(rw, GAT, len(key), 4, len(key), 0)
	// Extras
	binary.Write(rw, binary.BigEndian, common.Exp())
	// Body
	rw.Write(key)

	rw.Flush()

	// consume all of the response and return
	return consumeResponse(rw.Reader)
}
Beispiel #3
0
func (b BinProt) Touch(rw *bufio.ReadWriter, key []byte) error {
	// Header
	writeReq(rw, Touch, len(key), 4, len(key)+4)
	// Extras
	binary.Write(rw, binary.BigEndian, common.Exp())
	// Body
	rw.Write(key)

	rw.Flush()

	// consume all of the response and discard
	return consumeResponse(rw.Reader)
}
Beispiel #4
0
func (b BinProt) Set(rw *bufio.ReadWriter, key, value []byte) error {
	// set packet contains the req header, flags, and expiration
	// flags are irrelevant, and are thus zero.
	// expiration could be important, so hammer with random values from 1 sec up to 1 hour

	// Header
	bodylen := 8 + len(key) + len(value)
	writeReq(rw, Set, len(key), 8, bodylen)
	// Extras
	binary.Write(rw, binary.BigEndian, uint32(0))
	binary.Write(rw, binary.BigEndian, common.Exp())
	// Body / data
	rw.Write(key)
	rw.Write(value)

	rw.Flush()

	// consume all of the response and discard
	return consumeResponse(rw.Reader)
}
Beispiel #5
0
func (t TextProt) Touch(rw *bufio.ReadWriter, key []byte) error {
	strKey := string(key)
	if VERBOSE {
		fmt.Printf("Touching key %s\n", strKey)
	}

	if _, err := fmt.Fprintf(rw, "touch %s %v\r\n", strKey, common.Exp()); err != nil {
		return err
	}

	rw.Flush()

	response, err := rw.ReadString('\n')
	if err != nil {
		return err
	}
	if VERBOSE {
		fmt.Println(response)
		fmt.Printf("Touched key %s\n", strKey)
	}
	return nil
}