@varasto/redis-storage
v3.0.0
Published
Varasto storage that uses Redis as it's backend
Downloads
4
Readme
@varasto/redis-storage
Implementation of storage that uses Redis as backend for storing data.
Installation
$ npm install --save @varasto/redis-storage
Usage
The package provides an function called createRedisStorage
which takes an
Redis client as an argument.
import { createClient } from 'redis';
import { createRedisStorage } from '@varasto/redis-storage';
const client = createClient({ host: 'example.com' });
const storage = createRedisStorage(client);
Custom serializers
By default, JSON.stringify is used for serializing data passed to Redis and
JSON.parse is used for deserializing coming from Redis. However you can also
use your own custom serialization functions by passing them as options to the
createRedisStorage
function.
import { createClient } from 'redis';
import { createRedisStorage } from '@varasto/redis-storage';
import { JsonObject } from 'type-fest';
const client = createClient({ host: 'example.com' });
const storage = createRedisStorage(client, {
serialize: (data: string): JsonObject => {},
deserialize: (data: JsonObject): string => "",
});