如何从节点js中的所有redis槽中获取值?
How to get values from all redis slots in node js?
我正在尝试从 Redis 获取所有密钥,但我 运行 遇到一个问题,一些密钥被保存在不同的插槽中,但我无法获取它们,经过一些研究后我知道redis 对密钥进行哈希处理,然后决定将密钥存储在何处(在哪个插槽中)。
redisConnect.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-commands-to-multiple-nodes
await Promise.all(
cluster.nodes('master').map(node => node.keys())
);
// [['key1', 'key2'], ['key3', 'key4']]
我正在尝试从 Redis 获取所有密钥,但我 运行 遇到一个问题,一些密钥被保存在不同的插槽中,但我无法获取它们,经过一些研究后我知道redis 对密钥进行哈希处理,然后决定将密钥存储在何处(在哪个插槽中)。
redisConnect.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-commands-to-multiple-nodes
await Promise.all(
cluster.nodes('master').map(node => node.keys())
);
// [['key1', 'key2'], ['key3', 'key4']]