# merapi-plugin-redis

> Merapi plugin for working with ioredis

Latest version **0.2.1** (published 2018-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install merapi-plugin-redis
pnpm add merapi-plugin-redis
yarn add merapi-plugin-redis
bun add merapi-plugin-redis
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-07-29 |
| First published | 2018-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ricky Anders |
| Maintainers | ikmals, rickyanders, rizqme |
| Keywords | merapi, redis, ioredis |

## Links

- npm: https://www.npmjs.com/package/merapi-plugin-redis
- Repository: https://github.com/kata-ai/merapi-plugin-redis
- Homepage: https://github.com/kata-ai/merapi-plugin-redis#readme
- Issues: https://github.com/kata-ai/merapi-plugin-redis/issues
- npm.io page: https://npm.io/package/merapi-plugin-redis

## Dependencies (2)

- [merapi](https://npm.io/package/merapi.md) ^0.18.3
- [ioredis](https://npm.io/package/ioredis.md) ^3.2.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2018-07-29
- 0.2.0 — 2018-03-19
- 0.1.5 — 2018-02-13
- 0.1.4 — 2018-02-13
- 0.1.3 — 2018-01-16
- 0.1.2 — 2018-01-15
- 0.1.1 — 2018-01-15
- 0.1.0 — 2018-01-15

## README

# Merapi Plugin Redis

## Introduction

[Merapi](https://github.com/kata-ai/merapi) plugin for working with [ioredis](https://github.com/luin/ioredis).

# Quick Start

## Installation

```
npm install merapi-plugin-redis --save
```

## Configuration

```json
{
    "name": "merapi",
    "version": "0.1.0",
    "plugins": [
        "redis"
    ],
    "components": {
        "redisPub": {
            "type": "redis",
            "config": "redisConfig"
        },
        "redisSub": {
            "type": "redis",
            "config": "redisConfig"
        }
    },
    "redisConfig": {
        "type": "single",
        "prefix": "merapi",
        "host": "127.0.0.1",
        "port": "6379",
        "password": "mypassword",
        "ttl": "300",
        "redisHosts": "[{\"host\": \"127.0.0.1\", \"port\": 6379},{\"host\": \"127.0.0.1\", \"port\": \"16379\"}]",
        "sentinelName": "mymaster",
        "args": {}
    }
}
```

The arguments passed to the redis configuration are different from one another, where:

* `type` identifies redis type (`single`, `cluster`, or `sentinel`)
* `prefix` prefix for redis key (key will be `{prefix}:yourkey`)
* `host` redis host
* `port` redis port
* `password` redis auth
* `ttl` default value for ttl
* `redisHosts` (optional) fill this field if you wish to use more than one host. Fill this field in string format
* `sentinelName` (optional) name for sentinel master
* `args` (optional) used as second argument in `cluster` configuration

### Standard Configuration

Example of redis configuration.
```json
    {
        "type": "single",
        "prefix": "merapi",
        "host": "127.0.0.1",
        "port": 6380,
        "password": "mypassword"
    }
```
More information about [redis configuration](https://github.com/luin/ioredis#connect-to-redis)

### Cluster Configuration

```json
    {
        "type": "cluster",
        "prefix": "merapi",
        "password": "mypassword",
        "redisHosts": "[{\"host\": \"127.0.0.1\", \"port\": 6379},{\"host\": \"127.0.0.1\", \"port\": 16379}]",
        "args": {
            "slotsRefreshTimeout": 2000
        }
    }
```
More information about [cluster configuration](https://github.com/luin/ioredis#cluster)

### Sentinel Configuration

```json
    {
        "type": "sentinel",
        "prefix": "merapi",
        "host": "localhost",
        "port": "26379",
        "sentinelName": "mymaster",
        "password": "mypassword"
    }
```
More information about [sentinel configuration](https://github.com/luin/ioredis#sentinel)

## Usage

You can call redis client by using `client` function:
```javascript
import { IRedis } from "merapi-plugin-redis";

export default class YourManager {
    constructor(protected redisRepo: IRedis) {
        super();
    }

    getRedisClient() {
        const redisClient = this.redisRepo.client();
        return redisClient;
    }
}
```
Then you can proceed to use ioredis from `redisClient`.

# License

MIT

---
_Source: https://npm.io/package/merapi-plugin-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
