Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ path-absolutize = "3"
pin-project-lite = "0.2.16"
quote = "1"
rand = "0.10.1"
redis = "0.32.5"
redis = "1.8"
regex = "1"
reqwest = { version = "0.12", features = ["stream", "blocking", "rustls-tls-native-roots"] }
rusqlite = "0.41"
Expand Down
62 changes: 28 additions & 34 deletions crates/factor-outbound-redis/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use crate::allowed_hosts::AllowedHostChecker;

const REDIS_CONNECTION_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);

const WRONG_TYPE: &str = "WRONGTYPE";

pub struct InstanceState {
pub(crate) allowed_host_checker: AllowedHostChecker,
pub blocked_networks: BlockedNetworks,
Expand Down Expand Up @@ -47,7 +49,7 @@ impl InstanceState {
.map_err(|_| v2::Error::TooManyConnections)?;
let config = AsyncConnectionConfig::new()
.set_dns_resolver(SpinDnsResolver(self.blocked_networks.clone()))
.set_connection_timeout(REDIS_CONNECTION_TIMEOUT);
.set_connection_timeout(Some(REDIS_CONNECTION_TIMEOUT));
let conn = redis::Client::open(address.as_str())
.map_err(|_| v2::Error::InvalidAddress)?
.get_multiplexed_async_connection_with_config(&config)
Expand Down Expand Up @@ -152,7 +154,7 @@ mod operations {
values: Vec<String>,
) -> Result<u32, v3::Error> {
let value = conn.sadd(&key, &values).await.map_err(|e| {
if e.kind() == redis::ErrorKind::TypeError {
if e.code().is_some_and(|c| c == WRONG_TYPE) {
v3::Error::TypeError
} else {
v3::Error::Other(e.to_string())
Expand Down Expand Up @@ -675,69 +677,61 @@ impl RedisResults {
}

impl FromRedisValue for RedisResults {
fn from_redis_value(value: &Value) -> redis::RedisResult<Self> {
fn append(values: &mut Vec<v3::RedisResult>, value: &Value) -> redis::RedisResult<()> {
fn from_redis_value(value: Value) -> Result<Self, redis::ParsingError> {
fn append(
values: &mut Vec<v3::RedisResult>,
value: Value,
) -> Result<(), redis::ParsingError> {
match value {
Value::Nil => {
values.push(v3::RedisResult::Nil);
Ok(())
}
Value::Int(v) => {
values.push(v3::RedisResult::Int64(*v));
values.push(v3::RedisResult::Int64(v));
Ok(())
}
Value::BulkString(bytes) => {
values.push(v3::RedisResult::Binary(bytes.to_owned()));
values.push(v3::RedisResult::Binary(bytes));
Ok(())
}
Value::SimpleString(s) => {
values.push(v3::RedisResult::Status(s.to_owned()));
values.push(v3::RedisResult::Status(s));
Ok(())
}
Value::Okay => {
values.push(v3::RedisResult::Status("OK".to_string()));
Ok(())
}
Value::Map(_) => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Could not convert Redis response",
"Redis Map type is not supported".to_string(),
))),
Value::Attribute { .. } => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Could not convert Redis response",
"Redis Attribute type is not supported".to_string(),
))),
Value::Map(_) => Err(redis::ParsingError::from("Redis Map type is not supported")),
Value::Attribute { .. } => Err(redis::ParsingError::from(
"Redis Attribute type is not supported",
)),
Value::Array(arr) | Value::Set(arr) => {
arr.iter().try_for_each(|value| append(values, value))
arr.into_iter().try_for_each(|value| append(values, value))
}
Value::Double(v) => {
values.push(v3::RedisResult::Binary(v.to_string().into_bytes()));
Ok(())
}
Value::VerbatimString { .. } => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Could not convert Redis response",
"Redis string with format attribute is not supported".to_string(),
))),
Value::VerbatimString { .. } => Err(redis::ParsingError::from(
"Redis string with format attribute is not supported",
)),
Value::Boolean(v) => {
values.push(v3::RedisResult::Int64(if *v { 1 } else { 0 }));
values.push(v3::RedisResult::Int64(if v { 1 } else { 0 }));
Ok(())
}
Value::BigNumber(v) => {
values.push(v3::RedisResult::Binary(v.to_string().as_bytes().to_owned()));
Ok(())
}
Value::Push { .. } => Err(redis::RedisError::from((
redis::ErrorKind::TypeError,
"Could not convert Redis response",
"Redis Pub/Sub types are not supported".to_string(),
))),
Value::ServerError(err) => Err(redis::RedisError::from((
redis::ErrorKind::ResponseError,
"Server error",
format!("{err:?}"),
))),
Value::Push { .. } => Err(redis::ParsingError::from(
"Redis Pub/Sub types are not supported",
)),
Value::ServerError(err) => {
Err(redis::ParsingError::from(format!("Server error: {err:?}")))
}
_ => Err(redis::ParsingError::from("Unknown Redis value type")),
}
}
let mut values = Vec::new();
Expand Down
9 changes: 6 additions & 3 deletions crates/key-value-redis/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl StoreManager for KeyValueRedis {
}

fn summary(&self, _store_name: &str) -> Option<String> {
let redis::ConnectionInfo { addr, .. } = self.database_url.as_str().parse().ok()?;
Some(format!("Redis at {addr}"))
let conn_info: redis::ConnectionInfo = self.database_url.as_str().parse().ok()?;
Some(format!("Redis at {}", conn_info.addr()))
}
}

Expand Down Expand Up @@ -159,7 +159,10 @@ impl Store for RedisStore {
loop {
match scan.next_item().await {
None => break,
Some(k) => {
Some(Err(e)) => {
return Err(v3::Error::Other(e.to_string()));
}
Some(Ok(k)) => {
if k.len() > max_result_bytes {
return Err(v3::Error::Other(format!(
"query result exceeds limit of {max_result_bytes} bytes"
Expand Down
4 changes: 2 additions & 2 deletions crates/trigger-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<F: RuntimeFactors> Subscriber<F> {
}

async fn run_listener(self) -> anyhow::Result<()> {
let server_addr = &self.client.get_connection_info().addr;
let server_addr = self.client.get_connection_info().addr();

tracing::info!("Connecting to Redis server at {server_addr}");
let mut pubsub = self
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<F: RuntimeFactors> Subscriber<F> {
messaging.system = "redis"
))]
async fn handle_message(&self, msg: Msg) -> anyhow::Result<()> {
let server_addr = &self.client.get_connection_info().addr;
let server_addr = self.client.get_connection_info().addr();
let channel = msg.get_channel_name();
tracing::trace!(%server_addr, %channel, "Received message");

Expand Down
Loading