-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
32 lines (25 loc) · 980 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const redisHost = process.env.REDIS_HOST;
const expireInSecs = process.env.EXPIRE_IN_SECS;
exports.refresh = async (event, context) => {
const asyncRedis = require("async-redis");
// const client = asyncRedis.createClient({host: 'bi-cache-server.i1c2dr.ng.0001.use1.cache.amazonaws.com'});
const client = asyncRedis.createClient({host: redisHost});
client.on("error", function (err) {
console.log("Error " + err);
});
const expire = async (key) => {
console.log(key);
const ll = await client.ttl(key);
if (ll < parseInt(<string>expireInSecs, 10) || 0) {
console.log(`expiring key -> ${key}`);
await client.expire(key, 1);
}
};
const asyncBlock = async () => {
const keys = await client.keys('SQL_QUERY_RESULT_CUBEJS_APP*');
const promises = keys.map(expire);
await Promise.all(promises);
};
await asyncBlock();
context.done(null, event);
};