@@ -5,6 +5,8 @@ use std::ptr;
5
5
use std:: str:: Utf8Error ;
6
6
use std:: time:: Duration ;
7
7
8
+ use raw:: KeyType ;
9
+
8
10
use crate :: from_byte_string;
9
11
use crate :: native_types:: RedisType ;
10
12
use crate :: raw;
@@ -60,6 +62,10 @@ impl RedisKey {
60
62
Ok ( Some ( value) )
61
63
}
62
64
65
+ pub fn key_type ( & self ) -> raw:: KeyType {
66
+ unsafe { raw:: RedisModule_KeyType . unwrap ( ) ( self . key_inner ) } . into ( )
67
+ }
68
+
63
69
/// Detects whether the key pointer given to us by Redis is null.
64
70
pub fn is_null ( & self ) -> bool {
65
71
let null_key: * mut raw:: RedisModuleKey = ptr:: null_mut ( ) ;
@@ -179,12 +185,12 @@ impl RedisKeyWritable {
179
185
REDIS_OK
180
186
}
181
187
182
- pub fn is_empty ( & self ) -> bool {
183
- use raw:: KeyType ;
184
-
185
- let key_type: KeyType = unsafe { raw:: RedisModule_KeyType . unwrap ( ) ( self . key_inner ) } . into ( ) ;
188
+ pub fn key_type ( & self ) -> raw:: KeyType {
189
+ unsafe { raw:: RedisModule_KeyType . unwrap ( ) ( self . key_inner ) } . into ( )
190
+ }
186
191
187
- key_type == KeyType :: Empty
192
+ pub fn is_empty ( & self ) -> bool {
193
+ self . key_type ( ) == KeyType :: Empty
188
194
}
189
195
190
196
pub fn get_value < T > ( & self , redis_type : & RedisType ) -> Result < Option < & mut T > , RedisError > {
@@ -261,8 +267,6 @@ fn to_raw_mode(mode: KeyMode) -> raw::KeyMode {
261
267
}
262
268
263
269
fn verify_type ( key_inner : * mut raw:: RedisModuleKey , redis_type : & RedisType ) -> RedisResult {
264
- use raw:: KeyType ;
265
-
266
270
let key_type: KeyType = unsafe { raw:: RedisModule_KeyType . unwrap ( ) ( key_inner) } . into ( ) ;
267
271
268
272
if key_type != KeyType :: Empty {
0 commit comments