Skip to content

Commit

Permalink
Added expire to the set tabletype, but it works only with KeyDB (Red…
Browse files Browse the repository at this point in the history
…is is not supported)
  • Loading branch information
deem0n committed Aug 7, 2020
1 parent 5cdaa39 commit bbed188
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MODULE_big = redis_fdw
OBJS = redis_fdw.o

EXTENSION = redis_fdw
DATA = redis_fdw--1.0.sql
DATA = redis_fdw--1.0.1.sql

REGRESS = redis_fdw
REGRESS_OPTS = --inputdir=test --outputdir=test \
Expand Down
File renamed without changes.
73 changes: 69 additions & 4 deletions redis_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ redis_fdw_validator(PG_FUNCTION_ARGS)
}
else if (strcmp(def->defname, "keyexpire") == 0)
{
if(tabletype != PG_REDIS_SCALAR_TABLE)
if (tabletype != PG_REDIS_SCALAR_TABLE && tabletype != PG_REDIS_SET_TABLE)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid tabletype for option keyexpire. "
"Only SCALAR is supported")));
errmsg("invalid tabletype for option keyexpire."
"Only set tabletype is supported. Or just don't specify tabletype to use scalar keys.")));
if (keyexpire)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
Expand Down Expand Up @@ -2222,6 +2222,16 @@ redisExecForeignInsert(EState *estate,
case PG_REDIS_SET_TABLE:
sreply = redisCommand(context, "SADD %s %s",
fmstate->singleton_key, keyval);
if (fmstate->keyexpire) {
check_reply(sreply, context, ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot insert value for key %s", keyval);
freeReplyObject(sreply);

// supported only in KeyDB
sreply = redisCommand(context, "EXPIREMEMBER %s %s %d",
fmstate->singleton_key, keyval,
fmstate->keyexpire);
}
break;
case PG_REDIS_LIST_TABLE:
sreply = redisCommand(context, "RPUSH %s %s",
Expand Down Expand Up @@ -2387,6 +2397,16 @@ redisExecForeignInsert(EState *estate,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"could not add set member %s", valueval);
freeReplyObject(sreply);

if (fmstate->keyexpire) {
// supported only in KeyDB
sreply = redisCommand(context, "EXPIREMEMBER %s %s %d",
keyval, valueval, fmstate->keyexpire);
check_reply(sreply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot set expire for member %s", valueval);
freeReplyObject(sreply);
}
}
}
break;
Expand Down Expand Up @@ -2469,6 +2489,17 @@ redisExecForeignInsert(EState *estate,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"could not add keyset element %s", valueval);
freeReplyObject(sreply);

if (fmstate->keyexpire) {
// supported only in KeyDB
sreply = redisCommand(context, "EXPIREMEMBER %s %s %d",
fmstate->keyset, keyval,
fmstate->keyexpire);
check_reply(sreply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot set expire for keyset element %s", valueval);
freeReplyObject(sreply);
}
}
}
return slot;
Expand Down Expand Up @@ -2772,7 +2803,19 @@ redisExecForeignUpdate(EState *estate,
check_reply(ereply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"adding keyset element %s", newkey);
freeReplyObject(ereply); }
freeReplyObject(ereply);

if (fmstate->keyexpire) {
// supported only in KeyDB
ereply = redisCommand(context, "EXPIREMEMBER %s %s %d",
fmstate->keyset, newkey,
fmstate->keyexpire);
check_reply(ereply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot set expire for keyset element %s", newkey);
freeReplyObject(ereply);
}
}
}
else /* is a singleton */
{
Expand Down Expand Up @@ -2807,6 +2850,17 @@ redisExecForeignUpdate(EState *estate,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"setting value %s", newkey);
freeReplyObject(ereply);

if (fmstate->keyexpire) {
// supported only in KeyDB
ereply = redisCommand(context, "EXPIREMEMBER %s %s %d",
fmstate->singleton_key, newkey,
fmstate->keyexpire);
check_reply(ereply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot set expire for value %s", newkey);
freeReplyObject(ereply);
}
break;
case PG_REDIS_ZSET_TABLE:
{
Expand Down Expand Up @@ -2935,6 +2989,17 @@ redisExecForeignUpdate(EState *estate,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"could not add element %s", array_vals[i]);
freeReplyObject(ereply);

if (fmstate->keyexpire) {
// supported only in KeyDB
ereply = redisCommand(context, "EXPIREMEMBER %s %s %d",
newkey, array_vals[i],
fmstate->keyexpire);
check_reply(ereply, context,
ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION,
"cannot set expire for element %s", array_vals[i]);
freeReplyObject(ereply);
}
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion redis_fdw.control
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
##########################################################################

comment = 'Foreign data wrapper for querying a Redis server'
default_version = '1.0'
default_version = '1.0.1'
module_pathname = '$libdir/redis_fdw'
relocatable = true

0 comments on commit bbed188

Please sign in to comment.