@@ -141,33 +141,26 @@ int ExecCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
141141 RedisModuleKey * key ;
142142 int key_type ;
143143 PhyPersistentSQLiteDB * key_value ;
144+
145+ if (3 != argc ){
146+ return RedisModule_WrongArity (ctx );
147+ }
144148
145- if (argc == 3 ){
146- key = RedisModule_OpenKey (ctx , argv [1 ], REDISMODULE_READ | REDISMODULE_WRITE );
147- key_type = RedisModule_KeyType (key );
149+ key = RedisModule_OpenKey (ctx , argv [1 ], REDISMODULE_READ | REDISMODULE_WRITE );
150+ key_type = RedisModule_KeyType (key );
148151
149- if (REDISMODULE_KEYTYPE_EMPTY == key_type ||
150- RedisModule_ModuleTypeGetType (key ) != PersistentSQLiteDB ){
152+ if (REDISMODULE_KEYTYPE_EMPTY == key_type ||
153+ RedisModule_ModuleTypeGetType (key ) != PersistentSQLiteDB ){
151154
152- return RedisModule_ReplyWithError (ctx , REDISMODULE_ERRORMSG_WRONGTYPE );
153- }
155+ return RedisModule_ReplyWithError (ctx , REDISMODULE_ERRORMSG_WRONGTYPE );
156+ }
154157
155- key_value = RedisModule_ModuleTypeGetValue (key );
158+ key_value = RedisModule_ModuleTypeGetValue (key );
156159
157- connection = key_value -> connection ;
158- query = RedisModule_StringPtrLen (argv [2 ], & query_len );
160+ connection = key_value -> connection ;
161+ query = RedisModule_StringPtrLen (argv [2 ], & query_len );
159162
160- return RediSQL_ExecOnConnection (ctx , connection , query , query_len );
161- }
162- if (argc == 2 ){
163- connection = db ;
164- query = RedisModule_StringPtrLen (argv [1 ], & query_len );
165-
166- return RediSQL_ExecOnConnection (ctx , connection , query , query_len );
167- }
168- else {
169- return RedisModule_WrongArity (ctx );
170- }
163+ return RediSQL_ExecOnConnection (ctx , connection , query , query_len );
171164}
172165
173166int RediSQL_ExecOnConnection (RedisModuleCtx * ctx , sqlite3 * connection , const char * query , size_t query_len ){
@@ -291,20 +284,6 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
291284
292285 if (PersistentSQLiteDB == NULL ) return REDISMODULE_ERR ;
293286
294- int rc ;
295- const char * database_name ;
296-
297- if (1 == argc ){
298- database_name = RedisModule_StringPtrLen (argv [0 ], NULL );
299-
300- rc = sqlite3_open (database_name , & db );
301- } else {
302- rc = sqlite3_open (":memory:" , & db );
303- }
304-
305- if (rc != SQLITE_OK )
306- return REDISMODULE_ERR ;
307-
308287 if (RedisModule_CreateCommand (ctx , "rediSQL.EXEC" , ExecCommand ,
309288 "deny-oom random no-cluster" , 1 , 1 , 1 ) == REDISMODULE_ERR ){
310289 return REDISMODULE_ERR ;
0 commit comments