ValkeyClusterClient class
The concrete implementation of ValkeyClusterClientBase.
This client manages connections to all master nodes in a Valkey Cluster, automatically routing commands to the correct node based on the key's hash slot.
Features:
- Auto-Discovery: Fetches cluster topology on connection.
- Smart Routing: Directs commands to the master node owning the key's slot.
- Resilience (v1.8.0+): Automatically handles
-MOVED/-ASKredirections and refreshes topology on connection failures (Failover).- Automatic Failover: Detects connection failures and refreshes topology.
- Topology Refresh: Queries available nodes to update the slot map.
- NAT Support: Automatically detects and maps Docker/NAT IP addresses.
- Implemented types
Constructors
-
ValkeyClusterClient(List<
ValkeyConnectionSettings> _initialNodes, {int maxRedirects = 5})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Closes all pooled connections to all nodes in the cluster.
override
-
connect(
) → Future< void> -
Connects to the cluster using the provided initial node(s).
override
-
debugCorruptSlotMap(
String key, int wrongPort) → void -
DEBUG ONLY: Manually corrupts the slot map to test redirection logic.
See
test/valkey_cluster_redirection_test.dart -
decr(
String key) → Future< int> -
Decrements the number stored at
keyby one.override -
decrBy(
String key, int amount) → Future< int> -
Decrements the number stored at
keybyamount.override -
del(
String key) → Future< int> -
Deletes the specified
key.override -
echo(
String message) → Future< String> -
Echoes the given
messageback from the server.override -
exists(
String key) → Future< int> -
Checks if
keyexists.override -
expire(
String key, int seconds) → Future< int> -
Sets a timeout on
keyin seconds.override -
get(
String key) → Future< String?> -
Gets the value of
key.override -
getMasterFor(
String key) → ClusterNodeInfo? -
Returns the ClusterNodeInfo of the master node that currently owns
key. Returnsnullif the client is not connected or the map is not loaded. -
hget(
String key, String field) → Future< String?> -
Gets the value of
fieldin the hash stored atkey.override -
hgetall(
String key) → Future< Map< String, String> > -
Gets all fields and values of the hash stored at
key.override -
hset(
String key, String field, String value) → Future< int> -
Sets
fieldin the hash stored atkeytovalue.override -
incr(
String key) → Future< int> -
Increments the number stored at
keyby one.override -
incrBy(
String key, int amount) → Future< int> -
Increments the number stored at
keybyamount.override -
lpop(
String key) → Future< String?> -
Removes and returns the first element of the list stored at
key.override -
lpush(
String key, String value) → Future< int> -
Prepends
valueto the list stored atkey.override -
lrange(
String key, int start, int stop) → Future< List< String?> > -
Returns the specified elements of the list stored at
key.override -
mget(
List< String> keys) → Future<List< String?> > -
Gets the values of all specified
keys.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pingAll(
[String? message]) → Future< Map< String, String> > -
PINGs all master nodes in the cluster.
override
-
rpop(
String key) → Future< String?> -
Removes and returns the last element of the list stored at
key.override -
rpush(
String key, String value) → Future< int> -
Appends
valueto the list stored atkey.override -
sadd(
String key, String member) → Future< int> -
Adds
memberto the set stored atkey.override -
set(
String key, String value) → Future< String> -
Sets
keytovalue.override -
smembers(
String key) → Future< List< String?> > -
Returns all members of the set stored at
key.override -
spublish(
String channel, String message) → Future< int> -
Posts a
messageto the givenchannelusing Sharded Pub/Sub. Returns the number of clients that received the message. Note: In Cluster mode, this command is routed to the specific node that owns the slot forchannel.override -
srem(
String key, String member) → Future< int> -
Removes
memberfrom the set stored atkey.override -
ssubscribe(
List< String> channels) → Subscription -
Subscribes the client to the specified
channelsusing Sharded Pub/Sub.override -
sunsubscribe(
[List< String> channels = const []]) → Future<void> -
Unsubscribes from the given
channelsusing Sharded Pub/Sub.override -
toString(
) → String -
A string representation of this object.
inherited
-
ttl(
String key) → Future< int> -
Gets the remaining time to live of a
keyin seconds.override -
zadd(
String key, double score, String member) → Future< int> -
Adds
memberwith the specifiedscoreto the sorted set stored atkey.override -
zrange(
String key, int start, int stop) → Future< List< String?> > -
Returns the specified range of members in the sorted set stored at
key, ordered from lowest to highest score.override -
zrem(
String key, String member) → Future< int> -
Removes
memberfrom the sorted set stored atkey.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited