redis-async-rs icon indicating copy to clipboard operation
redis-async-rs copied to clipboard

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

Open Json1949 opened this issue 4 years ago • 6 comments

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 = "*"

Json1949 avatar Apr 01 '21 07:04 Json1949

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.

nazar-pc avatar Apr 09 '21 12:04 nazar-pc

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.

benashford avatar Apr 12 '21 08:04 benashford

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

jesse996 avatar May 01 '21 07:05 jesse996

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.

benashford avatar May 04 '21 20:05 benashford

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.

nazar-pc avatar May 04 '21 20:05 nazar-pc

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

Json1949 avatar May 11 '21 10:05 Json1949