# ut-port-redis

> A redis object caching port

Latest version **1.0.7** (published 2022-06-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ut-port-redis
pnpm add ut-port-redis
yarn add ut-port-redis
bun add ut-port-redis
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-06-23 |
| First published | 2022-06-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Software Group |
| Maintainers | kalin.krustev |
| Keywords | cache, key-value, redis, catbox |

## Links

- npm: https://www.npmjs.com/package/ut-port-redis
- Repository: https://github.com/softwaregroup-bg/ut-port-redis
- Homepage: https://github.com/softwaregroup-bg/ut-port-redis#readme
- Issues: https://github.com/softwaregroup-bg/ut-port-redis/issues
- npm.io page: https://npm.io/package/ut-port-redis

## Dependencies (1)

- [ioredis](https://npm.io/package/ioredis.md) ^5.0.6

## 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

- 1.0.7 (latest) — 2022-06-23
- 1.0.6 — 2022-06-22

## README

# ut-port-redis

`ut-port-redis` is a redis object caching port.
It is a convinient wrapper for [ionredis](https://github.com/luin/ioredis)
and provides on top of that the standard `ut` mechanisms for logging,
monitoring, error handling, etc. inherited from
[ut-port](https://github.com/softwaregroup-bg/ut-port).

## Usage

This port can be used the same way as any other `ut` compliant port.
For more information about how to bootstrap a `ut port` click [here](https://github.com/softwaregroup-bg/ut-run)

## Configuration

Besides `logLevel`, `concurrency`, and other configuration options
which are common for all ports, ut-port-redis defines 2 additional
properties:

* **`client`** - This object provides a low-level cache abstraction.
  * `options` - The strategy configuration object

More information about how to configure the policy `options`
can be found [here](https://github.com/luin/ioredis/blob/v4/API.md#new-redisport-host-options)

### Configuration example

```javascript
function cache() {
    return class cache extends require('ut-port-redis')(...arguments) {
        get defaults() {
            options: {} // ionredis-redis options
        }
    };
}
```

## API

By setting up the port using the
[example](#configuration-example) above it will expose the following set of
methods available through [ut-bus](https://github.com/softwaregroup-bg/ut-bus):

* `bus.importMethod('cache/module.entity.action')(msg, $meta)`

  * `module.entity.action` is arbitrary string, usually corresponding to a
  namespaced method call
  * `msg` is the value for the cache operation and has the following
    structure {`operation`, `key`, `value` }
    * `operation` is a valid redis command
    * `key` is a string identifier used to locate/create a key value pair
    * `value` is optional depending on the redis operation
  * `$meta` contains the metadata associated with the request
  * `return` value is determined by the redis operation

## Example

This is a trivial example illustrating a set and get operation

```javascript
const msg = {
    key : 'foo',
    operation: 'set',
    value: 'bar'
}
Promise.resolve()
    .then(result => {
        return bus.importMethod('cache/module.foo.set')(msg, $meta)
                // returns promise which resolves to string, "OK"
                .then(() => { 
                    return bus.importMethod('cache/module.foo.get')({
                      key : 'foo',
                      operation: 'get'
                    }, $meta) // Promise resolves to "bar"
                });
    })
    .catch(e => { // an exception in case any of the above calls fail
        throw e;
    });
```

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