如何从nodejs中的所有redis槽中获取值



我正试图从redis中获取所有密钥,但我遇到了一个问题,一些密钥被保存在不同的插槽中,我无法获取它们,经过一些研究,我知道redis会对密钥进行散列,然后决定将密钥存储在哪里(哪个插槽(。

rediConnect.js

const { nodes, options } = require("./redisConfig");
const chalk = require("chalk");
const redis =
process.env.NODE_ENV === "dev"
? new Redis()
: new Redis.Cluster(nodes, options);
redis.on("connect", () => {
console.log(chalk.blue(`Redis status: ${redis.status}`));
});
redis.on("close", () => {
console.log(chalk.red("Redis closed"));
});
redis.on("error", (err) => {
console.log(chalk.red(err));
});
redis.on("reconnecting", () => {
console.log(chalk.yellow("Redis reconnecting"));
});
module.exports = redis;

redisConfig.js

const nodes = [
{
port: 6379,
host: "hostname"
}
];
const options = {
enableReadyCheck: true,

};
module.exports = { nodes, options };

我正在AWS ElastiCache 3碎片(9个节点(上运行redis

这是我尝试提取密钥时得到的:

'firebaseToken-driverID:61850d30033c84316bda42a5',
'firebaseToken-vendorID:hassan-chocolate-factory',
'firebaseToken-driverID:61af31f241bbcd63068736a4',
'firebaseToken-driverID:61b31880e85415fd3a2b3a0f-undefined',
'firebaseToken-vendorID:test-7f9fdeb0bc911187',
'firebaseToken-vendorID:saha',
'firebaseToken-vendorID:blessing',
'firebaseToken-vendorID:test-1ba3f58016c66903'

但实际存储在所有插槽中的是:

drivers
firebaseToken-driverID:617a784e2fa14ec9dfe7b0a1-undefined
users
firebaseToken-vendorID:test-undefined
firebaseToken-vendorID:test-D549DE57-6968-4D7A-AE4B-1948016421A1
firebaseToken-vendorID:test-A52E725F-7B6B-452E-960D-90D9B6C41127
firebaseToken-vendorID:test
tasks
firebaseToken-vendorID:hassan-chocolate-factory
vendorsList
vendor:undefined
firebaseToken-vendorID:blessing
firebaseToken-driverID:61850d30033c84316bda42a5
firebaseToken-vendorID:test-7f9fdeb0bc911187
firebaseToken-vendorID:test-1ba3f58016c66903
firebaseToken-vendorID:saha
firebaseToken-driverID:61af31f241bbcd63068736a4
firebaseToken-driverID:61b31880e85415fd3a2b3a0f-undefined
firebaseToken-vendorID:test
tasks
firebaseToken-vendorID:test
tasks
firebaseToken-vendorID:blessing
firebaseToken-vendorID:saha
firebaseToken-driverID:61af31f241bbcd63068736a4
firebaseToken-driverID:61850d30033c84316bda42a5
vendor:undefined
firebaseToken-vendorID:hassan-chocolate-factory
firebaseToken-vendorID:test-7f9fdeb0bc911187
firebaseToken-vendorID:test-1ba3f58016c66903
vendorsList
firebaseToken-driverID:61b31880e85415fd3a2b3a0f-undefined
firebaseToken-vendorID:test-D549DE57-6968-4D7A-AE4B-1948016421A1
vendors
firebaseToken-vendorID:test-undefined
firebaseToken-vendorID:test-A52E725F-7B6B-452E-960D-90D9B6C41127
drivers
firebaseToken-driverID:617a784e2fa14ec9dfe7b0a1
users
firebaseToken-driverID:617a784e2fa14ec9dfe7b0a1-undefined
firebaseToken-driverID:61850d30033c84316bda42a5
firebaseToken-vendorID:hassan-chocolate-factory
firebaseToken-driverID:61af31f241bbcd63068736a4
firebaseToken-driverID:61b31880e85415fd3a2b3a0f-undefined
firebaseToken-vendorID:test-7f9fdeb0bc911187
vendor:undefined
firebaseToken-vendorID:saha
firebaseToken-vendorID:blessing
firebaseToken-vendorID:test-1ba3f58016c66903
firebaseToken-vendorID:test-A52E725F-7B6B-452E-960D-90D9B6C41127
firebaseToken-driverID:617a784e2fa14ec9dfe7b0a1-undefined
vendors
firebaseToken-driverID:617a784e2fa14ec9dfe7b0a1
drivers
firebaseToken-vendorID:test-D549DE57-6968-4D7A-AE4B-1948016421A1
firebaseToken-vendorID:test-undefined

如何使用ioredis从所有redis插槽获取所有密钥或数据

https://github.com/luin/ioredis#running-对多个节点的命令

await Promise.all(
cluster.nodes('master').map(node => node.keys())
);
// [['key1', 'key2'], ['key3', 'key4']]

相关内容

  • 没有找到相关文章

最新更新