benashford / redis-async-rs

A Rust client for Redis, using Tokio
Apache License 2.0
253 stars 30 forks source link

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.4.0/src/runtime/context.rs:37:26 #68

Open Json1949 opened 3 years ago

Json1949 commented 3 years ago

main.rs

let main_redis = redis_async::client::paired_connect("172.0.0.1:6800".parse().unwrap()).await.unwrap();

Cargo.toml

[dependencies]
actix-web = "*"
async-trait = "*"

redis-async = "*"

sqlx = { version = "0.4.1", features = [ 'runtime-actix-rustls', "mysql" ] }
async-std = { version = "1.6", features = [ "attributes" ] }

#redis = { version = "0.19.0", features = ["async-std-tls-comp"] }

serde = { version = "*", features = ["derive"] }
serde_json = "*"
nazar-pc commented 3 years ago

You need to run this under Tokio 1.0 like error says. According to Cargo.toml and incomplete main.rs you might be running it under async-std runtime instead.

benashford commented 3 years ago

Yes, this looks to be the case.

I do have experimental support for async-std in a branch, but this isn't ready yet. The current default is Tokio 1.x, but there is also support for Tokio 0.2 behind a feature flag if necessary.

jesse996 commented 3 years ago

same problem,i also use it in actix_web,and get this error

benashford commented 3 years ago

Hello, unfortunately I'm not familiar with Actix Web, but @nazar-pc 's comment above is correct in the sense this error means that a Tokio runtime isn't running which is required for this library to work.

So I'm guessing something has recently changed with Actix Web, perhaps allowing it to run under different async runtimes?

But if Actix is still Tokio based then something else is going on.

nazar-pc commented 3 years ago

Actix-web 3.x uses Tokio 0.2, while 4.x (which is beta currently) switched to Tokio 1.0. Just pick versions correctly, there is nothing to do about it in this crate.

Json1949 commented 3 years ago

You need to run this under Tokio 1.0 like error says. According to Cargo.toml and incomplete main.rs you might be running it under async-std runtime instead.

ok