Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@javien/mikro-orm-redis-cache-adapter

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

@javien/mikro-orm-redis-cache-adapter - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

100

dist/index.js

@@ -23,3 +23,4 @@ "use strict";

__export(src_exports, {
Options: () => Options
Options: () => Options,
RedisCacheAdapter: () => RedisCacheAdapter
});

@@ -59,5 +60,100 @@ module.exports = __toCommonJS(src_exports);

};
// src/redisCacheAdapter.ts
var import_node_v8 = require("node:v8");
var RedisCacheAdapter = class {
options;
serializer = import_node_v8.serialize;
deserializer = import_node_v8.deserialize;
constructor(options) {
this.options = options instanceof Options ? options : new Options(options);
}
async get(name) {
try {
const key = this.generateKey(name);
const data = await this.options.client.getBuffer(key);
if (!data) {
return void 0;
}
const deserializedData = this.deserializer(data);
this.debug("Get", key, deserializedData);
return deserializedData;
} catch (error) {
this.options.logger("Failed to fetch data.");
this.options.logger(error);
return void 0;
}
}
async set(name, data, _origin, expiration) {
try {
const key = this.generateKey(name);
const serializedData = this.serializer(data);
if (expiration) {
this.options.client.set(key, serializedData, "PX", expiration);
} else {
this.options.client.set(key, serializedData);
}
this.debug("Set", key, data);
} catch (error) {
this.options.logger("Failed to store data.");
this.options.logger(error);
}
}
async remove(name) {
try {
const key = this.generateKey(name);
await this.options.client.del(key);
this.debug("Remove", key, void 0);
} catch (error) {
this.options.logger("Failed to remove data.");
this.options.logger(error);
}
}
clear() {
return new Promise((resolve, reject) => {
const stream = this.options.client.scanStream({
match: `${this.options.prefix}${this.options.prefixDelimiter}*`
});
const pipeline = this.options.client.pipeline();
stream.on("data", (keys) => {
if (keys.length === 0) {
return;
}
for (const key of keys) {
pipeline.del(key);
}
});
stream.on("end", () => {
pipeline.exec((err) => {
if (err) {
this.options.logger("Failed to clear data.");
this.options.logger(err);
return reject(err);
}
this.options.logger("Cache has been successfully cleared.");
resolve();
});
});
});
}
close() {
if (!this.options.gracefulShutdown) {
return;
}
this.options.client.disconnect();
}
debug(method, key, data) {
if (!this.options.debug) {
return;
}
this.options.logger(`${method} ${key}: ${JSON.stringify(data)}`);
}
generateKey(name) {
return `${this.options.prefix}:${name}`;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Options
Options,
RedisCacheAdapter
});

2

dist/redisCacheAdapter.d.ts
import type { CacheAdapter } from '@mikro-orm/core';
import type { RedisCacheAdapterOptions } from './options';
export default class RedisCacheAdapter implements CacheAdapter {
export declare class RedisCacheAdapter implements CacheAdapter {
private readonly options;

@@ -5,0 +5,0 @@ private readonly serializer;

@@ -5,3 +5,3 @@ {

"description": "",
"version": "0.0.8",
"version": "0.0.9",
"author": "Javien Lee <kraccoon@dimipay.io> (https://github.com/SnowMarble/)",

@@ -8,0 +8,0 @@ "keywords": ["mikro-orm", "redis", "cache", "adapter"],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc