-
-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of redis subscribe/psubscribe #258
Comments
See also: actix/actix-redis#20 |
@GopherJ actix-redis publish example use actix::Addr;
use redis_async::resp_array;
use actix_redis::{Command, RedisActor};
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
#[actix_web::get("/")]
async fn cache_stuff(
redis: web::Data<Addr<RedisActor>>
) -> HttpResponse {
let datetime_now: String = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
let _future = redis.send(Command(resp_array!["PUBLISH", "test", datetime_now.as_str()])).await;
HttpResponse::Ok().body(format!("successfully publish {message} to `test` channel", message = datetime_now))
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=trace,actix_redis=trace");
env_logger::init();
HttpServer::new(|| {
App::new()
.data(RedisActor::start("127.0.0.1:6379"))
.wrap(middleware::Logger::default())
.service(cache_stuff)
})
.bind("0.0.0.0:8080")?
.run()
.await
}
|
@pymongo hello, what's really needed is subscribe and psubscribe |
@GopherJ actix-redis depend on redis-async, you can check out pubsub example in redis-async/examples/pubsub.rs |
@pymongo I already checked them before creating this issue and that's also why I created this issue, because we should have a way to subscribe/publish. |
I also encounter this problem. Is there a plan to improve it? |
@GopherJ |
Hello guys, is there a way to use redis
subscribe/psubscribe
in actix + actix-web system?I don't want to create a seperate thread for handling this, is there a better way to do this?
The text was updated successfully, but these errors were encountered: