get base buffer

This commit is contained in:
Josh Baker 2016-10-08 10:53:01 -07:00
parent 3696c16b1d
commit 3ca743f4c9
1 changed files with 20 additions and 0 deletions

View File

@ -289,6 +289,14 @@ func (c *conn) PeekPipeline() []Command {
return c.cmds
}
// BaseWriter returns the underlying connection writer, if any
func BaseWriter(c Conn) *Writer {
if c, ok := c.(*conn); ok {
return c.wr
}
return nil
}
// DetachedConn represents a connection that is detached from the server
type DetachedConn interface {
// Conn is the original connection
@ -411,6 +419,18 @@ func (w *Writer) WriteBulkString(bulk string) {
w.b = append(w.b, '\r', '\n')
}
// Buffer returns the unflushed buffer. This is a copy so changes
// to the resulting []byte will not affect the writer.
func (w *Writer) Buffer() []byte {
return append([]byte(nil), w.b...)
}
// SetBuffer replaces the unflushed buffer with new bytes.
func (w *Writer) SetBuffer(raw []byte) {
w.b = w.b[:0]
w.b = append(w.b, raw...)
}
// Flush writes all unflushed Write* calls to the underlying writer.
func (w *Writer) Flush() error {
if _, err := w.w.Write(w.b); err != nil {