I would like to update and add an item to the redis hash session entry.
I have been able to create a hash using the redis client using the code below:
var redis = require('redis');
var client = redis.createClient(); //creates a new client
client.on('connect', function() {
console.log('connected');
});
client.hmset('frameworks', {
'javascript': 'AngularJS',
'css': 'Bootstrap',
'node': 'Express'
});
Is there a way of adding to this hash? I would like to change and also to update an existing hash element.
Is this possible without reading everything and creating a new hash with updated and new hash elements.
I am using this webpage as a tutorial guide : https://www.sitepoint.com/using-redis-node-js/
You can use same hmset/hset based on how many you want to add or update
var redis = require('redis');
var client = redis.createClient(); //creates a new client
client.on('connect', function() {
console.log('connected');
});
client.hmset('frameworks', {
'javascript': 'AngularJS',
'css': 'Bootstrap',
'node': 'Express'
});
Say you initially have this and want to add db : mongo, and want to update node: Express4 then you can just use
//If you know will update only one use hset instead
client.hmset('frameworks', {
'node': 'Express4',
'db' : 'MongoDB'
});
Will add db & update node too for the key frameworks
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