The following code save the whole array as single value in redis list. But I want to save array values individually. How can I do it?
P.S So sorry for poor English.
var redis = require('redis'),
client = redis.createClient();
var arr = [1,2,3];
client.rpush('testlist',arr);
You could store an array of unique ids, each one the key of a seperately stored hash.
Redis, an in-memory database that stores data in the server memory, is a popular tool to cache data. You can connect to Redis in Node. js using the node-redis module, which gives you methods to retrieve and store data in Redis.
Create new session. js file in the root directory with the following content: const express = require('express'); const session = require('express-session'); const redis = require('redis'); const client = redis. createClient(); const redisStore = require('connect-redis')(session); const app = express(); app.
Use multi()
to pipeline multiple commands at once:
var redis = require('redis'),
client = redis.createClient();
var arr = [1,2,3];
var multi = client.multi()
for (var i=0; i<arr.length; i++) {
multi.rpush('testlist', arr[i]);
}
multi.exec(function(errors, results) {
})
And finally call exec()
to send the commands to redis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With