@gogoout/cache-manager-redis-store

中文文档
2.1.0发布于 2021/04/12MITCommonJS近 30 天下载 10.8万

Redis 节点管理仓库

中文使用文档
文档目录7 节
  1. 这个软件包和 node-cache-manager-redis ? 吗?
  2. 安装
  3. 用法实例
  4. 单行店
  5. 多层
  6. 捐款
  7. 许可证

build status coverage status dependencies status npm version GitHub issues

节点缓存管理器的 Redis 存储

Redis 缓存存储 节点控制器。 。 。 .

这个软件包和 node-cache-manager-redis? 吗?

这是一个 完全不同的版本 较以往 节点控制器此软件包不使用 redis-pool 这是不必要的,没有积极维护.

这个一揽子计划旨在提供 最简单的包装 通过将配置传递到下面 node_redis 软件包.

安装

npm install cache-manager-redis-store --save

或者说

yarn add cache-manager-redis-store

用法实例

见下文关于如何实施Redis缓存商店的例子.

单行店

var cacheManager = require('cache-manager');
var redisStore = require('cache-manager-redis-store');

var redisCache = cacheManager.caching({
  store: redisStore,
  host: 'localhost', // default value
  port: 6379, // default value
  auth_pass: 'XXXXX',
  db: 0,
  ttl: 600
});

// listen for redis connection error event
var redisClient = redisCache.store.getClient();

redisClient.on('error', (error) => {
  // handle error here
  console.log(error);
});

var ttl = 5;

redisCache.set('foo', 'bar', { ttl: ttl }, (err) => {
  if (err) {
    throw err;
  }

  redisCache.get('foo', (err, result) => {
    console.log(result);
    // >> 'bar'
    redisCache.del('foo', (err) => {
    });
  });
});

function getUser(id, cb) {
  setTimeout(() => {
    console.log("Returning user from slow database.");
    cb(null, { id: id, name: 'Bob' });
  }, 100);
}

var userId = 123;
var key = `user_${userId}`;

// Note: ttl is optional in wrap()
redisCache.wrap(key, (cb) => {
  getUser(userId, cb);
}, { ttl: ttl }, (err, user) => {
  console.log(user);

  // Second time fetches user from redisCache
  redisCache
    .wrap(key, () => getUser(userId))
    .then(console.log)
    .catch(err => {
      // handle error
    });
});

多层

var cacheManager = require('cache-manager');
var redisStore = require('cache-manager-redis-store');

var redisCache = cacheManager.caching({ store: redisStore, db: 0, ttl: 600 });
var memoryCache = cacheManager.caching({ store: 'memory', max: 100, ttl: 60 });

var multiCache = cacheManager.multiCaching([memoryCache, redisCache]);

var userId2 = 456;
var key2 = `user_${userId2}`;

// Set value in all caches
multiCache.set('foo2', 'bar2', { ttl: ttl }, (err) => {
  if (err) {
    throw err;
  }

  // Fetches from highest priority cache that has the key
  multiCache.get('foo2', (err, result) => {
    console.log(result);

    // Delete from all caches
    multiCache.del('foo2');
  });
});

// Note: ttl is optional in wrap
multiCache.wrap(key2, (cb) => {
  getUser(userId2, cb);
}, (err, user) => {
  console.log(user);

  // Second time fetches user from memoryCache, since it's highest priority.
  // If the data expires in the memory cache, the next fetch would pull it from
  // the 'someOtherCache', and set the data in memory again.
  multiCache.wrap(key2, (cb) => {
    getUser(userId2, cb);
  }, (err, user) => {
    console.log(user);
  });
});

捐款

想帮助改进这个套装吗? 我们拿 拖动请求。 。 。 .

许可证

这个 node-cache-manager-redis-store 根据麻省理工学院的许可.

版本与发布记录

@gogoout/cache-manager-redis-store 共发布 1 个版本,首次发布于 2021/04/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2021/04/125 年前

关于 @gogoout/cache-manager-redis-store 的常见问题

@gogoout/cache-manager-redis-store 是什么?

Redis 节点管理仓库

如何安装 @gogoout/cache-manager-redis-store?

在项目目录运行 npm install @gogoout/cache-manager-redis-store,或使用 pnpm add / yarn add / bun add。

@gogoout/cache-manager-redis-store 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/gogoout__cache-manager-redis-store 是否存在。

@gogoout/cache-manager-redis-store 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gogoout/cache-manager-redis-store 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 8.3。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gogoout/cache-manager-redis-store 可以商用吗?

@gogoout/cache-manager-redis-store 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gogoout/cache-manager-redis-store 的下载量有多少?

根据 npm 官方下载统计,@gogoout/cache-manager-redis-store 在 2026/10/17 – 2026/11/15 这 30 天内被下载 108,362 次,日均约 3,612 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gogoout/cache-manager-redis-store 还在维护吗?

最新版本 2.1.0 发布于 2021/04/12(5 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。