ValkeyClient class

The main client implementation for communicating with a Valkey server.

Implemented types

Constructors

ValkeyClient({String host = '127.0.0.1', int port = 6379, String? username, String? password, Duration commandTimeout = const Duration(seconds: 10), Duration connectTimeout = const Duration(seconds: 10), bool useSsl = false, SecurityContext? sslContext, bool onBadCertificate(X509Certificate)?, int database = 0, ReadPreference readPreference = ReadPreference.master, LoadBalancingStrategy loadBalancingStrategy = LoadBalancingStrategy.roundRobin, List<ValkeyConnectionSettings>? explicitReplicas, AddressMapper? addressMapper})
Creates a new Valkey client instance.
ValkeyClient.fromSettings(ValkeyConnectionSettings settings)
Creates a client using a ValkeyConnectionSettings object.
factory

Properties

allowRedisOnlyJsonMerge bool
Implementation of JsonCommands Interface Exposes the private variable to the Mixin via a getter.
no setter
currentConnectionConfig ValkeyConnectionSettings?
no setter
hashCode int
The hash code for this object.
no setterinherited
isConnected bool
Returns true if the client has an active socket connection.
no setter
isStateful bool
Returns true if the client is in a stateful mode that makes it unsuitable for reuse without a reset (e.g., Pub/Sub, Transaction).
no setter
lastUsedConnectionConfig ValkeyConnectionSettings?
Returns the configuration of the connection used for the last command. Useful for debugging load balancing strategies.
no setter
metadata ServerMetadata?
Returns the metadata of the connected server.
no setter
onConnected Future<void>
A Future that completes once the connection and authentication are successful.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setAllowRedisOnlyJsonMerge bool
no getter

Methods

close() Future<void>
Closes the connection to the server.
override
clusterSlots() Future<List<ClusterSlotRange>>
Fetches the cluster topology information from the server.
override
connect({String? host, int? port, String? username, String? password}) Future<void>
Connects to the Valkey server.
override
decr(String key) Future<int>
Decrements the number stored at key by one.
override
decrBy(String key, int amount) Future<int>
Decrements the number stored at key by amount.
override
del(String key) Future<int>
Deletes the specified key.
override
deprecatedIsJsonModuleLoaded() Future<bool>
Checks if the JSON module is loaded on the server.
inherited
deprecatedJsonGet({required String key, String path = r'$'}) Future
JSON.GET key path ...
inherited
deprecatedJsonSet({required String key, required String path, required dynamic data, bool nx = false, bool xx = false}) Future<void>
JSON.SET key path value NX | XX
inherited
discard() Future<String>
Discards all commands queued after multi().
override
echo(String message) Future<String>
Echoes the given message back from the server.
override
exec() Future<List?>
Executes all commands queued after multi().
override
execute(List<String> command) Future
v2.2.0 Routing Logic
override
exists(String key) Future<int>
Checks if key exists.
override
expire(String key, int seconds) Future<int>
Sets a timeout on key in seconds.
override
get(String key) Future<String?>
Gets the value of key.
override
getModuleList() Future<List<Map<String, dynamic>>>
Returns a list of loaded modules and their details.
inherited
getServerName() Future<String?>
getServerVersion() Future<String?>
hGet(String key, String field) Future<String?>
Gets the value of field in the hash stored at key.
override
hget(String key, String field) Future<String?>
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 field in the hash stored at key to value.
override
incr(String key) Future<int>
Increments the number stored at key by one.
override
incrBy(String key, int amount) Future<int>
Increments the number stored at key by amount.
override
isJsonModuleLoaded() Future<bool>
Checks if the JSON module is loaded on the server.
inherited
isRedisServer() Future<bool>
Helper to check server type based on metadata.
isValkeyServer() Future<bool>
Checks if the connected server is Valkey.
jsonArrAppend({required String key, String path = r'$', required List values}) Future
JSON.ARRAPPEND key path value value ...
inherited
jsonArrAppendEnhanced({required String key, required List<String> paths, required dynamic value}) Future<List<int?>?>
JSON.ARRAPPEND (Enhanced)
inherited
jsonArrIndex({required String key, required String path, required dynamic value, int? start, int? stop}) Future
JSON.ARRINDEX key path value [start stop]
inherited
jsonArrIndexEnhanced({required String key, required List<String> paths, required dynamic value, int? start, int? stop}) Future<List<int?>?>
JSON.ARRINDEX (Enhanced)
inherited
jsonArrInsert({required String key, required String path, required int index, required List values}) Future
JSON.ARRINSERT key path index value value ...
inherited
jsonArrInsertEnhanced({required String key, required List<String> paths, required int index, required List values}) Future<List<int?>?>
JSON.ARRINSERT (Enhanced)
inherited
jsonArrLen({required String key, String path = r'$'}) Future
JSON.ARRLEN key path
inherited
jsonArrLenEnhanced({required String key, required List<String> paths}) Future<List<int?>?>
JSON.ARRLEN (Enhanced)
inherited
jsonArrPop({required String key, String path = r'$', int? index}) Future
JSON.ARRPOP key [path index]
inherited
jsonArrPopEnhanced({required String key, required List<String> paths, int? index}) Future<List?>
JSON.ARRPOP (Enhanced)
inherited
jsonArrTrim({required String key, required String path, required int start, required int stop}) Future
JSON.ARRTRIM key path start stop
inherited
jsonArrTrimEnhanced({required String key, required List<String> paths, required int start, required int stop}) Future<List<int?>?>
JSON.ARRTRIM (Enhanced)
inherited
jsonClear({required String key, String path = r'$'}) Future<int>
JSON.CLEAR key path
inherited
jsonDebug({required String key, String path = r'$'}) Future
JSON.DEBUG MEMORY key path
inherited
jsonDel({required String key, String path = r'$'}) Future<int?>
JSON.DEL key path
inherited
jsonForget({required String key, String path = r'$'}) Future<int>
JSON.FORGET key path
inherited
jsonGet({required String key, String path = r'$'}) Future
JSON.GET key path ...
inherited
jsonMerge({required String key, required String path, required dynamic data}) Future<void>
JSON.MERGE key path value
inherited
jsonMergeForce({required String key, required String path, required dynamic data}) Future<void>
inherited
jsonMGet({required List<String> keys, required String path}) Future<List>
JSON.MGET key key ... path
inherited
jsonMSet({required List<JsonMSetEntry> entries}) Future<void>
JSON.MSET key path value key path value ...
inherited
jsonNumIncrBy({required String key, required String path, required num value}) Future
JSON.NUMINCRBY key path value
inherited
jsonNumMultBy({required String key, required String path, required num value}) Future
JSON.NUMMULTBY key path value
inherited
jsonObjKeys({required String key, String path = r'$'}) Future
JSON.OBJKEYS key path
inherited
jsonObjKeysEnhanced({required String key, required List<String> paths}) Future<List<List?>?>
JSON.OBJKEYS (Enhanced)
inherited
jsonObjLen({required String key, String path = r'$'}) Future
JSON.OBJLEN key path
inherited
jsonResp({required String key, String path = r'$'}) Future
JSON.RESP key path
inherited
jsonSet({required String key, required String path, required dynamic data, bool nx = false, bool xx = false}) Future<void>
JSON.SET key path value NX | XX
inherited
jsonStrAppend({required String key, String path = r'$', required String value}) Future
JSON.STRAPPEND key path value
inherited
jsonStrAppendEnhanced({required String key, required List<String> paths, required String value}) Future<List<int?>?>
JSON.STRAPPEND (Enhanced)
inherited
jsonStrLen({required String key, String path = r'$'}) Future
JSON.STRLEN key path
inherited
jsonStrLenEnhanced({required String key, required List<String> paths}) Future<List<int?>?>
JSON.STRLEN (Enhanced)
inherited
jsonToggle({required String key, String path = r'$'}) Future
JSON.TOGGLE key path
inherited
jsonType({required String key, String path = r'$'}) Future
JSON.TYPE key path
inherited
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 value to the list stored at key.
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
multi() Future<String>
Marks the start of a transaction block.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ping([String? message]) Future<String>
PINGs the server.
override
psubscribe(List<String> patterns) Subscription
Subscribes the client to the given patterns (e.g., "log:*").
override
publish(String channel, String message) Future<int>
Posts a message to the given channel.
override
pubsubChannels([String? pattern]) Future<List<String?>>
Lists the currently active channels.
override
pubsubNumPat() Future<int>
Returns the number of subscriptions to patterns.
override
pubsubNumSub(List<String> channels) Future<Map<String, int>>
Returns the number of subscribers for the specified channels.
override
punsubscribe([List<String> patterns = const []]) Future<void>
Unsubscribes the client from the given patterns, or all patterns if none are given.
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 value to the list stored at key.
override
sadd(String key, String member) Future<int>
Adds member to the set stored at key.
override
scan({required String cursor, String match = '*', int count = 100}) Future<ScanResult>
inherited
set(String key, String value) Future<String>
Sets key to value.
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 message to the given channel using 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 for channel.
override
srem(String key, String member) Future<int>
Removes member from the set stored at key.
override
ssubscribe(List<String> channels) Subscription
Subscribes the client to the specified channels using Sharded Pub/Sub.
override
subscribe(List<String> channels) Subscription
Subscribes the client to the specified channels.
override
sunsubscribe([List<String> channels = const []]) Future<void>
Unsubscribes from the given channels using 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 key in seconds.
override
unsubscribe([List<String> channels = const []]) Future<void>
Unsubscribes the client from the given channels, or all channels if none are given.
override
zadd(String key, double score, String member) Future<int>
Adds member with the specified score to the sorted set stored at key.
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 member from the sorted set stored at key.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

setLogLevel(ValkeyLogLevel level) → void
Sets the logging level for all ValkeyClient instances.