Cache
Cache
提供缓存的功能,可以缓存一些复杂计算的结果。
用法
需要引入@giteeteam/apps-api
import { Cache } from '@giteeteam/apps-api';
const run = async () => {
const myCache = new Cache({
ttl: 3600 * 1000, // ttl,单位毫秒,默认1分钟
})
// 设置缓存
await myCache.set('cache-key', 'cache-value');
// 可以单独设置ttl
await myCache.set('cache-key', 'cache-value', { ttl: 60 * 1000 })
// 获取缓存
await myCache.get('cache-key');
// 删除缓存
await myCache.del('cache-key');
// 将 key 中储存的数字值增一
await myCache.incr('cache-key');
// 将 key 所储存的值加上给定的增量值(increment)
await myCache.incrby('cache-key', 10);
// 将 key 中储存的数字值减一
await myCache.decr('cache-key');
// key 所储存的值减去给定的减量值(decrement)
await myCache.decrby('cache-key', 10);
// 定义一个lua脚本命令
await myCache.defineCommand("command-name", {
lua: "..........定义lua脚本"
});
// 执行上述定义的lua脚本
await myCache.execCommand("command-name" ,[arg1, arg2, arg3]);
}