dartist / redis_client

A high-performance async/non-blocking Redis client for Dart
BSD 2-Clause "Simplified" License
100 stars 29 forks source link

Connection fail on Dart SDK version 1.0.0.10_r30798 #39

Closed caxelrud closed 10 years ago

caxelrud commented 10 years ago

I am using Windows 8.1. I tried a simple connection example below but the connection always return null. Redis is working with Redis-cli.exe. There is no password and the port is correct. I started Dart Editor as an Administration. Also, I can connect from node.js applications. The same problem happen if you tried to connect using the other dart library (redis-cli.dart). Am I missing any Dart configuration?

import "package:redis_client/redis_client.dart"; main() { RedisConnection connection; RedisConnection.connect("127.0.0.1:6379") .then((c) => connection = c); connection.close(); }

bbss commented 10 years ago

Because a connection is async it returns a future. This means the code gets run and the callback in .then() only gets executed after the connection returns. You want to rewrite your example to:

import "package:redis_client/redis_client.dart";

main() {
  RedisConnection connection;
  RedisConnection.connect("127.0.0.1:6379")
  .then((c) { 
    connection = c;
    connection.close();
  } );

}

Of course that would render the connection useless because you close it as soon as it's available and set.

You should be using the RedisClient though, unless you have a specific reason to be using the connection only.