Remove works

This commit is contained in:
Tobe O 2018-10-21 12:41:23 -04:00
parent f1782c581f
commit 7137dcad5b
2 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart'; import 'package:resp_client/resp_commands.dart';
class RedisService extends Service<String, Map<String, dynamic>> { class RedisService extends Service<String, Map<String, dynamic>> {
@ -58,6 +59,11 @@ class RedisService extends Service<String, Map<String, dynamic>> {
Future<Map<String, dynamic>> remove(String id, Future<Map<String, dynamic>> remove(String id,
[Map<String, dynamic> params]) async { [Map<String, dynamic> params]) async {
var client = respCommands.client; var client = respCommands.client;
throw await client.writeArrayOfBulk(['MULTI']); await client.writeArrayOfBulk(['MULTI']);
await client.writeArrayOfBulk(['GET', _applyPrefix(id)]);
await client.writeArrayOfBulk(['DEL', _applyPrefix(id)]);
var result = await client.writeArrayOfBulk(['EXEC']);
var str = result.payload[0] as RespBulkString;
return json.decode(str.payload);
} }
} }

View file

@ -42,4 +42,10 @@ main() async {
expect(output, {'id': id, 'bar': 'quux'}); expect(output, {'id': id, 'bar': 'quux'});
expect(await service.read(id), output); expect(await service.read(id), output);
}); });
test('remove', () async {
var id = 'gelatin${new DateTime.now().millisecondsSinceEpoch}';
var input = await service.create({'id': id, 'bar': 'baz'});
expect(await service.remove(id), input);
});
} }