Can we add Redis to Dart's get started web app?

Viewed 54

I want to write my own program. For that I chose the Dart language and I used the tutorial: get started with a web app

My program to work needs a de-serialization of the data coming from Redis. And for the moment here it blocks.

An external python program serialize data with JSON and use lpush to send data on Redis.

I have a compilation error on web server and I can't get out of it.

//library db.redis;
import 'dart:html';
import 'dart:convert';
import 'dart:core';
import 'package:redis/redis.dart';
//import 'package:redis_client/redis_client.dart';
//import 'package:redis';

Iterable<String> thingsTodo() sync* {
    yield "walk the dog";
    yield "wash the dog";
}

LIElement newLI(String itemText) => LIElement()..text = itemText;

void main() {
    querySelector('#output')?.children.addAll(thingsTodo().map(newLI));
    const jsonString = '{"text": "Your app is running", "value": 1, "status": false, "extra": null}';

    final data = jsonDecode(jsonString);
    final conn = RedisConnection();

    //final client = await conn.connect('localhost');
    //conn.connect('localhost', 6379).then((Command command){
    //    command.send_object(["SET","key","0"]).then((var response)
    //        print(response);
    //    )
    //}

    //final client = await RedisClient.connect('localhost');
    //await client.set('name', 'Gabriel');

    //var res = await client.get('name');
    //print(res);

    //await client.close();

    querySelector('#end').text = data['text'];
}

When I try to add Redis, I always get an error message on the console with the webdev serve command.

The last:

[WARNING] build_web_compilers:entrypoint on web/main.dart: Skipping
compiling quickstart|web/main.dart with ddc because some of its transitive libraries have SDK dependencies that not supported on this platform:

redis|lib/redis.dart

https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings

1 Answers

You are compiling dart for the web (to JavaScript and HTML). And redis package is not supported there.

If you are trying to build actual web page, you are probably out of luck.

But if you want a console app (which I suppose is correct), try this example instead. This will run script (program) on your system, instead of building web page.

Related