IBMStreams / streamsx.dps

The IBMStreams/streamsx.dps GitHub repository is home to the Streams toolkit named DPS (Distributed Process Store)
http://ibmstreams.github.io/streamsx.dps
Other
4 stars 9 forks source link

Does the DPS toolkit support multiple databases within a Redis instance? #34

Closed Alex-Cook4 closed 7 years ago

Alex-Cook4 commented 7 years ago

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!

Alex-Cook4 commented 7 years ago

I did some tests, and this does work.

phcaptjim commented 6 years ago

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!

brandtol commented 6 years ago

@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);

    }
}