-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmod.rs
More file actions
71 lines (59 loc) · 1.8 KB
/
mod.rs
File metadata and controls
71 lines (59 loc) · 1.8 KB
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
/*
* Copyright Redis Ltd. 2021 - present
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
* the Server Side Public License v1 (SSPLv1).
*/
//! This module provides with the Map-Reduce operations supported.
use crate::libmr_c_raw::bindings::{
MRRecordType, MR_CalculateSlot, MR_ClusterIsInClusterMode, MR_Init, MR_IsMySlot, RedisModuleCtx,
};
use redis_module::Context;
use std::{ffi::CString, os::raw::c_char, ptr};
use linkme::distributed_slice;
pub mod accumulator;
pub mod base_object;
pub mod execution_builder;
pub mod execution_object;
pub mod filter;
pub mod mapper;
pub mod reader;
pub mod record;
pub mod remote_task;
#[distributed_slice()]
pub static REGISTER_LIST: [fn()] = [..];
impl Default for crate::libmr_c_raw::bindings::Record {
fn default() -> Self {
crate::libmr_c_raw::bindings::Record {
recordType: 0 as *mut MRRecordType,
}
}
}
pub type RustMRError = String;
pub fn mr_init(ctx: &Context, num_threads: usize, password: Option<&str>) {
let password = password.map(|v| CString::new(v).unwrap());
unsafe {
MR_Init(
ctx.ctx as *mut RedisModuleCtx,
num_threads,
password
.as_ref()
.map(|v| v.as_ptr())
.unwrap_or(ptr::null_mut()) as *mut c_char,
)
};
record::init();
for register in REGISTER_LIST {
register();
}
}
pub fn calc_slot(s: &[u8]) -> usize {
unsafe { MR_CalculateSlot(s.as_ptr() as *const c_char, s.len()) }
}
pub fn is_my_slot(slot: usize) -> bool {
(unsafe { MR_IsMySlot(slot) }) != 0
}
/// Returns [`true`] if the cluster is in cluster mode and has been
/// properly initialised.
pub fn is_cluster_in_cluster_mode() -> bool {
unsafe { MR_ClusterIsInClusterMode().is_positive() }
}