I am writing a program which creates and then uses Redis keys for message sorting. When i try to do this using my local Redis instance i can see that the keys are created and the program works fine. But when I try to do this using a Redis Cluster I am not able to view the keys on the cluster.
This is how i connect to the cluster –
constructor() {
const clusterEndpoints = [{ host: env.REDIS_ENDPOINT, port: parseInt(env.REDIS_PORT) }];
const redisPassword = env.REDIS_PASSWORD;
const sslOptions = {
tls: {
rejectUnauthorized: false,
minVersion: 'TLSv1.2' as const,
},
};
const clusterOptions: ClusterOptions = {
redisOptions: {
password: redisPassword,
...sslOptions,
},
};
this.client = new Redis.Cluster(clusterEndpoints, clusterOptions);
// Log connection success
this.client.on('connect', () => {
logger.info('Successfully connected to Redis cluster at:', clusterEndpoints);
});
}
this established connection is then used by the sorting function-
public async sortMessage(message: Message, messageTimestamp: number): Promise<number | null> {
try {
const heapKey = `{message_heap}`;
const lastTsKey = `{message_heap}:last_ts`;
const brandLastTsKey = `{message_heap}:brand_last_ts`;
const brandCntKey = `{message_heap}:brand_count`;
await this.client.eval(
this.insertScript,
4, // Number of keys
lastTsKey,
brandLastTsKey,
brandCntKey,
heapKey,
String(messageTimestamp),
String(limit),
JSON.stringify(message),
);
return messageTimestamp;
} catch (error) {
logger.error('Error sorting message:', error);
return null;
}
}
which in turn calls a lua script to do the redis functionality. I don’t think the lua script is the issue as the Redis operations work fine locally.
I can verify that I can connect to the cluster fine. I also have permissions to execute commands and read/write keys on the cluster. I also forced the keys to be in the same hash slot by using the ‘{}’ around ‘message_heap’
I tried connecting to the Redis Cluster and trying to locate the keys using GET <key_name> for the string keys. I can confirm the there is a master node with a slave replica on the Redis cluster, so it shouldn’t be an issue that I am hitting the wrong node.
I want to be able to see the keys pop up on the Cluster with their associated values when i try locating them using redis-cli, which i don’t see happening currently.
This is how i connect to the cluster-
redis-cli -h <host> -p 6379 -a <password> --tls --no-aut
h-warning --insecure -c