RedisController class
The RedisController maintains an active connection to the Redis server. It handles caching, publishing, and subscriptions of strings. If the connection is broken the controller automatically tries to reconnect. Messages sent across Redis are best effort and not guaranteed to be delivered, if a message fails to be sent it will not retry.
Constructors
Properties
- connectTimeout → Duration
-
Maximum time to wait while opening the TCP/TLS connection to Redis.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String
-
The host of the Redis server.
final
- password → String?
-
The password of the Redis server. Not required, but recommended.
final
- port → int
-
The port of the Redis server.
final
- requireSsl → bool
-
require ssl
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
subscribedChannels
→ List<
String> -
Returns a list of subscribed channels.
no setter
- user → String?
-
The user name if the Redis server requires it.
final
Methods
-
clear(
) → Future< bool> - Removes all objects in the Redis cache, use with caution. Returns true if successful.
-
del(
String key) → Future< bool> - Deletes an entry from the Redis cache. Returns true if successful.
-
get(
String key) → Future< String?> - Gets a String from the Redis cache. If there is no object matching the key, null is returned.
-
getConnection(
) → Future< RedisCommand?> -
Returns the underlying Redis
Commandconnection. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ping(
) → Future< bool> - Tests Redis connectivity with a PING command.
-
publish(
String channel, String message) → Future< bool> - Publishes a message to a Redis channel. All subscribed listeners will be notified across servers.
-
set(
String key, String message, {Duration? lifetime}) → Future< bool> - Sets a String in the Redis cache, which optionally expires.
-
start(
{bool handleError(Exception e)?, Duration? connectTimeout}) → Future< void> - Starts the controller and connects to Redis. Maintains an open connection until stop is called.
-
stop(
) → Future< void> - Stops the controller and closes all open connections.
-
subscribe(
String channel, RedisSubscriptionCallback listener) → Future< bool> -
Subscribes to a Redis channel. When a message is published on the channel
the
listenercallback is called. Only one subscription call should be made per channel. -
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
String channel) → Future< bool> - Unsubscribes from a Redis channel.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited