@lindorm-io/redis
TypeScript icon, indicating that this package has built-in type declarations

0.12.6 • Public • Published

@lindorm-io/redis

Redis cache tools lindorm.io packages

Installation

npm install --save @lindorm-io/redis

Usage

Redis Connection

const connection = new RedisConnection({
  host: "localhost",
  port: 6379,
  logger,
});

await connection.connect();
const client = connection.client;

await client.set("key", JSON.stringify({ blobify: "data" }));
const data = await client.get("key");
await client.del("key");

await connection.disconnect();

Lindorm Cache

export class TestCache extends LindormCache<TestEntityAttributes, TestEntity> {
  public constructor(options: CacheBaseOptions) {
    super({
      ...options,
      entityName: "TestEntity",
      indexedAttributes: ["name"],
      ttlAttribute: "expires",
    });
  }

  protected createEntity(data: TestEntityAttributes): TestEntity {
    return new TestEntity(data);
  }
}

const cache = new TestCache({
  connection,
  logger,
});

await cache.create(entity);
await cache.createMany([entity, anotherEntity]);

await cache.deleteMany({ name: "destroy" });
await cache.destroy(entity);
await cache.destroyMany([entity, anotherEntity]);

await cache.find({ id: "id" });
await cache.findMany({ name: "name" });

await cache.findOrCreate({ name: "name" });
await cache.tryFind({ name: "name" });

await cache.ttl(entity);

await cache.update(entity);
await cache.updateMany([entity, anotherEntity]);

Readme

Keywords

none

Package Sidebar

Install

npm i @lindorm-io/redis

Weekly Downloads

3

Version

0.12.6

License

AGPL-3.0-or-later

Unpacked Size

86.1 kB

Total Files

88

Last publish

Collaborators

  • princejonn