From 932c8841adc0e3156144e1675c06fdae72e1bcd6 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 21 Oct 2018 13:04:21 -0400 Subject: [PATCH] Done --- lib/src/redis_service.dart | 9 +++++++++ test/all_test.dart | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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); });