在使用 node-redis 和 timeSeries 的打字稿中,我想在范围内获得 argmin,但我找不到方法来做到这一点。
Bellow 是一个带有 timeSeries 的简单示例(时间戳 0、1、2、3、4、5 上有 6 个点,每个点都有一个随机值)。我想要时间戳范围 [3, 5] 上的 argmin
import * as rd from 'redis';
// Connect to redis
const { REDIS_ENDPOINT, REDIS_PASSWORD, REDIS_PORT } = process.env;
if (!REDIS_ENDPOINT || !REDIS_PASSWORD || !REDIS_PORT) throw new Error('missing env variable');
const client = rd.createClient({ socket: { host: REDIS_ENDPOINT, port: parseInt(REDIS_PORT, 10) }, password: REDIS_PASSWORD });
await client.connect();
// Create a time series with timestamp 0, 1, 2, 3, 4, 5 (random value on each point)
const savePipeline = client.multi();
Array.from(Array(6).keys()).forEach((timestamp) => {
savePipeline.ts.add('test_time_serie_key', timestamp, Math.random());
});
await savePipeline.exec();
// Query argmin: I want timestamp and value of point with min value in timestamp range [3, 5]
const fromTimestamp = 3;
const toTimestamp = 5;
const argmin = { timestamp: null, value: null }; // How to get It ?
console.log(`Argmin in range [${fromTimestamp}, ${toTimestamp}] is: ${JSON.stringify(argmin)}`);