mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
use redis pipeline to set multiple values at once
This commit is contained in:
parent
c25cd9c3fe
commit
c762f9cf8e
20
src/cache/redis_cacher.rs
vendored
20
src/cache/redis_cacher.rs
vendored
@ -118,14 +118,18 @@ impl RedisCache {
|
|||||||
/// on a failure.
|
/// on a failure.
|
||||||
pub async fn cache_json(
|
pub async fn cache_json(
|
||||||
&mut self,
|
&mut self,
|
||||||
json_results: &str,
|
json_results: impl Iterator<Item = String>,
|
||||||
key: &str,
|
keys: impl Iterator<Item = String>,
|
||||||
) -> Result<(), Report<CacheError>> {
|
) -> Result<(), Report<CacheError>> {
|
||||||
self.current_connection = Default::default();
|
self.current_connection = Default::default();
|
||||||
|
let mut pipeline = redis::Pipeline::with_capacity(3);
|
||||||
|
|
||||||
let mut result: Result<(), RedisError> = self.connection_pool
|
for (key, json_result) in keys.zip(json_results) {
|
||||||
[self.current_connection as usize]
|
pipeline.set_ex(key, json_result, self.cache_ttl.into());
|
||||||
.set_ex(key, json_results, self.cache_ttl.into())
|
}
|
||||||
|
|
||||||
|
let mut result: Result<(), RedisError> = pipeline
|
||||||
|
.query_async(&mut self.connection_pool[self.current_connection as usize])
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Code to check whether the current connection being used is dropped with connection error
|
// Code to check whether the current connection being used is dropped with connection error
|
||||||
@ -145,8 +149,10 @@ impl RedisCache {
|
|||||||
CacheError::PoolExhaustionWithConnectionDropError,
|
CacheError::PoolExhaustionWithConnectionDropError,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
result = self.connection_pool[self.current_connection as usize]
|
result = pipeline
|
||||||
.set_ex(key, json_results, 60)
|
.query_async(
|
||||||
|
&mut self.connection_pool[self.current_connection as usize],
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user