@varasto/redis-storage

Varasto storage that uses Redis as it's backend

Usage no npm install needed!

<script type="module">
  import varastoRedisStorage from 'https://cdn.skypack.dev/@varasto/redis-storage';
</script>

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 => "",
});