Package com.blackrook.redis.io
Class RESPWriter
- java.lang.Object
-
- com.blackrook.redis.io.RESPWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class RESPWriter extends Object implements Closeable
Writer class for writing requests to a Redis Socket.- Author:
- Matthew Tropiano
-
-
Constructor Summary
Constructors Constructor Description RESPWriter(OutputStream out)
Opens a RedisWriter attached to an output stream.RESPWriter(Writer out)
Opens a RedisWriter attached to a writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
writeArray(Iterable<Object> iterable)
Writes a bulk string array.void
writeArray(Object... objects)
Writes a bulk string array.void
writeArray(String... strings)
Writes a bulk string array.void
writeBulkString(String s)
Writes a bulk string to output.protected void
writeBulkString(String s, boolean flush)
Writes a bulk string.void
writeChar(char c)
Writes a character to output.void
writeCommand(String commandString)
Writes a Redis command as though it will be executed from a REPL-like command prompt.void
writeError(String s)
Writes an error to output.void
writeNull()
Writes a null object.protected void
writeNull(boolean flush)
Writes a null object.void
writeNullArray()
Writes a null object.void
writeNumber(Number n)
Writes a number to output.protected void
writeNumber(Number n, boolean flush)
Writes a number to output.void
writeObject(RedisObject object)
Writes a full object that represents a Redis request.void
writeRaw(String rawcontent)
Writes raw content into this writer and flushes it.void
writeSimpleString(String s)
Writes a simple string to output.protected void
writeSimpleString(String s, boolean flush)
Writes a bulk string to output.
-
-
-
Constructor Detail
-
RESPWriter
public RESPWriter(OutputStream out)
Opens a RedisWriter attached to an output stream.- Parameters:
out
- theOutputStream
to use.
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
writeNull
public void writeNull()
Writes a null object.
-
writeNullArray
public void writeNullArray()
Writes a null object.
-
writeNumber
public void writeNumber(Number n)
Writes a number to output.- Parameters:
n
- the number to write.
-
writeSimpleString
public void writeSimpleString(String s)
Writes a simple string to output.- Parameters:
s
- the string to write.
-
writeBulkString
public void writeBulkString(String s)
Writes a bulk string to output.- Parameters:
s
- the string to write.
-
writeArray
public void writeArray(Iterable<Object> iterable)
Writes a bulk string array.- Parameters:
iterable
- the objects to write.
-
writeArray
public void writeArray(Object... objects)
Writes a bulk string array.- Parameters:
objects
- the objects to write.
-
writeArray
public void writeArray(String... strings)
Writes a bulk string array.- Parameters:
strings
- the series of strings.
-
writeObject
public void writeObject(RedisObject object)
Writes a full object that represents a Redis request.- Parameters:
object
- the Redis object to write.
-
writeChar
public void writeChar(char c)
Writes a character to output.- Parameters:
c
- the character.
-
writeError
public void writeError(String s)
Writes an error to output.- Parameters:
s
- the error string to write.
-
writeCommand
public void writeCommand(String commandString)
Writes a Redis command as though it will be executed from a REPL-like command prompt. The full command is sent to the server as a raw request.- Parameters:
commandString
- the command to send to the server.
-
writeRaw
public void writeRaw(String rawcontent)
Writes raw content into this writer and flushes it.- Parameters:
rawcontent
- the content to send.
-
writeNull
protected void writeNull(boolean flush)
Writes a null object.- Parameters:
flush
- if true, flushes the stream.
-
writeNumber
protected void writeNumber(Number n, boolean flush)
Writes a number to output.- Parameters:
n
- the number to write.flush
- if true, flushes the stream.
-
writeSimpleString
protected void writeSimpleString(String s, boolean flush)
Writes a bulk string to output.- Parameters:
s
- the string to write.flush
- if true, flushes the stream.
-
writeBulkString
protected void writeBulkString(String s, boolean flush)
Writes a bulk string.- Parameters:
s
- the string to write.flush
- if true, flushes the stream.
-
-