Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

Commit 3aa2f7c

Browse files
authored
Merge pull request #11 from RedBeardLab/remove_default
fix #9, first attempt
2 parents 24c7856 + 5064294 commit 3aa2f7c

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

rediSQL.c

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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

173166
int 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

Comments
 (0)