Skip to content

Commit

Permalink
fix: add url encode for username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
suxb201 committed Aug 22, 2024
1 parent 81483b4 commit 79982cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ awaitgroup = "0.7.0"
colored = "2.1.0"
enum_delegate = "0.2.0"
ctrlc = "3.4.4"
urlencoding = "2.1.3"
7 changes: 5 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use redis::aio::MultiplexedConnection;
use redis::cluster_async::ClusterConnection;
use redis::{Cmd, RedisFuture, Value};
use std::fmt::{Display, Formatter};
use urlencoding::encode;

#[derive(Clone)]
pub struct ClientConfig {
Expand All @@ -17,10 +18,12 @@ pub struct ClientConfig {

impl ClientConfig {
pub async fn get_client(&self) -> Client {
let username = encode(&self.username);
let password = encode(&self.password);
let conn_str = if self.tls {
format!("rediss://{}:{}@{}/#insecure", &self.username, &self.password, &self.address)
format!("rediss://{}:{}@{}/#insecure", username, password, &self.address)
} else {
format!("redis://{}:{}@{}", &self.username, &self.password, &self.address)
format!("redis://{}:{}@{}", username, password, &self.address)
};

if self.cluster {
Expand Down

0 comments on commit 79982cf

Please sign in to comment.