Class RedisObject
java.lang.Object
com.blackrook.redis.data.RedisObject
An object, received or sent to the Redis Server.
This is an objectified form of RESP messages.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RedisObjectAll NULL string objects are this object.static final RedisObjectAll NULL array objects are this object. -
Method Summary
Modifier and TypeMethodDescriptiondoubleasDouble()Returns this object as a double.longasLong()Returns this object as a long integer.asRaw()Returns this object as a raw string, sent/received by/from Redis, replete with newline characters.asRaw(boolean alwaysBulk) Returns this object as a raw string, sent/received by/from Redis, replete with newline characters.asString()Returns this object as a String.static RedisObjectcreate(double value) Creates an object of type STRING, using a floating-point number.static RedisObjectcreate(long value) Creates an object of type INTEGER.static RedisObjectCreates an object of type STRING.static RedisObjectCreates an object of type ARRAY.static RedisObjectcreateEmptyArray(int length) Creates an object of type ARRAY, but with allnullelements.static RedisObjectcreateError(String message) Creates an object of type ERROR.static RedisObjectCreates a null object (type STRING).static RedisObjectCreates a null object (type ARRAY).get(int index) If this is an array, this returns an element at a specific index in it.getType()booleanisArray()booleanisError()booleanisNull()intlength()If this is an ARRAY type, this returns its length in elements.set(int index, double value) If this is an array, this sets an element at a specific index in it.set(int index, long value) If this is an array, this sets an element at a specific index in it.set(int index, RedisObject value) If this is an array, this sets an element at a specific index in it.If this is an array, this sets an element at a specific index in it.If this is an array, this sets an element at a specific index in it.toString()
-
Field Details
-
NULL
All NULL string objects are this object. -
NULL_ARRAY
All NULL array objects are this object.
-
-
Method Details
-
createNull
Creates a null object (type STRING).- Returns:
- the Redis object read.
-
createNullArray
Creates a null object (type ARRAY). This differs in the way it is sent.- Returns:
- the Redis object read.
-
createError
Creates an object of type ERROR.- Parameters:
message- the error message.- Returns:
- the Redis object read.
-
create
Creates an object of type INTEGER.- Parameters:
value- the integer value.- Returns:
- the Redis object read.
-
create
Creates an object of type STRING, using a floating-point number. Floating-point values in Redis are Strings, internally.- Parameters:
value- the double value.- Returns:
- the Redis object read.
-
create
Creates an object of type STRING.- Parameters:
value- the String value.- Returns:
- the Redis object read.
-
create
Creates an object of type ARRAY.- Parameters:
value- the String[] value.- Returns:
- the Redis object read.
-
createEmptyArray
Creates an object of type ARRAY, but with allnullelements.- Parameters:
length- the length of the array to create. If < 0, this returnsNULL_ARRAY.- Returns:
- the Redis object read.
-
getType
- Returns:
- the underlying type of this object.
-
isError
public boolean isError()- Returns:
- true if this represents an error. False, otherwise.
-
isNull
public boolean isNull()- Returns:
- true if this is a NULL object, STRING or ARRAY typed. False, otherwise.
-
isArray
public boolean isArray()- Returns:
- true if this is an ARRAY-typed object. False, otherwise.
-
length
public int length()If this is an ARRAY type, this returns its length in elements. Else, this returns its length in characters. Nulls return -1.- Returns:
- the length of this value.
-
get
If this is an array, this returns an element at a specific index in it.- Parameters:
index- the array index to inspect.- Returns:
- the object in the array.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
set
If this is an array, this sets an element at a specific index in it.- Parameters:
index- the array index to set.value- the long value to add.- Returns:
- the object created/set.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
set
If this is an array, this sets an element at a specific index in it.- Parameters:
index- the array index to set.value- the floating-point value to add.- Returns:
- the object created/set.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
set
If this is an array, this sets an element at a specific index in it.- Parameters:
index- the array index to set.value- the string value to add.- Returns:
- the object created/set.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
set
If this is an array, this sets an element at a specific index in it.- Parameters:
index- the array index to set.value- the string array value to add.- Returns:
- the object created/set.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
set
If this is an array, this sets an element at a specific index in it.- Parameters:
index- the array index to set.value- the RedisObject to add.- Returns:
- the object set.
- Throws:
IllegalStateException- if this is NOT an array.IndexOutOfBoundsException- if the provided index is outside the bounds of this array.
-
asLong
public long asLong()Returns this object as a long integer. Strings are cast to a long integer -0Lif conversion is impossible. Arrays are cast to0L. Errors are cast to0L. Nulls are cast to0L.- Returns:
- the integer value.
-
asDouble
public double asDouble()Returns this object as a double. Integers are cast to a double. Strings are cast to a double -0.0if conversion is impossible. Arrays are cast to0.0. Errors are cast to0.0. Nulls are cast to0.0.- Returns:
- the double value.
-
asString
Returns this object as a String. Integers are cast to a String. Arrays arenull. Errors are returned as their message. Nulls arenull.NOTE: Not to be confused with
toString().- Returns:
- the String value.
-
asRaw
Returns this object as a raw string, sent/received by/from Redis, replete with newline characters. The content returned by this method can be sent as-is to a Redis server.Equivalent to
asRaw(false).- Returns:
- the raw string value.
-
asRaw
Returns this object as a raw string, sent/received by/from Redis, replete with newline characters. The content returned by this method can be sent as-is to a Redis server.- Parameters:
alwaysBulk- if true, all strings are rendered as "bulk," binary-safe strings.- Returns:
- the raw string value.
-
toString
-