Socket
Book a DemoInstallSign in
Socket

@braken/cache-ioredis

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braken/cache-ioredis

somethings

1.1.32
latest
npmnpm
Version published
Maintainers
1
Created
Source

@braken/cache-ioredis

Braken 框架的 Redis 缓存实现,基于 IORedis 提供高性能的分布式缓存支持。

安装

pnpm add @braken/cache-ioredis

特性

  • 基于 IORedis 的高性能缓存实现
  • 支持分布式缓存
  • 支持过期时间设置
  • 支持 JSON 序列化
  • 支持键前缀管理
  • 依赖注入集成

使用示例

import { Application } from '@braken/application';
import IORedisCache from '@braken/cache-ioredis';
import { IORedis } from '@braken/ioredis';

// 设置缓存前缀
IORedisCache.prefix('my-app');

// 创建缓存实例
const cache = new IORedisCache();

// 写入缓存
await cache.write('user:1', { id: 1, name: 'John' }, Date.now() + 3600000); // 1小时后过期

// 读取缓存
const user = await cache.read('user:1');

// 检查缓存是否存在
const exists = await cache.has('user:1');

// 获取过期时间
const expireTime = await cache.expire('user:1');

// 删除缓存
await cache.delete('user:1');

API

IORedisCache 类

主要的缓存实现类,提供以下功能:

  • 缓存读写
  • 过期时间管理
  • 键前缀管理
  • 依赖注入集成

静态方法

prefix

设置缓存键前缀:

static prefix(value: string)

实例方法

write

写入缓存:

async write(key: string, value: any, time: number = 0)

read

读取缓存:

async read(key: string)

expire

获取过期时间:

async expire(key: string)

delete

删除缓存:

async delete(key: string)

has

检查缓存是否存在:

async has(key: string)

依赖注入

@Application.Injectable
class MyService {
  @Application.Inject(IORedisCache)
  private readonly cache: IORedisCache;
}

许可证

MIT

FAQs

Package last updated on 09 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.