diff --git a/.gitignore b/.gitignore index 7dcfd960..d220238f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # If you don't generate documentation locally you can remove this line. doc/api/ .dart_tool +dump.rdb diff --git a/lib/src/redis_service.dart b/lib/src/redis_service.dart index 9d13ccff..40d35b2a 100644 --- a/lib/src/redis_service.dart +++ b/lib/src/redis_service.dart @@ -64,6 +64,11 @@ class RedisService extends Service> { await client.writeArrayOfBulk(['DEL', _applyPrefix(id)]); var result = await client.writeArrayOfBulk(['EXEC']); var str = result.payload[0] as RespBulkString; - return json.decode(str.payload); + + if (str.payload == null) + throw new AngelHttpException.notFound( + message: 'No record found for ID $id'); + else + return json.decode(str.payload); } } diff --git a/test/all_test.dart b/test/all_test.dart index a95363ba..795ace67 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -1,3 +1,4 @@ +import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:angel_redis/angel_redis.dart'; import 'package:resp_client/resp_client.dart'; import 'package:resp_client/resp_commands.dart'; @@ -47,5 +48,11 @@ main() async { var id = 'gelatin${new DateTime.now().millisecondsSinceEpoch}'; var input = await service.create({'id': id, 'bar': 'baz'}); expect(await service.remove(id), input); + expect(await service.respCommands.exists([id]), 0); + }); + + test('remove nonexistent', () async { + expect(() => service.remove('definitely_does_not_exist'), + throwsA(const TypeMatcher())); }); }