diff --git a/lib/src/redis_service.dart b/lib/src/redis_service.dart index b160974f..1651a73d 100644 --- a/lib/src/redis_service.dart +++ b/lib/src/redis_service.dart @@ -18,6 +18,20 @@ class RedisService extends Service> { String _applyPrefix(String id) => prefix == null ? id : '$prefix:$id'; + @override + Future>> index( + [Map params]) async { + var result = + await respCommands.client.writeArrayOfBulk(['KEYS', _applyPrefix('*')]); + var keys = result.payload.map((RespType s) => s.payload) as Iterable; + if (keys.isEmpty) return []; + result = await respCommands.client.writeArrayOfBulk(['MGET']..addAll(keys)); + return result.payload + .map>( + (RespType s) => json.decode(s.payload) as Map) + .toList(); + } + @override Future> read(String id, [Map params]) async { diff --git a/pubspec.yaml b/pubspec.yaml index fa8c400f..5acaf22e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,13 @@ name: angel_redis +version: 1.0.0 +description: An Angel service provider for Redis. Works well for caching volatile data. +author: Tobe O +homepage: https://github.com/angel-dart/redis +environment: + sdk: ">=2.0.0-dev <3.0.0" dependencies: angel_framework: ^2.0.0-alpha + angel_http_exception: ^1.0.0 resp_client: ^0.1.6 dev_dependencies: - test: ^1.0.0 \ No newline at end of file + test: ^1.0.0 diff --git a/test/all_test.dart b/test/all_test.dart index 11e4a8cb..8164ec2d 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -16,6 +16,18 @@ main() async { tearDown(() => connection.close()); + test('index', () async { + // Wipe + await service.respCommands.flushDb(); + await service.create({'id': '0', 'name': 'Tobe'}); + await service.create({'id': '1', 'name': 'Osakwe'}); + + var output = await service.index(); + expect(output, hasLength(2)); + expect(output[1], {'id': '0', 'name': 'Tobe'}); + expect(output[0], {'id': '1', 'name': 'Osakwe'}); + }); + test('create with id', () async { var input = {'id': 'foo', 'bar': 'baz'}; var output = await service.create(input);