putMany<T> method
Stores all entries from object. The optional ttl applies uniformly
to every entry; pass null to skip expiration.
Implementation
@override
Future<void> putMany<T>(Map<String, T> objects, {Duration? ttl}) async {
// MSET cannot carry an expiration, so when any entry has a TTL we issue
// one SET … PX per key. Without TTL we keep the single MSET round-trip.
final keyTtls = {
for (final key in objects.keys) key: ttl ?? _ttlPolicy.ttlFor(key),
};
final hasAnyTtl =
keyTtls.values.any((d) => d != null && d > Duration.zero);
if (!hasAnyTtl) {
final encoded = {
for (final entry in objects.entries) entry.key: jsonEncode(entry.value),
};
await Command(_connection).send_object(buildMsetCommand(encoded));
return;
}
for (final entry in objects.entries) {
await Command(_connection).send_object(
buildSetCommand(entry.key, jsonEncode(entry.value), keyTtls[entry.key]),
);
}
}