Skip to content
Merged
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
70 changes: 29 additions & 41 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 @@ -144,7 +144,7 @@ lazy_static = "1.5"
path-absolutize = "3"
quote = "1"
rand = "0.9"
redis = "0.29"
redis = "0.32.5"
regex = "1"
reqwest = { version = "0.12", features = ["stream", "blocking"] }
rusqlite = "0.34"
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-outbound-redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = { workspace = true }

[dependencies]
anyhow = { workspace = true }
redis = { version = "0.25", features = ["tokio-comp", "tokio-native-tls-comp", "aio"] }
redis = { workspace = true , features = ["tokio-comp", "tokio-native-tls-comp", "aio"] }
spin-core = { path = "../core" }
spin-factor-outbound-networking = { path = "../factor-outbound-networking" }
spin-factors = { path = "../factors" }
Expand Down
72 changes: 63 additions & 9 deletions crates/factor-outbound-redis/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl v2::HostConnection for crate::InstanceState {
}
});

cmd.query_async::<_, RedisResults>(conn)
cmd.query_async::<RedisResults>(conn)
.await
.map(|values| values.0)
.map_err(other_error)
Expand Down Expand Up @@ -296,18 +296,72 @@ struct RedisResults(Vec<RedisResult>);

impl FromRedisValue for RedisResults {
fn from_redis_value(value: &Value) -> redis::RedisResult<Self> {
fn append(values: &mut Vec<RedisResult>, value: &Value) {
fn append(values: &mut Vec<RedisResult>, value: &Value) -> redis::RedisResult<()> {
match value {
Value::Nil | Value::Okay => (),
Value::Int(v) => values.push(RedisResult::Int64(*v)),
Value::Data(bytes) => values.push(RedisResult::Binary(bytes.to_owned())),
Value::Bulk(bulk) => bulk.iter().for_each(|value| append(values, value)),
Value::Status(message) => values.push(RedisResult::Status(message.to_owned())),
Value::Nil => {
values.push(RedisResult::Nil);
Ok(())
}
Value::Int(v) => {
values.push(RedisResult::Int64(*v));
Ok(())
}
Value::BulkString(bytes) => {
values.push(RedisResult::Binary(bytes.to_owned()));
Ok(())
}
Value::SimpleString(s) => {
values.push(RedisResult::Status(s.to_owned()));
Ok(())
}
Value::Okay => {
values.push(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::Array(arr) | Value::Set(arr) => {
arr.iter().try_for_each(|value| append(values, value))
}
Value::Double(v) => {
values.push(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::Boolean(v) => {
values.push(RedisResult::Int64(if *v { 1 } else { 0 }));
Ok(())
}
Value::BigNumber(v) => {
values.push(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:?}"),
))),
}
}

let mut values = Vec::new();
append(&mut values, value);
append(&mut values, value)?;
Ok(RedisResults(values))
}
}
Loading