diff --git a/cspell.config.yaml b/cspell.config.yaml index 353698d7..d9544db0 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -45,7 +45,7 @@ words: - gradlew - hotreload - idevicesyslog - - incrbyfloat # From redis_client + - incrbyfloat # From ./packages/redis_client - iokit - iphoneos - keyalg # From .github/workflows/e2e.yaml @@ -66,6 +66,7 @@ words: - metadatas - mktemp - mocktail + - mset # From ./packages/redis_client - multioption - noaudio # From .github dir, doesn't show up in "**" check? - NOAUTH diff --git a/packages/redis_client/lib/src/redis_client.dart b/packages/redis_client/lib/src/redis_client.dart index 527bf253..baf04962 100644 --- a/packages/redis_client/lib/src/redis_client.dart +++ b/packages/redis_client/lib/src/redis_client.dart @@ -182,6 +182,17 @@ class RedisClient { ]); } + /// Sets the given keys to their respective values. MSET replaces existing + /// values with new values, just as regular SET. + /// Equivalent to the `MSET` command. + /// https://redis.io/commands/mset + Future mset({required List<({String key, String value})> pairs}) async { + return execute([ + 'MSET', + for (final pair in pairs) ...[pair.key, pair.value], + ]); + } + /// Gets the value of a key. /// Returns null if the key does not exist. /// Equivalent to the `GET` command. diff --git a/packages/redis_client/test/src/redis_client_test.dart b/packages/redis_client/test/src/redis_client_test.dart index a92f58c6..043f3108 100644 --- a/packages/redis_client/test/src/redis_client_test.dart +++ b/packages/redis_client/test/src/redis_client_test.dart @@ -252,19 +252,13 @@ void main() { }); }); - group('MGET', () { + group('MGET/MSET', () { final kvPairs = [ for (var i = 0; i < 10; i++) (key: 'key_$i', value: 'value_$i'), ]; setUp(() async { await client.connect(); - for (final pair in kvPairs) { - await expectLater( - client.set(key: pair.key, value: pair.value), - completes, - ); - } }); tearDown(() async { @@ -280,6 +274,7 @@ void main() { }); test('completes', () async { + await expectLater(client.mset(pairs: kvPairs), completes); await expectLater( client.mget(keys: kvPairs.map((pair) => pair.key).toList()), completion(equals(kvPairs.map((pair) => pair.value).toList())),