Skip to content

Commit

Permalink
Handle ErrorKind::NoScriptError on pipeline ourselves too
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <alex@wcgw.dev>
  • Loading branch information
alexsnaps committed Oct 8, 2024
1 parent 2f31b31 commit 789d713
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions limitador/src/storage/redis/redis_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::storage::redis::is_limited;
use crate::storage::redis::scripts::{SCRIPT_UPDATE_COUNTER, VALUES_AND_TTLS};
use crate::storage::{AsyncCounterStorage, Authorization, StorageErr};
use async_trait::async_trait;
use redis::{AsyncCommands, RedisError};
use redis::{AsyncCommands, ErrorKind, RedisError};
use std::collections::HashSet;
use std::ops::Deref;
use std::str::FromStr;
Expand Down Expand Up @@ -127,10 +127,21 @@ impl AsyncCounterStorage for AsyncRedisStorage {
)
.ignore()
}
pipeline
if let Err(err) = pipeline
.query_async::<()>(&mut con)
.instrument(info_span!("datastore"))
.await?;
.await
{
if err.kind() == ErrorKind::NoScriptError {
self.load_script(SCRIPT_UPDATE_COUNTER).await?;
pipeline
.query_async::<()>(&mut con)
.instrument(info_span!("datastore"))
.await?
} else {
Err(err)?
}
}

Ok(Authorization::Ok)
}
Expand Down

0 comments on commit 789d713

Please sign in to comment.