pub async fn record_fixed_window(
        &mut self,
        resource: &str,
        subject: &str,
        size: Duration,
    ) -> Result<u64, Box<dyn Error>> {
        let now = SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap();
        let window = (now.as_secs() / size.as_secs()) * size.as_secs();
        let key = format!("{}:{}:{}:{}", KEY_PREFIX, resource, subject, window);

        let (count,): (u64,) = redis::pipe()
            .atomic()
            .incr(&key, 1)
            .expire(&key, size.as_secs() as usize)
            .ignore()
            .query_async(&mut self.conn)
            .await?;
        Ok(count)
    }
/// Records an access to `resource` by `subject` with fixed window algorithm.
/// Size of time window equals the `size` in seconds.
Records an access to `resource` by `subject` with fixed window algorithm.
Size of time window equals the `size` in seconds.
Records an access to ` resource ` by ` subject ` with fixed window algorithm . Size of time window equals the ` size ` in seconds .
pub async fn record_fixed_window(
        &mut self,
        resource: &str,
        subject: &str,
        size: Duration,
    ) -> Result<u64, Box<dyn Error>> {
        let now = SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap();
        let window = (now.as_secs() / size.as_secs()) * size.as_secs();
        let key = format!("{}:{}:{}:{}", KEY_PREFIX, resource, subject, window);
        let (count,): (u64,) = redis::pipe()
            .atomic()
            .incr(&key, 1)
            .expire(&key, size.as_secs() as usize)
            .ignore()
            .query_async(&mut self.conn)
            .await?;
        Ok(count)
    }
pub async fn record_fixed_window ( & mut self , resource : & str , subject : & str , size : Duration , ) -> Result < u64 , Box < dyn Error > > { let now = SystemTime :: now ( ) . duration_since ( time :: UNIX_EPOCH ) . unwrap ( ) ; let window = ( now . as_secs ( ) / size . as_secs ( ) ) * size . as_secs ( ) ; let key = format ! ( " " KEY_PREFIX resource subject window ) ; let ( count , ) : ( u64 , ) = redis :: pipe ( ) . atomic ( ) . incr ( & key , 1 ) . expire ( & key , size . as_secs ( ) as usize ) . ignore ( ) . query_async ( & mut self . conn ) . await ? ; Ok ( count ) }
Records an access to `resource` by `subject` with fixed window algorithm.
Records an access to ` resource ` by ` subject ` with fixed window algorithm .
&mut self
resource
&str
subject
&str
size
Duration
&mut self
resource
&str
subject
&str
size
Duration