index
This commit is contained in:
parent
932c8841ad
commit
0b3aff2baa
3 changed files with 34 additions and 1 deletions
|
@ -18,6 +18,20 @@ class RedisService extends Service<String, Map<String, dynamic>> {
|
|||
|
||||
String _applyPrefix(String id) => prefix == null ? id : '$prefix:$id';
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> index(
|
||||
[Map<String, dynamic> 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<Map<String, dynamic>>(
|
||||
(RespType s) => json.decode(s.payload) as Map<String, dynamic>)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> read(String id,
|
||||
[Map<String, dynamic> params]) async {
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
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
|
||||
test: ^1.0.0
|
||||
|
|
|
@ -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], <String, dynamic>{'id': '0', 'name': 'Tobe'});
|
||||
expect(output[0], <String, dynamic>{'id': '1', 'name': 'Osakwe'});
|
||||
});
|
||||
|
||||
test('create with id', () async {
|
||||
var input = {'id': 'foo', 'bar': 'baz'};
|
||||
var output = await service.create(input);
|
||||
|
|
Loading…
Reference in a new issue