node_redis
in a serverless architecture (hosted on AWS) inside a Lambda. This Lambda is triggered by a dynamoDB stream (whenever changes are made to the database) and it should update the Redis cache. So the Redis cache should be an exact copy of the dynamoDB's items. We figured it out that we had some inconsistencies in the cache (2 items where missing). As of now, there aren't any listeners attached to the Client Object returned by redis.createClient
. What would be the good strategy to be able to debug that issue and ensure all transactions are safely handled ? The need is really to be sure that the cache is consistent with the database
client.setAsync('hello', 'world').thenn(console.log)
29 Jun 2018 11:06:14.626136 <190>1 2018-06-29T18:06:14.346750+00:00 app web.1 - - ReplyError: NOAUTH Authentication required
at new Command (/app/node_modules/redis/lib/command.js:12:22)
at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:10)Exception
// From this code
var redis = require("redis"),
client = redis.createClient();
client.on("connect", function () {
client.set("foo_rand000000000000", "some fantastic value", redis.print);
client.get("foo_rand000000000000");
});
// To this code
var redis = require("redis"),
client = redis.createClient();
client.on("connect", function () {
client.set("foo_rand000000000000", "some fantastic value", redis.print);
var temp = client.get("foo_rand000000000000",function (err, data) {console.log(data)});
console.log(temp) // I Understand client.get will return boolean value. is there any way where temp can have value as "some fantastic value"
client.quit();
});
Can anyone please tell me how can I perform a transaction in redis while watching the the hash key foo and set a value with key test and value fooTest. The multi is executing with ok but the value is not set in redis.
redisClient.watch("foo", function (err) {
if (err) {
console.log('There was an error while watching the key foo.');
}
// Is this the correct usage of multi with hset i could not find it anywhere in documentation?
// The documentation just says that it will watch the whole hash and trigger if any value of the hash is modified.
redisClient.multi().hset(data.conversationID, helper.lastActivity, data.sentTimeStamp).exec(function (err, result) {
if (err) {
console.log('There was an error while executing the multi query');
}
if (result === null) {
console.log('The transaction was not performed since the data was accessed by someone else during the transaction and changed.');
}
});
});
This gives a result [OK] when logged but the value is updated.
redisClient
options as prefix)
I want to increment a key every n seconds in redis using nodejs.
I thought of implementing it like below :
function func(id1, max){
for(i=0; i < max; i++){
client.incr(id1, (error, value) => {
if(error){
console.log("redis incr failed : " + error);
return error;
}
console.log("updated value : " + value);
});
sleep.sleep(1);
}
client.quit();
return("incr value ended for : " + id);
}
func(id1, max);
But then in this case the complete redis incr happens in a stretch and the callback (console.log("updated value : " + value")) happens with delay (sleep 1).
Afaik, it is caused due to the nodejs being synchronous and (I think) the node_redis client being async.
Could anyone here please help me with this ? Thank you in advance!
null
or undefined
?