Using REDIS to Store and Retrieve Data

167 views
Skip to first unread message

Tim Lane

unread,
Dec 19, 2021, 9:19:12 PM12/19/21
to mountebank-discuss
Hi All,

I've been playing with the idea of using redis to store information in order to share between mountebank calls.

Using a module from here https://github.com/redis/node-redis I'm able to add data to a set.

const redis = require('redis');
const client = redis.createClient("192.168.0.81",6379);
console.log("connecting to redis...");
client.connect();
client.sAdd('names', "BillyBob");
client.quit();

However, when i try to get a random name form that set I get returned an object which i cant figure out how to process it.

const redis = require('redis');
const client = redis.createClient("192.168.0.81",6379);
logger.info("connecting to redis...");
client.connect();
var userName2 = client.sRandMember('names');
logger.info("------------->" + userName2);
client.quit();

info: [http:2525 **-- VSE -- 2525 --**] ::ffff:127.0.0.1:51371 -------> reading from redis

info: [http:2525 **-- VSE -- 2525 --**] ::ffff:127.0.0.1:51371 userName2: [object Promise]

Any ideas how to access this?

Brandon Byars

unread,
Dec 21, 2021, 10:53:14 AM12/21/21
to Tim Lane, mountebank-discuss
Hi Tim,
I've not used that library, but it appears as though the sRandMember call is returning a promise. Assuming you're in an async function, you can say:

var userName2 = await client.sRandMember('names');

If it's a top level script, then I'd expect something like this to work:

client.sRandMember('names').then(userName2 => {
    logger.info('------------->'+userName2);
    client.quit();
});

-Brandon

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mountebank-discuss/8d849f80-7c8d-4379-83a0-bb42d5bee74en%40googlegroups.com.

Bob Ruub

unread,
Dec 23, 2021, 5:42:52 PM12/23/21
to mountebank-discuss
Thanks Brandon,

I'll have a go at it but i'm no Node programmer.

I see in another thread there's development on state-fullness and I might wait for that. 

I am getting some requests from the functional team who care about these things and they are impressed with what i've done with your product but I don't really want the maintenance overhead in my life right now :)

Regards,

Tim Lane.

Bob Ruub

unread,
Apr 20, 2022, 12:46:24 AM4/20/22
to mountebank-discuss
Hi,

I've had to revisit this as I now need it for alignment of a load driver and a virtual service data-wise in our 

Had a crack at it but cant seem to get it working (I'm no node programmer) and am not sure what I'm getting wrong.

I've got my whole codebase her https://github.com/bobruub/mb_redis_poc and was hoping you could take a look and point me in the right direction.

Also, is there some other in memory data store that would be easier to implement, I'm not wedded to redis in particular it's just one we use for other tasks.

Bob Ruub

unread,
Apr 22, 2022, 1:38:38 AM4/22/22
to mountebank-discuss
I've managed to get a mysql database connected and getting some data :) but running into the same issue with asynchronous processing.

I've updated the repo so if anyone's got some advice I'm all ears.

Plenty of info on the web around callback and promises but I cant seem to retrofit it into the mountebank framework as I've deployed it :(

Bob Ruub

unread,
May 7, 2022, 4:26:34 AM5/7/22
to mountebank-discuss
Decided to do the whole thing in java so spent a couple of days developing and testing it out. 

It's inefficient  (I'm no java developer) but I'll set it behind a load balancer and scale sideways :)

Probably make it generic, config driven and implement some better error handling (its a bit touchy) at some stage but right now works for what I need.

But do let me know if anyone makes progress with redis and mountbank I don't want to be supporting two frameworks and I love mountebank

Brandon Byars

unread,
May 8, 2022, 6:48:43 PM5/8/22
to Bob Ruub, mountebank-discuss
Glad you were able to get it working! Slow moving, but I do very much intend to modularize the persistence options.
-Brandon

Bob Ruub

unread,
May 9, 2022, 7:10:53 PM5/9/22
to mountebank-discuss
Thanks Brandon, 

if you need anyone to test it out (I've some experience with mysql and redis) let me know.

Reply all
Reply to author
Forward
0 new messages