Created
May 10, 2021 17:33
-
-
Save guyroyse/1b2d9fe024bdce14f74ee8cab771ce34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Redis from 'ioredis' | |
const redis = new Redis() | |
async function main() { | |
await redis.flushall() | |
console.time('total') | |
console.log() | |
console.log('Creating keys and rules') | |
console.timeLog('total') | |
console.log() | |
await redis.call('TS.CREATE', 'temperature:2:32', 'RETENTION', 1000) | |
await redis.call('TS.CREATE', 'temperature:2:32:max') | |
await redis.call('TS.CREATERULE', 'temperature:2:32', 'temperature:2:32:max', 'AGGREGATION', 'max', 6 * 1000) | |
console.log('Adding three entries') | |
console.timeLog('total') | |
console.log() | |
await redis.call('TS.ADD', 'temperature:2:32', '*', 30) | |
await redis.call('TS.ADD', 'temperature:2:32', '*', 31) | |
await redis.call('TS.ADD', 'temperature:2:32', '*', 32) | |
let source = await redis.call('TS.RANGE', 'temperature:2:32', '-', '+') | |
let desination = await redis.call('TS.RANGE', 'temperature:2:32:max', '-', '+') | |
console.log("Values in Source series", source) | |
console.log("Values in Destination series", desination) | |
console.log() | |
console.timeLog('total') | |
console.log() | |
console.log("Waiting 2 seconds...") | |
setTimeout(async () => { | |
console.log("Time's up!") | |
console.timeLog('total') | |
console.log() | |
let source = await redis.call('TS.RANGE', 'temperature:2:32', '-', '+') | |
let destination = await redis.call('TS.RANGE', 'temperature:2:32:max', '-', '+') | |
console.log("Values in Source series", source) | |
console.log("Values in Destination series", destination) | |
console.log() | |
console.timeLog('total') | |
console.log() | |
console.log("Adding a temperature...") | |
await redis.call('TS.ADD', 'temperature:2:32', '*', 33) | |
source = await redis.call('TS.RANGE', 'temperature:2:32', '-', '+') | |
destination = await redis.call('TS.RANGE', 'temperature:2:32:max', '-', '+') | |
console.log("Values in Source series", source) | |
console.log("Values in Destination series", destination) | |
console.log() | |
console.timeEnd('total') | |
redis.quit() | |
}, 2000) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment