Skip to content

Pass redis connection to HttpProxy #478

Answered by vstepanyuk
iluxav asked this question in Q&A
Discussion options

You must be logged in to vote

You had issues because you tried to mutate a Redis connection stored in &self. Switching to deadpool-redis fixed that by letting you grab a connection dynamically. Here’s the fix:

Cargo.toml:

[package]
name = "pi"
version = "0.1.0"
edition = "2021"

[dependencies]
async-trait = "0.1.83"
deadpool-redis = "0.18.0"
pingora = { version = "0.4.0", features = ["lb"] }

main.rs:

use async_trait::async_trait;
use deadpool_redis::{redis::cmd, Config, Pool, Runtime};
use pingora::prelude::*;

pub struct Proxy {
    pool: Pool,
}

impl Proxy {
    fn new() -> Self {
        let cfg = Config::from_url("redis://127.0.0.1:6379");
        let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap();

        

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vstepanyuk
Comment options

Answer selected by iluxav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants