diff --git a/lib/command.dart b/lib/command.dart index 68da28e..1c16c60 100644 --- a/lib/command.dart +++ b/lib/command.dart @@ -23,16 +23,15 @@ class Command { this.serializer = other.serializer; } - Command setParser(Parser p){ + Command setParser(Parser p) { this.parser = p; return this; } - Command setSerializer(Serializer s){ + Command setSerializer(Serializer s) { this.serializer = s; return this; } - /// Serialize and send data to server /// @@ -44,7 +43,7 @@ class Command { /// send_object(["SET","key","value"]); Future send_object(Object obj) { try { - return _connection._sendraw(parser,serializer.serialize(obj)).then((v) { + return _connection._sendraw(parser, serializer.serialize(obj)).then((v) { // turn RedisError into exception if (v is RedisError) { return Future.error(v); diff --git a/lib/connection.dart b/lib/connection.dart index 776161a..791661e 100644 --- a/lib/connection.dart +++ b/lib/connection.dart @@ -71,7 +71,7 @@ class RedisConnection { } // ignore: unused_element - Future _sendraw(Parser parser,List data) { + Future _sendraw(Parser parser, List data) { _socket!.add(data); return _senddummy(parser); } diff --git a/lib/exceptions.dart b/lib/exceptions.dart index 9f3fab7..2167050 100644 --- a/lib/exceptions.dart +++ b/lib/exceptions.dart @@ -9,27 +9,35 @@ part of redis; - // this class is returned when redis response is type error -class RedisError { +class RedisError { String e; RedisError(this.e); - String toString() { return "RedisError($e)";} + String toString() { + return "RedisError($e)"; + } + String get error => e; } // thiss class is returned when parsing in client side (aka this libraray) // get error -class RedisRuntimeError { +class RedisRuntimeError { String e; RedisRuntimeError(this.e); - String toString() { return "RedisRuntimeError($e)";} + String toString() { + return "RedisRuntimeError($e)"; + } + String get error => e; } -class TransactionError { +class TransactionError { String e; TransactionError(this.e); - String toString() { return "TranscationError($e)";} - String get error => e; + String toString() { + return "TranscationError($e)"; + } + + String get error => e; } diff --git a/lib/lazystream.dart b/lib/lazystream.dart index d2129bc..6c1eff3 100644 --- a/lib/lazystream.dart +++ b/lib/lazystream.dart @@ -49,7 +49,7 @@ class StreamNext { // close socket on error // follow bug https://github.com/ra1u/redis-dart/issues/49 // and bug https://github.com/dart-lang/sdk/issues/47538 - socket.close().then((_){ + socket.close().then((_) { if (_nfut >= 1) { _nfut = 0; for (Completer> e in _queue) { diff --git a/lib/redis.dart b/lib/redis.dart index 5e1fd6a..883f1fb 100644 --- a/lib/redis.dart +++ b/lib/redis.dart @@ -7,7 +7,6 @@ * Luka Rahne */ - library redis; import 'dart:io'; @@ -24,4 +23,3 @@ part './command.dart'; part './pubsub.dart'; part './cas.dart'; part './exceptions.dart'; - diff --git a/lib/redisparser.dart b/lib/redisparser.dart index 1963f50..5e187b3 100644 --- a/lib/redisparser.dart +++ b/lib/redisparser.dart @@ -9,9 +9,7 @@ part of redis; -class RedisParser extends Parser { - -} +class RedisParser extends Parser {} class RedisParserBulkBinary extends Parser { Future parseBulk(LazyStream s) { @@ -21,17 +19,17 @@ class RedisParserBulkBinary extends Parser { return null; if (i >= 0) { //i of bulk data - return s.take_n(i).then((lst) => takeCRLF( - s, lst)); //consume CRLF and return list + return s + .take_n(i) + .then((lst) => takeCRLF(s, lst)); //consume CRLF and return list } else { return Future.error( RedisRuntimeError("cant process buld data less than -1")); } }); - } + } } - class Parser { static final UTF8 = const Utf8Codec(); static const int CR = 13; @@ -72,10 +70,10 @@ class Parser { }); } - Future parse(LazyStream s){ + Future parse(LazyStream s) { return parseredisresponse(s); } - + Future parseredisresponse(LazyStream s) { return s.take_n(1).then((list) { int cmd = list[0]; diff --git a/lib/redisserialise.dart b/lib/redisserialise.dart index 829ebd1..ef9062d 100644 --- a/lib/redisserialise.dart +++ b/lib/redisserialise.dart @@ -21,11 +21,10 @@ class RedisBulk { typedef Consumer = void Function(Iterable s); - class Serializer { - List serialize(Object? object){ + List serialize(Object? object) { return RedisSerialize.Serialize(object); - } + } } class RedisSerialize { diff --git a/lib/transaction.dart b/lib/transaction.dart index 8953e5c..fde762d 100644 --- a/lib/transaction.dart +++ b/lib/transaction.dart @@ -38,7 +38,9 @@ class Transaction extends Command { c.completeError( RedisError("Could not enqueue command: " + msg.toString())); } - }).catchError((error){ c.completeError(error); }); + }).catchError((error) { + c.completeError(error); + }); return c.future; } diff --git a/test/binary_parser_test.dart b/test/binary_parser_test.dart index 593ccf8..18b9bf2 100644 --- a/test/binary_parser_test.dart +++ b/test/binary_parser_test.dart @@ -4,11 +4,10 @@ import 'package:test/test.dart'; import 'main.dart'; import 'dart:math'; - -List _gen_rnd_array(Random rng){ +List _gen_rnd_array(Random rng) { int len = 1 + rng.nextInt(1000); - List r = List.filled(len,0); - for(int i=0;i r = List.filled(len, 0); + for (int i = 0; i < len; ++i) { r[i] = rng.nextInt(255); } return r; @@ -22,18 +21,18 @@ void main() { Command _cmd = await generate_connect(); Command cmd_bin = Command.from(_cmd).setParser(RedisParserBulkBinary()); - List d = [1,2,3,4,5,6,7,8,9]; + List d = [1, 2, 3, 4, 5, 6, 7, 8, 9]; var r = await cmd_bin.send_object(["SET", key, RedisBulk(d)]); expect(r, equals("OK")); expect(await cmd_bin.send_object(["GET", key]), equals(d)); }); - + test("binary with randomly generated data", () async { Command _cmd = await generate_connect(); Command cmd_bin = Command.from(_cmd).setParser(RedisParserBulkBinary()); - var rng = Random(); + var rng = Random(); - for(int i = 0;i < 1000; ++i){ + for (int i = 0; i < 1000; ++i) { List d = _gen_rnd_array(rng); var r = await cmd_bin.send_object(["SET", key, RedisBulk(d)]); expect(r, equals("OK")); diff --git a/test/close_test.dart b/test/close_test.dart index 6a7b1f5..8949c3a 100644 --- a/test/close_test.dart +++ b/test/close_test.dart @@ -22,7 +22,7 @@ main() { }); test("Open/Close in loop", () async { - for( int i=0;i<1000;++i) { + for (int i = 0; i < 1000; ++i) { Command cmd = await generate_connect(); await cmd.send_object(["SET", "test", "0"]); await cmd.get_connection().close(); diff --git a/test/conversion_test.dart b/test/conversion_test.dart index 2167189..4ef0ea8 100644 --- a/test/conversion_test.dart +++ b/test/conversion_test.dart @@ -10,5 +10,4 @@ void main() { expect(cmd.send_object(["SADD", "test_list", 1]), completion(isA())); }); }); - -} \ No newline at end of file +} diff --git a/test/lua_test.dart b/test/lua_test.dart index f1fbbef..41de318 100644 --- a/test/lua_test.dart +++ b/test/lua_test.dart @@ -7,14 +7,17 @@ void main() { test("Test Lua Native", () async { Command cmd = await generate_connect(); - expect((await cmd.send_object([ - "EVAL", - "return {KEYS[1],{KEYS[2],{ARGV[1]},ARGV[2]},2}", - "2", - "key1", - "key2", - "first", - "2" - ])).toString(), equals("[key1, [key2, [first], 2], 2]")); + expect( + (await cmd.send_object([ + "EVAL", + "return {KEYS[1],{KEYS[2],{ARGV[1]},ARGV[2]},2}", + "2", + "key1", + "key2", + "first", + "2" + ])) + .toString(), + equals("[key1, [key2, [first], 2], 2]")); }); } diff --git a/test/main.dart b/test/main.dart index 573c899..7594f49 100644 --- a/test/main.dart +++ b/test/main.dart @@ -19,14 +19,13 @@ int g_db_port = 0; void init_db_vars() { // read REDIS_URL and REDIS_PORT from ENV and store in globals for faster retreival - if(g_redis_initialsed) - return; + if (g_redis_initialsed) return; Map envVars = Platform.environment; g_db_uri = envVars["REDIS_URL"] ?? "localhost"; String port = envVars["REDIS_PORT"] ?? "6379"; g_db_port = int.tryParse(port) ?? 6379; g_redis_initialsed = true; -} +} Future generate_connect() { init_db_vars(); diff --git a/test/pubsub_test.dart b/test/pubsub_test.dart index 2faaa69..d0fe001 100644 --- a/test/pubsub_test.dart +++ b/test/pubsub_test.dart @@ -7,8 +7,7 @@ void main() async { Command cmdP = await generate_connect(); Command cmdS = await generate_connect(); - group("Test Redis Pub-Sub", () { - + group("Test Redis Pub-Sub", () { PubSub subscriber = PubSub(cmdS); test("Publishing to channel before subscription", () { @@ -58,18 +57,17 @@ void main() async { "Publishing a message after unsubscribe should be received by zero clients."); // TODO: Multiple channels, Pattern (un)subscribe - }); - - test("Test close", () async { - // test that we can close connection - // creates new connection as prevously used in test - // does not expect errors - Command cmdClose = await generate_connect(); - PubSub ps_c = PubSub(cmdClose); - cmdClose.get_connection().close(); - expect(ps_c.getStream(), - emitsError(anything), // todo catch CloseError - reason: "Number of subscribers should be 0 after unsubscribe"); - }); + }); + + test("Test close", () async { + // test that we can close connection + // creates new connection as prevously used in test + // does not expect errors + Command cmdClose = await generate_connect(); + PubSub ps_c = PubSub(cmdClose); + cmdClose.get_connection().close(); + expect(ps_c.getStream(), emitsError(anything), // todo catch CloseError + reason: "Number of subscribers should be 0 after unsubscribe"); + }); }); } diff --git a/test/unicode_test.dart b/test/unicode_test.dart index a2628fb..e88e25f 100644 --- a/test/unicode_test.dart +++ b/test/unicode_test.dart @@ -9,7 +9,6 @@ void main() { Command cmd = await generate_connect(); String unicodeString = "中华人民共和😊👍📱😀😬"; - expect(cmd.send_object(["SET", "unicode_test", unicodeString]), completion(equals("OK"))); @@ -17,4 +16,4 @@ void main() { completion(equals(unicodeString))); }); }); -} \ No newline at end of file +}