From acee5d892d9997fb9c69346ae2da69a27203e21c Mon Sep 17 00:00:00 2001 From: neon_arch Date: Mon, 2 Sep 2024 21:17:31 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20replace=20deprecated=20`s?= =?UTF-8?q?et=5Fex`=20command=20with=20`set=5Foptions`=20in=20`cache=5Fjso?= =?UTF-8?q?n`=20function=20(#592)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cache/redis_cacher.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cache/redis_cacher.rs b/src/cache/redis_cacher.rs index 1dd7cb8..1fde95b 100644 --- a/src/cache/redis_cacher.rs +++ b/src/cache/redis_cacher.rs @@ -4,7 +4,10 @@ use super::error::CacheError; use error_stack::Report; use futures::stream::FuturesUnordered; -use redis::{aio::ConnectionManager, AsyncCommands, Client, RedisError}; +use redis::{ + aio::ConnectionManager, AsyncCommands, Client, ExistenceCheck, RedisError, SetExpiry, + SetOptions, +}; /// A constant holding the redis pipeline size. const REDIS_PIPELINE_SIZE: usize = 3; @@ -139,8 +142,14 @@ impl RedisCache { self.current_connection = Default::default(); for (key, json_result) in keys.zip(json_results) { - self.pipeline - .set_ex(key, json_result, self.cache_ttl.into()); + self.pipeline.set_options( + key, + json_result, + SetOptions::default() + .conditional_set(ExistenceCheck::NX) + .get(true) + .with_expiration(SetExpiry::EX(self.cache_ttl.into())), + ); } let mut result: Result<(), RedisError> = self