Is there a redis package for "Azure cache for Redis" in dart 2.9.2 (for flutter app) which takes hostname, port and its key in the connection string?

Viewed 334

I want to connect my Azure Cache for Redis in a flutter app. Currently I've tried two packages in dart for redis which are redis 1.3.0 and dartis 0.5.0.

Example:

import 'package:redis/redis.dart';
...
RedisConnection conn = new RedisConnection();
    conn
        .connect('localhost', 6379)
        .then((Command command) {
      print("yo2");
      command.send_object(["SET", "key1", "value1"]).then((var response) {
        print(response);
      });
    });

Instead of "localhost" I put "SampleName.redis.cache.windows.net". This is the error I get:

E/flutter ( 4861): [ERROR:flutter/shell/common/shell.cc(209)] Dart Error: Unhandled exception: E/flutter ( 4861): RedisError(NOAUTH Authentication required.)

old package This is the package starred on Redis Website. But it's incompatible on versions >2.

1 Answers

Okay so I found the solution. Use your key in the following way:

For redis 1.3.0:

...
 RedisConnection conn = new RedisConnection();
    conn
        .connect('SampleName.redis.cache.windows.net', 6379)
        .then((Command command) {
      print("yo2");
      command.send_object([
        "AUTH",
        "<YourKey>"
      ]).then((var response) {
        print(response);
      });

      command.send_object(["SET", "key1", "value1"]);
    });
...

And for dartis 0.5.0:

...
final client = await redis.Client.connect(
        'redis://SampleName.redis.cache.windows.net:6379');

    // Runs some commands.
    final commands = client.asCommands<String, String>();
    await commands.auth("<YourKey>");
    // SET key value
    await commands.set('yo', 'yovalue');
...
Related