Complete the code to connect to a Redis cluster using the client.
const cluster = new Redis.Cluster([1]);You need to provide an array of node objects with host and port to connect to a Redis cluster.
Complete the code to execute a command on the Redis cluster client.
cluster.[1]('set', 'key', 'value');
execute or call which are not valid methods.run which does not exist.The sendCommand method is used to send commands to the Redis cluster client.
Fix the error in the code to properly handle cluster node errors.
cluster.on('error', [1] => { console.error('Cluster error:', err); });
The error event handler receives the error object as the parameter, commonly named err.
Fill both blanks to create a command that gets the value of a key from the cluster.
const value = await cluster.[1]('get', [2]);
execute instead of sendCommand.Use sendCommand to send the 'get' command and provide the key as a string.
Fill all three blanks to create a cluster client, set a key, and get its value.
const cluster = new Redis.Cluster([1]); await cluster.[2]('set', 'name', 'Alice'); const name = await cluster.[3]('get', 'name');
sendCommand.First, create the cluster client with an array of nodes. Then use sendCommand to set and get keys.