@@ -4,16 +4,15 @@ use std::os::raw::{c_int, c_void};
44
55use crate :: raw;
66
7- pub struct RedisModuleType < ' a > {
8- name : & ' a str ,
7+ pub struct RedisModuleType {
98 raw_type : * mut raw:: RedisModuleType ,
109}
1110
1211// We want to be able to create static instances of this type,
1312// which means we need to implement Sync.
14- unsafe impl < ' a > Sync for RedisModuleType < ' a > { }
13+ unsafe impl Sync for RedisModuleType { }
1514
16- fn redis_log (
15+ pub fn redis_log (
1716 ctx : * mut raw:: RedisModuleCtx ,
1817 msg : & str ,
1918) {
@@ -24,21 +23,26 @@ fn redis_log(
2423 }
2524}
2625
27- impl < ' a > RedisModuleType < ' a > {
28- pub const fn new ( name : & ' a str ) -> Self {
26+ impl RedisModuleType {
27+ pub const fn new ( ) -> Self {
2928 RedisModuleType {
30- name,
3129 raw_type : ptr:: null_mut ( ) ,
3230 }
3331 }
3432
3533 pub fn create_data_type (
3634 & mut self ,
3735 ctx : * mut raw:: RedisModuleCtx ,
38- ) -> Result < ( ) , ( ) > {
39- let type_name = CString :: new ( self . name ) . unwrap ( ) ;
36+ name : & str ,
37+ ) -> Result < ( ) , & str > {
4038
41- redis_log ( ctx, "Here 1" ) ;
39+ if name. len ( ) != 9 {
40+ let msg = "Redis requires the length of native type names to be exactly 9 characters" ;
41+ redis_log ( ctx, format ! ( "{}, name is: '{}'" , msg, name) . as_str ( ) ) ;
42+ return Err ( msg) ;
43+ }
44+
45+ let type_name = CString :: new ( name) . unwrap ( ) ;
4246
4347 let mut type_methods = raw:: RedisModuleTypeMethods {
4448 version : raw:: REDISMODULE_TYPE_METHOD_VERSION as u64 ,
@@ -53,8 +57,6 @@ impl<'a> RedisModuleType<'a> {
5357 digest : None ,
5458 } ;
5559
56- redis_log ( ctx, "Here 2" ) ;
57-
5860 let redis_type = unsafe {
5961 raw:: RedisModule_CreateDataType . unwrap ( ) (
6062 ctx,
@@ -64,19 +66,13 @@ impl<'a> RedisModuleType<'a> {
6466 )
6567 } ;
6668
67- redis_log ( ctx, "Here 3" ) ;
68-
6969 if redis_type. is_null ( ) {
7070 redis_log ( ctx, "Error: created data type is null" ) ;
71- return Err ( ( ) ) ;
71+ return Err ( "Error: created data type is null" ) ;
7272 }
7373
74- redis_log ( ctx, "Here 4" ) ;
75-
7674 self . raw_type = redis_type;
7775
78- redis_log ( ctx, "Here 5" ) ;
79-
8076 Ok ( ( ) )
8177 }
8278}
0 commit comments