dart_valkey 0.0.3
dart_valkey: ^0.0.3 copied to clipboard
Dart client for Valkey (and Redis-compatible servers)
dart valkey/redis
This project is a robust, type-safe Dart client for Redis (and Valkey) that manages both command and Pub/Sub interactions. It provides built‐in connection management, automatic reconnection, and pluggable authentication. Thanks to its modular design, the user can easily extend commands as Dart extensions and choose between a secure (TLS) and insecure connection.
Features #
-
Connection Management
Uses the Template Method pattern inBaseConnectionto handle the socket connection, reconnection logic, and error management automatically. -
Authentication and Command Execution
Implements authentication commands (e.g.HelloCommandandAuthCommand) to ensure secure and correct data exchange with the Redis/Valkey server. -
Pub/Sub Support
Supports Pub/Sub operations with theValkeySubscriptionClientwhich handles subscriptions to channels and patterns and delivers messages via a unified stream. -
Extensible & Modular
Commands are organized into modules so that new commands can be added as extensions. The core libraries (ValkeyCommandClientandValkeyClient) provide a foundation for building more specialized client implementations.
Installation #
-
Add the dependency in your pubspec.yaml:
// filepath: pubspec.yaml dependencies: dart_valkey: any -
Install the dependency by running:
pub get
Usage #
Connecting and Sending Commands
To connect and execute commands, first import the client library:
import 'package:dart_valkey/dart_valkey.dart';
Future<void> main() async {
// Create a command client (or use a specific implementation)
final client = ValkeyCommandClient(
host: 'localhost',
port: 6379,
username: 'your-username', // optional
password: 'your-password', // optional
);
// Connect to the server
await client.connect();
// Execute a command (for example, a PING command if implemented)
final response = await client.execute(PingCommand());
print('Server response: $response');
// Close the client when done
await client.close();
}
Pub/Sub Example
Subscribing to channels and listening for messages is simple with the ValkeySubscriptionClient:
import 'package:dart_valkey/dart_valkey.dart';
import 'dart:async';
Future<void> main() async {
final subClient = ValkeySubscriptionClient(
host: 'localhost',
port: 6379,
);
// Connect to the server
await subClient.connect();
// Subscribe to a channel
subClient.subscribe(['channel1']);
// Listen to Pub/Sub messages
final subscription = subClient.messages.listen((PubSubMessage msg) {
print('Received message: ${msg.message} on channel: ${msg.channel}');
});
// Run for a while and cancel subscription when done.
await Future.delayed(const Duration(seconds: 30));
await subClient.close();
await subscription.cancel();
}
Commands Implementation Status #
The implementation status of the Valkey commands is shown below, as indicated in the official documentation. Commands marked with [x] are implemented, while those marked with [ ] are not yet implemented.
Bitmap Operations #
Bloom filter Operations #
- ❌ BF.ADD
- ❌ BF.CARD
- ❌ BF.EXISTS
- ❌ BF.INFO
- ❌ BF.INSERT
- ❌ BF.LOAD
- ❌ BF.MADD
- ❌ BF.MEXISTS
- ❌ BF.RESERVE
Cluster #
- ❌ ASKING
- ❌ CLUSTER ADDSLOTS
- ❌ CLUSTER ADDSLOTSRANGE
- ❌ CLUSTER BUMPEPOCH
- ❌ CLUSTER COUNT-FAILURE-REPORTS
- ❌ CLUSTER COUNTKEYSINSLOT
- ❌ CLUSTER DELSLOTS
- ❌ CLUSTER DELSLOTSRANGE
- ❌ CLUSTER FAILOVER
- ❌ CLUSTER FLUSHSLOTS
- ❌ CLUSTER FORGET
- ❌ CLUSTER GETKEYSINSLOT
- ❌ CLUSTER HELP
- ❌ CLUSTER INFO
- ❌ CLUSTER KEYSLOT
- ❌ CLUSTER LINKS
- ❌ CLUSTER MEET
- ❌ CLUSTER MYID
- ❌ CLUSTER MYSHARDID
- ❌ CLUSTER NODES
- ❌ CLUSTER REPLICAS
- ❌ CLUSTER REPLICATE
- ❌ CLUSTER RESET
- ❌ CLUSTER SAVECONFIG
- ❌ CLUSTER SET-CONFIG-EPOCH
- ❌ CLUSTER SETSLOT
- ❌ CLUSTER SHARDS
- ❌ CLUSTER SLAVES
- ❌ CLUSTER SLOT-STATS
- ❌ CLUSTER SLOTS
- ❌ READONLY
- ❌ READWRITE
Connection #
- ✅ AUTH
- ✅ CLIENT CACHING
- ✅ CLIENT CAPA
- ✅ CLIENT GETNAME
- ✅ CLIENT GETREDIR
- ✅ CLIENT HELP
- ✅ CLIENT ID
- ✅ CLIENT IMPORT-SOURCE
- ✅ CLIENT INFO
- ✅ CLIENT KILL
- ✅ CLIENT LIST
- ✅ CLIENT NO-EVICT
- ✅ CLIENT NO-TOUCH
- ✅ CLIENT PAUSE
- ✅ CLIENT REPLY
- ✅ CLIENT SETINFO
- ✅ CLIENT SETNAME
- ✅ CLIENT TRACKING
- ✅ CLIENT TRACKINGINFO
- ✅ CLIENT UNBLOCK
- ✅ CLIENT UNPAUSE
- ✅ ECHO
- ✅ HELLO
- ✅ PING
- ✅ QUIT
- ✅ RESET
- ✅ SELECT
Generic #
- ❌ COPY
- ✅ DEL
- ❌ DUMP
- ✅ EXISTS
- ✅ EXPIRE
- ❌ EXPIREAT
- ❌ EXPIRETIME
- ❌ KEYS
- ❌ MIGRATE
- ❌ MOVE
- ❌ OBJECT ENCODING
- ❌ OBJECT FREQ
- ❌ OBJECT HELP
- ❌ OBJECT IDLETIME
- ❌ OBJECT REFCOUNT
- ✅ PERSIST
- ❌ PEXPIRE
- ❌ PEXPIREAT
- ❌ PEXPIRETIME
- ❌ PTTL
- ❌ RANDOMKEY
- ✅ RENAME
- ✅ RENAMENX
- ❌ RESTORE
- ❌ SCAN
- ❌ SORT
- ❌ SORT_RO
- ❌ TOUCH
- ✅ TTL
- ✅ TYPE
- ❌ UNLINK
- ❌ WAIT
- ❌ WAITAOF
Geospatial indices #
- ❌ GEOADD
- ❌ GEODIST
- ❌ GEOHASH
- ❌ GEOPOS
- ❌ GEORADIUS
- ❌ GEORADIUSBYMEMBER
- ❌ GEORADIUSBYMEMBER_RO
- ❌ GEORADIUS_RO
- ❌ GEOSEARCH
- ❌ GEOSEARCHSTORE
Hash Operations #
- ✅ HDEL
- ✅ HEXISTS
- ✅ HGET
- ✅ HGETALL
- ✅ HINCRBY
- ✅ HINCRBYFLOAT
- ✅ HKEYS
- ✅ HLEN
- ✅ HMGET
- ✅ HMSET
- ❌ HRANDFIELD
- ❌ HSCAN
- ✅ HSET
- ✅ HSETNX
- ✅ HSTRLEN
- ✅ HVALS
HyperLogLog #
- ❌ PFADD
- ❌ PFCOUNT
- ❌ PFDEBUG
- ❌ PFMERGE
- ❌ PFSELFTEST
JSON Operations #
- ❌ JSON.ARRAPPEND
- ❌ JSON.ARRINDEX
- ❌ JSON.ARRINSERT
- ❌ JSON.ARRLEN
- ❌ JSON.ARRPOP
- ❌ JSON.ARRTRIM
- ❌ JSON.CLEAR
- ❌ JSON.DEBUG
- ❌ JSON.DEL
- ❌ JSON.FORGET
- ❌ JSON.GET
- ❌ JSON.MGET
- ❌ JSON.MSET
- ❌ JSON.NUMINCRBY
- ❌ JSON.NUMMULTBY
- ❌ JSON.OBJKEYS
- ❌ JSON.OBJLEN
- ❌ JSON.RESP
- ❌ JSON.SET
- ❌ JSON.STRAPPEND
- ❌ JSON.STRLEN
- ❌ JSON.TOGGLE
- ❌ JSON.TYPE
List Operations #
- ❌ BLMOVE
- ❌ BLMPOP
- ❌ BLPOP
- ❌ BRPOP
- ❌ BRPOPLPUSH
- ✅ LINDEX
- ✅ LINSERT
- ✅ LLEN
- ❌ LMOVE
- ❌ LMPOP
- ✅ LPOP
- ❌ LPOS
- ✅ LPUSH
- ❌ LPUSHX
- ✅ LRANGE
- ✅ LREM
- ❌ LSET
- ✅ LTRIM
- ✅ RPOP
- ✅ RPOPLPUSH
- ✅ RPUSH
- ❌ RPUSHX
Pub/Sub #
- ✅ PSUBSCRIBE
- ✅ PUBLISH
- ✅ PUNSUBSCRIBE
- ✅ PUBSUB CHANNELS
- ✅ PUBSUB HELP
- ✅ PUBSUB NUMPAT
- ✅ PUBSUB NUMSUB
- ✅ PUBSUB SHARDCHANNELS
- ✅ PUBSUB SHARDNUMSUB
- ✅ SPUBLISH
- ✅ SSUBSCRIBE
- ✅ SUBSCRIBE
- ✅ SUNSUBSCRIBE
- ✅ UNSUBSCRIBE
Scripting and Functions #
- ❌ EVAL
- ❌ EVALSHA
- ❌ EVALSHA_RO
- ❌ EVAL_RO
- ❌ FCALL
- ❌ FCALL_RO
- ❌ FUNCTION DELETE
- ❌ FUNCTION DUMP
- ❌ FUNCTION FLUSH
- ❌ FUNCTION HELP
- ❌ FUNCTION KILL
- ❌ FUNCTION LIST
- ❌ FUNCTION LOAD
- ❌ FUNCTION RESTORE
- ❌ FUNCTION STATS
- ❌ SCRIPT DEBUG
- ❌ SCRIPT EXISTS
- ❌ SCRIPT FLUSH
- ❌ SCRIPT HELP
- ❌ SCRIPT KILL
- ❌ SCRIPT LOAD
- ❌ SCRIPT SHOW
Search #
- ❌ FT.CREATE
- ❌ FT.DROPINDEX
- ❌ FT.INFO
- ❌ FT.SEARCH
- ❌ FT._LIST
Server #
- ❌ ACL CAT
- ❌ ACL DELUSER
- ❌ ACL DRYRUN
- ❌ ACL GENPASS
- ❌ ACL GETUSER
- ❌ ACL HELP
- ❌ ACL LIST
- ❌ ACL LOAD
- ❌ ACL LOG
- ❌ ACL SAVE
- ❌ ACL SETUSER
- ❌ ACL USERS
- ❌ ACL WHOAMI
- ❌ BGREWRITEAOF
- ❌ BGSAVE
- ❌ COMMAND COUNT
- ❌ COMMAND DOCS
- ❌ COMMAND GETKEYS
- ❌ COMMAND GETKEYSANDFLAGS
- ❌ COMMAND HELP
- ❌ COMMAND INFO
- ❌ COMMAND LIST
- ❌ COMMANDLOG GET
- ❌ COMMANDLOG HELP
- ❌ COMMANDLOG LEN
- ❌ COMMANDLOG RESET
- ❌ CONFIG GET
- ❌ CONFIG HELP
- ❌ CONFIG RESETSTAT
- ❌ CONFIG REWRITE
- ❌ CONFIG SET
- ❌ DBSIZE
- ❌ DEBUG
- ❌ FAILOVER
- ❌ FLUSHALL
- ❌ FLUSHDB
- ❌ INFO
- ❌ LASTSAVE
- ❌ LATENCY DOCTOR
- ❌ LATENCY GRAPH
- ❌ LATENCY HELP
- ❌ LATENCY HISTOGRAM
- ❌ LATENCY HISTORY
- ❌ LATENCY LATEST
- ❌ LATENCY RESET
- ❌ LOLWUT
- ❌ MEMORY DOCTOR
- ❌ MEMORY HELP
- ❌ MEMORY MALLOC-STATS
- ❌ MEMORY PURGE
- ❌ MEMORY STATS
- ❌ MEMORY USAGE
- ❌ MODULE HELP
- ❌ MODULE LIST
- ❌ MODULE LOAD
- ❌ MODULE LOADEX
- ❌ MODULE UNLOAD
- ❌ MONITOR
- ❌ PSYNC
- ❌ REPLCONF
- ❌ REPLICAOF
- ❌ RESTORE-ASKING
- ❌ ROLE
- ❌ SAVE
- ❌ SHUTDOWN
- ❌ SLAVEOF
- ❌ SLOWLOG GET
- ❌ SLOWLOG HELP
- ❌ SLOWLOG LEN
- ❌ SLOWLOG RESET
- ❌ SWAPDB
- ❌ SYNC
- ❌ TIME
Set Operations #
- ✅ SADD
- ✅ SCARD
- ✅ SDIFF
- ✅ SDIFFSTORE
- ✅ SINTER
- ❌ SINTERCARD
- ✅ SINTERSTORE
- ✅ SISMEMBER
- ✅ SMEMBERS
- ❌ SMISMEMBER
- ✅ SMOVE
- ✅ SPOP
- ✅ SRANDMEMBER
- ✅ SREM
- ❌ SSCAN
- ✅ SUNION
- ✅ SUNIONSTORE
Sorted Set Operations #
- ✅ ZADD
- ❌ BZMPOP
- ❌ BZPOPMAX
- ❌ BZPOPMIN
- ✅ ZCARD
- ✅ ZCOUNT
- ❌ ZDIFF
- ❌ ZDIFFSTORE
- ✅ ZINCRBY
- ❌ ZINTER
- ❌ ZINTERCARD
- ❌ ZINTERSTORE
- ❌ ZLEXCOUNT
- ❌ ZMPOP
- ❌ ZMSCORE
- ❌ ZPOPMAX
- ❌ ZPOPMIN
- ❌ ZRANDMEMBER
- ✅ ZRANGE
- ❌ ZRANGEBYLEX
- ✅ ZRANGEBYSCORE
- ❌ ZRANGESTORE
- ✅ ZRANK
- ✅ ZREM
- ❌ ZREMRANGEBYLEX
- ❌ ZREMRANGEBYRANK
- ❌ ZREMRANGEBYSCORE
- ✅ ZREVRANGE
- ❌ ZREVRANGEBYLEX
- ✅ ZREVRANGEBYSCORE
- ✅ ZREVRANK
- ❌ ZSCAN
- ✅ ZSCORE
- ❌ ZUNION
- ❌ ZUNIONSTORE
Stream Operations #
- ❌ XACK
- ❌ XADD
- ❌ XAUTOCLAIM
- ❌ XCLAIM
- ❌ XDEL
- ❌ XGROUP CREATE
- ❌ XGROUP CREATECONSUMER
- ❌ XGROUP DELCONSUMER
- ❌ XGROUP DESTROY
- ❌ XGROUP HELP
- ❌ XGROUP SETID
- ❌ XINFO CONSUMERS
- ❌ XINFO GROUPS
- ❌ XINFO HELP
- ❌ XINFO STREAM
- ❌ XLEN
- ❌ XPENDING
- ❌ XRANGE
- ❌ XREAD
- ❌ XREADGROUP
- ❌ XREVRANGE
- ❌ XSETID
- ❌ XTRIM
String Operations #
- ✅ APPEND
- ❌ BITCOUNT
- ❌ BITFIELD
- ✅ DECR
- ✅ DECRBY
- ❌ DELIFEQ
- ✅ GET
- ❌ GETBIT
- ❌ GETDEL
- ❌ GETEX
- ✅ GETRANGE
- ✅ GETSET
- ✅ INCR
- ✅ INCRBY
- ❌ INCRBYFLOAT
- ❌ LCS
- ✅ MGET
- ✅ MSET
- ❌ MSETNX
- ❌ PSETEX
- ✅ SET
- ❌ SETBIT
- ❌ SETEX
- ❌ SETNX
- ✅ SETRANGE
- ✅ STRLEN
- ❌ SUBSTR
Transactions #
Contributing #
Contributions are welcome!
Feel free to open issues or submit pull requests on our repository.