Reputation: 3975
I am new to node.js, and am not yet familiar with the ecosystem around it.
I have a one-page Express app that caches some data in redis and I would like to add a few configuration settings to the redis db. Thus far I have been simply using redis-cli to manually set the necessary keys. I would prefer to somehow have npm run a script (or something), so that deploying the app on a server is as simple as possible.
What is the recommended mechanism for initializing a redis database for a node.js app?
Upvotes: 0
Views: 693
Reputation: 106696
Using the redis
module on npm you could easily use mset()
to set multiple keys in one go. Example:
var redis = require('redis'),
client = redis.createClient();
var kv = [
'key1', 'value1',
'key2', 2,
'key3', 'value3'
];
client.mset(kv, function(err) {
if (err) throw err;
// end the connection gracefully if
// you don't need to access redis anymore
client.quit();
});
Upvotes: 1