Storage API¶
Storage Backends¶
Memory Backends¶
Bases: RateLimiterBackend
In-memory rate limiter using sliding window with TTL cleanup.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__init__(*, engine='python')
¶
Initialize one process-local engine; no implicit fallback is performed.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
22 23 24 25 26 27 28 29 30 | |
allow(key, max_events, per_seconds)
async
¶
Check if request is allowed and increment counter.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
get_rate_limit(key)
async
¶
Get current rate limit count for key.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
88 89 90 91 92 93 94 95 96 | |
get_remaining(key, max_events, per_seconds)
async
¶
Get remaining requests in current window.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
increment_rate_limit(key, window)
async
¶
Increment rate limit counter and return current count.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
77 78 79 80 81 82 83 84 85 86 | |
reset_rate_limit(key)
async
¶
Reset rate limit for key.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
98 99 100 101 102 103 104 105 | |
Bases: DebounceBackend
In-memory debounce backend using monotonic time.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
__init__(*, engine='python')
¶
Initialize one process-local engine; no implicit fallback is performed.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
111 112 113 114 115 116 117 118 119 | |
is_debounced(key)
async
¶
Check if key is currently debounced.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
152 153 154 155 156 157 158 159 160 161 162 163 164 | |
seen(key, window_seconds, fingerprint)
async
¶
Check if fingerprint was seen within window and record it.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
set_debounce(key, delay)
async
¶
Set debounce for a key.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/memory.py
138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Redis Backends¶
Bases: RateLimiterBackend
Redis rate limiter using INCR + EXPIRE pattern.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
__init__(redis, prefix)
¶
Initialize the rate limiter.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
19 20 21 22 | |
allow(key, max_events, per_seconds)
async
¶
Check if request is allowed and increment counter.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
get_remaining(key, max_events, per_seconds)
async
¶
Get remaining requests in current window.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
46 47 48 49 50 51 52 53 54 55 | |
Bases: DebounceBackend
Redis debounce backend using SET NX EX pattern.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
__init__(redis, prefix)
¶
Initialize the debounce backend.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
61 62 63 64 | |
seen(key, window_seconds, fingerprint)
async
¶
Check if fingerprint was seen within window and record it.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/redis.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
Storage Protocols¶
Bases: Protocol
Protocol for rate limiting storage backend.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/base.py
10 11 12 13 14 15 16 17 18 19 20 | |
allow(key, max_events, per_seconds)
async
¶
Check if request is allowed and increment counter.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/base.py
14 15 16 | |
get_remaining(key, max_events, per_seconds)
async
¶
Get remaining requests in current window.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/base.py
18 19 20 | |
Bases: Protocol
Protocol for debouncing storage backend.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/base.py
23 24 25 26 27 28 29 | |
seen(key, window_seconds, fingerprint)
async
¶
Check if fingerprint was seen within window and record it.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/base.py
27 28 29 | |
Factory¶
Build infrastructure backends (rate_limiter + debounce) based on configuration.
Source code in packages/aiogram-sentinel/src/aiogram_sentinel/storage/factory.py
10 11 12 13 14 15 16 17 | |