Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class RedisConnection
- Object
- RedisConnection
One connection to a Redis server speaking RESP2, the protocol every Redis, Valkey and KeyDB release understands.
RedisKeyValueStore keeps a pool of these and lends one per call; ask it for
a RedisKeyValueStore.dedicated() connection for a command that blocks –
XREADGROUP ... BLOCK, BLPOP, SUBSCRIBE – so it never holds a pooled one.
Replies come back as Java values: a simple string as String, a bulk string
as byte[], an integer as Long, an array as Object[], a nil as null. An
error reply is thrown as a RedisException, and leaves the connection usable.
Any other failure leaves it in an unknown state; the caller closes it.
Not thread safe.
Methods
public boolean isBroken() | Whether a failure other than an error reply happened on this connection, after which it must not be reused. |
public void setReadTimeout(int millis)
throws IOException | Changes how long a reply may take; zero waits forever. |
public Object call(String... args)
throws IOException | Sends one command and answers its reply. |
public Object call(byte[][] args)
throws IOException | Sends one command whose arguments are already bytes and answers its reply. |
public void write(byte[][] args) | Stages one command without sending it, for a pipeline: stage several, flush once, then read each reply in order. |
public void flush()
throws IOException | Sends what write staged. |
public Object read()
throws IOException | Reads the next reply. |
public void close() | Closes the socket. |
Inherited methods
Method details
isBroken
public boolean isBroken()Whether a failure other than an error reply happened on this connection,
after which it must not be reused.
setReadTimeout
public void setReadTimeout(int millis)
throws IOExceptionChanges how long a reply may take; zero waits forever.
Throws
call
public Object call(String... args)
throws IOExceptionSends one command and answers its reply.
Throws
call
public Object call(byte[][] args)
throws IOExceptionSends one command whose arguments are already bytes and answers its reply.
Throws
write
public void write(byte[][] args)flush
public void flush()
throws IOExceptionSends what
write staged.Throws
read
public Object read()
throws IOExceptionReads the next reply. An error reply is thrown after it has been read
whole, so the connection stays in step.
Throws
close
public void close()Closes the socket. Never throws.