Skip to content

Commit 350531c

Browse files
committed
add fields to KeyMode bitflags
1 parent b5b359e commit 350531c

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ serde = { version = "1", features = ["derive"] }
133133
nix = "0.26"
134134
cfg-if = "1"
135135
redis-module-macros-internals = { path = "./redismodule-rs-macros-internals" }
136+
strum = {version = "0.27.2",features = ["derive"]}
136137
log = "0.4"
137138

138139
[dev-dependencies]
@@ -146,6 +147,10 @@ redis-module = { path = "./", default-features = false }
146147
bindgen = "0.66"
147148
cc = "1"
148149

150+
#[build-dependencies.bindgen]
151+
#version = "0.71.1"
152+
#default-features = false
153+
149154
[features]
150155
default = ["min-redis-compatibility-version-6-0"]
151156
min-redis-compatibility-version-7-4 = ["redis-module/min-redis-compatibility-version-7-4"]

build.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ impl ParseCallbacks for RedisModuleCallback {
1212
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
1313
if name.starts_with("REDISMODULE_SUBEVENT_") || name.starts_with("REDISMODULE_EVENT_") {
1414
Some(IntKind::U64)
15-
} else if name.starts_with("REDISMODULE_REPLY_")
16-
|| name.starts_with("REDISMODULE_KEYTYPE_")
17-
|| name.starts_with("REDISMODULE_AUX_")
18-
|| name == "REDISMODULE_OK"
19-
|| name == "REDISMODULE_ERR"
20-
|| name == "REDISMODULE_LIST_HEAD"
15+
} else if name.starts_with("REDISMODULE_REPLY") {
16+
Some(IntKind::I32)
17+
} else if name == "REDISMODULE_LIST_HEAD"
2118
|| name == "REDISMODULE_LIST_TAIL"
2219
{
2320
// These values are used as `enum` discriminants, and thus must be `isize`.

src/key.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl RedisKey {
110110
/// Will panic if `RedisModule_KeyType` is missing in redismodule.h
111111
#[must_use]
112112
pub fn key_type(&self) -> raw::KeyType {
113-
unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into()
113+
let discriminant = unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) };
114+
KeyType::from_repr(discriminant as u32).unwrap()
114115
}
115116

116117
/// Detects whether the key pointer given to us by Redis is null.
@@ -379,7 +380,8 @@ impl RedisKeyWritable {
379380
/// Will panic if `RedisModule_KeyType` is missing in redismodule.h
380381
#[must_use]
381382
pub fn key_type(&self) -> raw::KeyType {
382-
unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into()
383+
let discriminant = unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) };
384+
KeyType::from_repr(discriminant as u32).unwrap()
383385
}
384386

385387
pub fn open_with_redis_string(
@@ -670,7 +672,7 @@ fn to_raw_mode(mode: KeyMode) -> raw::KeyMode {
670672
/// Will panic if `RedisModule_KeyType` or `RedisModule_ModuleTypeGetType` are missing in redismodule.h
671673
#[allow(clippy::not_unsafe_ptr_arg_deref)]
672674
pub fn verify_type(key_inner: *mut raw::RedisModuleKey, redis_type: &RedisType) -> RedisResult {
673-
let key_type: KeyType = unsafe { raw::RedisModule_KeyType.unwrap()(key_inner) }.into();
675+
let key_type: KeyType = KeyType::from_repr(unsafe { raw::RedisModule_KeyType.unwrap()(key_inner) as u32 }).unwrap();
674676

675677
if key_type != KeyType::Empty {
676678
// The key exists; check its type

src/raw.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ bitflags! {
2929
pub struct KeyMode: c_int {
3030
const READ = REDISMODULE_READ as c_int;
3131
const WRITE = REDISMODULE_WRITE as c_int;
32+
33+
const KEYOPEN_NOTOUCH = REDISMODULE_OPEN_KEY_NOTOUCH as c_int;
34+
const KEYOPEN_NONOTIFY = REDISMODULE_OPEN_KEY_NONOTIFY as c_int;
35+
const KEYOPEN_NOSTATS = REDISMODULE_OPEN_KEY_NOSTATS as c_int;
36+
const KEYOPEN_NOEFFECTS = REDISMODULE_OPEN_KEY_NOEFFECTS as c_int;
37+
const KEYOPEN_NOEXPIRE = REDISMODULE_OPEN_KEY_NOEXPIRE as c_int;
38+
const KEYOPEN_ACCESSEXPIRED = REDISMODULE_OPEN_KEY_ACCESS_EXPIRED as c_int;
3239
}
3340
}
3441

@@ -40,7 +47,8 @@ bitflags! {
4047
}
4148
}
4249

43-
#[derive(Primitive, Debug, PartialEq, Eq)]
50+
#[repr(u32)]
51+
#[derive(Primitive, Debug, PartialEq, Eq, strum::FromRepr)]
4452
pub enum KeyType {
4553
Empty = REDISMODULE_KEYTYPE_EMPTY,
4654
String = REDISMODULE_KEYTYPE_STRING,
@@ -52,19 +60,14 @@ pub enum KeyType {
5260
Stream = REDISMODULE_KEYTYPE_STREAM,
5361
}
5462

55-
impl From<c_int> for KeyType {
56-
fn from(v: c_int) -> Self {
57-
Self::from_i32(v).unwrap()
58-
}
59-
}
60-
6163
#[derive(Primitive, Debug, PartialEq, Eq)]
6264
pub enum Where {
6365
ListHead = REDISMODULE_LIST_HEAD,
6466
ListTail = REDISMODULE_LIST_TAIL,
6567
}
6668

67-
#[derive(Primitive, Debug, PartialEq, Eq)]
69+
#[repr(i32)]
70+
#[derive(Primitive, Debug, PartialEq, Eq, strum::FromRepr)]
6871
pub enum ReplyType {
6972
Unknown = REDISMODULE_REPLY_UNKNOWN,
7073
String = REDISMODULE_REPLY_STRING,
@@ -86,13 +89,15 @@ impl From<c_int> for ReplyType {
8689
}
8790
}
8891

89-
#[derive(Primitive, Debug, PartialEq, Eq)]
92+
#[repr(u32)]
93+
#[derive(Primitive, Debug, PartialEq, Eq, strum::FromRepr)]
9094
pub enum Aux {
9195
Before = REDISMODULE_AUX_BEFORE_RDB,
9296
After = REDISMODULE_AUX_AFTER_RDB,
9397
}
9498

95-
#[derive(Primitive, Debug, PartialEq, Eq)]
99+
#[repr(u32)]
100+
#[derive(Primitive, Debug, PartialEq, Eq, strum::FromRepr)]
96101
pub enum Status {
97102
Ok = REDISMODULE_OK,
98103
Err = REDISMODULE_ERR,

0 commit comments

Comments
 (0)