diff --git a/lib/src/redis_service.dart b/lib/src/redis_service.dart index 40d35b2a..b160974f 100644 --- a/lib/src/redis_service.dart +++ b/lib/src/redis_service.dart @@ -4,6 +4,7 @@ import 'package:angel_framework/angel_framework.dart'; import 'package:resp_client/resp_client.dart'; import 'package:resp_client/resp_commands.dart'; +/// An Angel service that reads and writes JSON within a Redis store. class RedisService extends Service> { final RespCommands respCommands; @@ -47,6 +48,14 @@ class RedisService extends Service> { return data; } + @override + Future> modify(String id, Map data, + [Map params]) async { + var input = await read(id); + input.addAll(data); + return await update(id, input, params); + } + @override Future> update(String id, Map data, [Map params]) async { diff --git a/test/all_test.dart b/test/all_test.dart index 795ace67..11e4a8cb 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -36,11 +36,19 @@ main() async { expect(await service.read(id), input); }); + test('modify', () async { + var id = 'jamboree${new DateTime.now().millisecondsSinceEpoch}'; + await service.create({'id': id, 'bar': 'baz', 'yes': 'no'}); + var output = await service.modify(id, {'bar': 'quux'}); + expect(output, {'id': id, 'bar': 'quux', 'yes': 'no'}); + expect(await service.read(id), output); + }); + test('update', () async { var id = 'hoopla${new DateTime.now().millisecondsSinceEpoch}'; await service.create({'id': id, 'bar': 'baz'}); - var output = await service.update(id, {'bar': 'quux'}); - expect(output, {'id': id, 'bar': 'quux'}); + var output = await service.update(id, {'yes': 'no'}); + expect(output, {'id': id, 'yes': 'no'}); expect(await service.read(id), output); });