Class RESPReader
java.lang.Object
com.blackrook.redis.io.RESPReader
Reader class for reading responses from a Redis Socket connection.
- Author:
- Matthew Tropiano
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a RedisReader attached to an input stream. -
Method Summary
Modifier and TypeMethodDescriptionString[]Reads and expects an Array Reply from Redis.protected intReads bytes until CRLF and returns how many bytes in the "string" (before CRLF).Reads and expects an Integer Reply from Redis.protected intReads bytes until CRLF and returns how many bytes in the "string" (before CRLF).Reads a full Redis data structure as aRedisObject.booleanreadOK()Reads and expects "OK" from Redis.booleanreadPong()Reads and expects "PONG" from Redis.booleanReads and expects "QUEUED" from Redis.readRaw()Reads until a full Redis data structure is read.Reads and expects a String Reply from Redis, bulk or otherwise.
-
Constructor Details
-
RESPReader
Creates a RedisReader attached to an input stream.- Parameters:
in- theInputStreamto wrap.
-
-
Method Details
-
readOK
public boolean readOK()Reads and expects "OK" from Redis. Will block until something is read from the stream. Should be used if AND ONLY IF "OK" is expected.- Returns:
- true.
- Throws:
RedisException- if the server reports an error, or isn't OK.RedisParseException- if an error occurs during the read.
-
readQueued
public boolean readQueued()Reads and expects "QUEUED" from Redis. Will block until something is read from the stream. Should be used if AND ONLY IF "QUEUED" is expected.- Returns:
- true.
- Throws:
RedisException- if the server reports an error, or isn't QUEUED.RedisParseException- if an error occurs during the read.
-
readPong
public boolean readPong()Reads and expects "PONG" from Redis. Will block until something is read from the stream. Should be used if AND ONLY IF "PONG" is expected.- Returns:
- true.
- Throws:
RedisException- if the server reports an error, or isn't PONG.RedisParseException- if an error occurs during the read.
-
readInteger
Reads and expects an Integer Reply from Redis. Will block until something is read from the stream. Should be used if AND ONLY IF an Integer or Null is expected.- Returns:
- a long or null reply.
- Throws:
RedisException- if the server reports an error.RedisParseException- if an error occurs during the read.
-
readString
Reads and expects a String Reply from Redis, bulk or otherwise. Will block until something is read from the stream. Should be used if AND ONLY IF a non-array or Null is expected. Integers are cast to Strings.- Returns:
- a long or null reply.
- Throws:
RedisException- if the server reports an error.RedisParseException- if an error occurs during the read.
-
readArray
Reads and expects an Array Reply from Redis. Will block until something is read from the stream. Should be used if AND ONLY IF an array or Null is expected. Integers are cast to Strings.- Returns:
- an array or null reply. Arrays may contain null elements!
- Throws:
RedisException- if the server reports an error.RedisParseException- if an error occurs during the read.
-
readObject
Reads a full Redis data structure as aRedisObject. This is useful for commands that return complex or not-yet-supported responses. Will block until something is read completely from the stream.- Returns:
- a full string with all breaks and newlines.
- Throws:
RedisException- if the server reports an error.RedisParseException- if an error occurs during the read.
-
readRaw
Reads until a full Redis data structure is read. Will block until something is read completely from the stream.- Returns:
- a full string with all breaks and newlines.
- Throws:
RedisException- if the server reports an error.RedisParseException- if an error occurs during the read.
-
readLine
Reads bytes until CRLF and returns how many bytes in the "string" (before CRLF).- Parameters:
dl- the data buffer to read from.- Returns:
- the amount of bytes read.
- Throws:
IOException
-
readBulk
Reads bytes until CRLF and returns how many bytes in the "string" (before CRLF).- Parameters:
dl- the data buffer to read from.len- the maximum amount of bytes to read.- Returns:
- the amount of bytes read.
- Throws:
IOException
-