I am trying to get around this problem since yesterday but no matter what I do, I just cannot make redis to execute for my project. Here are the details in steps:
Step 1: I created new setup for redis using Elasticache in aws console, then I copied the url mentioned in primary endpoint e.g. my-redisxxxxx.cache.amazonaws.com. Thereafter, I assigned custom parameter group to this cluster from aws console where I have also configured the "notify-keyspace-events" in following way:
It still breaks even if I select default parameter group and don't assign this key.
Step 2: I made ssh connection to my nodejs EC2 instance and went to the environment variables file and assigned this url in this way:
REDIS_URI="my-redisxxxxx.cache.amazonaws.com"
REDIS_HOST="my-redisxxxxx.cache.amazonaws.com"
REDIS_PORT=6379
REDIS_INDEX=14
Now all other configurations are working fine in this manner, even redis works if I replace above url with one another existing cluster url. Only this particular new cluster that I made using elasticache seems to be having some problem.
As soon as I run node project using pm2, it hits the wall and throws this:
subscribed to channel ===> __keyevent@14__:expired
0|npm | events.js:377
0|npm | throw er; // Unhandled 'error' event
0|npm | ^
0|npm | ReplyError: ERR unknown command `config`, with args beginning with: `set`, `notify-keyspace-events`, `AKE`,
0|npm | at parseError (/usr/share/nginx/project-directory/node_modules/redis-parser/lib/parser.js:193:12)
0|npm | at parseType (/usr/share/nginx/project-directory/node_modules/redis-parser/lib/parser.js:303:14)
0|npm | Emitted 'error' event on RedisClient instance at:
0|npm | at Object.callbackOrEmit [as callback_or_emit] (/usr/share/nginx/project-directory/node_modules/redis/lib/utils.js:91:14)
0|npm | at RedisClient.return_error (/usr/share/nginx/project-directory/node_modules/redis/index.js:706:11)
0|npm | at JavascriptRedisParser.returnError (/usr/share/nginx/project-directory/node_modules/redis/index.js:196:18)
0|npm | at JavascriptRedisParser.execute (/usr/share/nginx/project-directory/node_modules/redis-parser/lib/parser.js:572:12)
0|npm | at Socket.<anonymous> (/usr/share/nginx/project-directory/node_modules/redis/index.js:274:27)
0|npm | at Socket.emit (events.js:400:28)
0|npm | at Socket.emit (domain.js:475:12)
0|npm | at addChunk (internal/streams/readable.js:293:12)
0|npm | at readableAddChunk (internal/streams/readable.js:267:9)
0|npm | at Socket.Readable.push (internal/streams/readable.js:206:10)
0|npm | at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
0|npm | command: 'CONFIG',
0|npm | args: [ 'set', 'notify-keyspace-events', 'AKE' ],
0|npm | code: 'ERR'
0|npm | }
0|npm | npm
0|npm | ERR! code ELIFECYCLE
0|npm | npm
0|npm | ERR! errno 1
0|npm | npm ERR!
I spent countless hours to understand this problem by reading documentation, only to find out that config command is restricted in aws elasticache. Also I found this answer here however not able to adapt it in my current code as I am creating redis connection like this (also I am not sure whether this is good solution):
const sub = redis.createClient(options);
export const subscribe = async (channel: string) => {
try {
sub.subscribe(channel);
console.log(`subscribed to channel ===> ${channel}`);
return {};
}
catch (error) {
console.log("Error while subscribing to a channel", error);
return {}
}
}
I am completely lost now as not able to think over what can solve this.