1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use lazy_static::lazy_static;
use redis_module::{redis_command, redis_event_handler, redis_module};
use redis_module::{NextArg, RedisResult, REDIS_OK};
mod bucket;
mod errors;
#[allow(dead_code, unused_features, unused_variables)]
mod mcaptcha;
mod utils;
use bucket::MCAPTCHA_BUCKET_TYPE;
use mcaptcha::MCAPTCHA_MCAPTCHA_TYPE;
pub const HIT_PER_SECOND: usize = 100;
pub const REDIS_MCAPTCHA_BUCKET_TYPE_VERSION: i32 = 1;
pub const PKG_NAME: &str = "mcap";
pub const PKG_VERSION: usize = 1;
pub const PREFIX_BUCKET_TIMER: &str = "timer:";
pub const BUCKET_EXPIRY_OFFSET: u64 = 30;
lazy_static! {
pub static ref ID: usize = {
use rand::prelude::*;
let mut rng = rand::thread_rng();
rng.gen()
};
pub static ref PREFIX_COUNTER: String = format!("{}:captcha:{}:", PKG_NAME, *ID);
pub static ref PREFIX_BUCKET: String = format!("{}:bucket:{{{}}}:", PKG_NAME, *ID);
}
redis_module! {
name: "mcaptcha_cahce",
version: PKG_VERSION,
data_types: [MCAPTCHA_BUCKET_TYPE, MCAPTCHA_MCAPTCHA_TYPE],
commands: [
["mcaptcha_cache.count", bucket::Bucket::counter_create, "write", 1, 1, 1],
["mcaptcha_cache.get", mcaptcha::MCaptcha::get, "readonly", 1, 1, 1],
],
event_handlers: [
[@EXPIRED @EVICTED: bucket::Bucket::on_delete],
]
}