Closed Alex-Cook4 closed 7 years ago
I did some tests, and this does work.
Alex, thanks for posing and answering this question as I have the same one.
Do you have any sample SPL code you could share on exactly how you did this? I am interested in the piece that initially creates the database and then writes to it. Thanks!
@phcaptjim Hi Jim, you do not need to create databases in redis yourself. Per default it comes with 16 dbs already configured (named 0 to 15). You can switch between them using the redis select command: https://redis.io/commands/select .
To use different databases from the DPS toolkit, try this code:
() as Test = Custom()
{
logic
onProcess :
{
mutable uint64 errorCode = 0ul;
mutable rstring dummyKey = "";
mutable int32 dummyVal = 0;
mutable int32 returnVal = 0;
// create store in default DB (index 0) and put/get one key
mutable uint64 handle1 = dpsCreateOrGetStore("db0store",dummyKey,dummyVal,errorCode);
dpsPut(handle1,"key1",28,errorCode);
dpsGet(handle1,"key1",returnVal,errorCode);
println("key1 in db0 = " + (rstring)returnVal);
// switch to db1
dpsRunDataStoreCommand("select 1", errorCode);
// repeat with new store/key
mutable uint64 handle2 = dpsCreateOrGetStore("db1store",dummyKey,dummyVal,errorCode);
returnVal = 0;
dpsPut(handle2,"key1",42,errorCode);
dpsGet(handle2,"key1",returnVal,errorCode);
println("key1 in db1 = " + (rstring)returnVal);
}
}
For multi-tenancy purposes, I'm wondering if I can choose a different database within a single Redis instance (node:port combination). According to this: http://www.rediscookbook.org/multiple_databases.html I should be able to just SELECT the database, then subsequent operations would be done there.
Do we support this? If so, would it work with the TTL functions?
Seems like I might be able to run: dpsRunDataStoreCommand("select 3", err); dpsSetTTL(...);
I'm just not sure how that fits in with the "global store" described in the TTL section of the docs. Thanks!