# redis-odmd

> ODM like for redis cache server.

Latest version **0.2.7** (published 2017-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install redis-odmd
pnpm add redis-odmd
yarn add redis-odmd
bun add redis-odmd
```

## 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.7 |
| Published | 2017-08-25 |
| First published | 2017-08-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Saeid Alidadi |
| Maintainers | saeid_alidadi |
| Keywords | redis, cache, hash, dictionary, store, odm |

## Links

- npm: https://www.npmjs.com/package/redis-odmd
- Repository: https://github.com/saeidalidadi/redis-odmd
- Homepage: https://github.com/saeidalidadi/redis-odmd#readme
- Issues: https://github.com/saeidalidadi/redis-odmd/issues
- npm.io page: https://npm.io/package/redis-odmd

## Dependencies (2)

- [flat](https://npm.io/package/flat.md) ^4.0.0
- [redis](https://npm.io/package/redis.md) ^2.6.5

## 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.7 (latest) — 2017-08-25
- 0.2.6 — 2017-08-24
- 0.2.5 — 2017-08-23
- 0.2.4 — 2017-08-23
- 0.2.3 — 2017-08-22
- 0.2.2 — 2017-08-22
- 0.2.1 — 2017-08-22
- 0.2.0 — 2017-08-21
- 0.0.0 — 2017-08-20
- 0.0.0-development — 2017-08-20

## README

For some use cases we need to have a `ODM` like structure in order to work with our
our stored hash data in `redis`. this module give us all the main methods for that but there
is't already any kind of `schemas` to define or `validations`.

```
npm install redis-odmd
```

## Example

```javascript
const Dictionary = require('redis-odmd');

const options = {
    prefix: 'online', // Prefix for your dictionary
    redis: {
        port: 6379
    }
}

// create your dictionary object
const online_users = Dictionary(options);

let data = {
      name: 'John',
      family: 'Doe',
      address: {
        country: 'Iran',
        city: 'Shiraz'
      }
    };

// Add data to your dictionary (store hash string)
online_users.set('123', data).then(result => {
  
  console.log(result) // OK

}).catch(err) {
  throw(err);
}

// get a field of the user hash
online_users.get('123', 'address.city').then(user => {
  console.log(user.data.address.city)
})
```
## options

Is an object which:

* `prefix` prefix of dictionary
* `keySeperator` for seperating `prefix` and `id` as `prefix<keySeperator>id`.
* `redis` all [redis options](https://www.npmjs.com/package/redis#options-object-properties)

## methods

* `set(id, data<Object|String>)` returns `OK` like redis.

* `get(id)` returns an dictionary object.

* `get(id, property)` returns the property from stored hash.
  
    ### Example

    ```javascript
    // stored hash
    const user = {
      name: 'John',
      family: 'Doe'
    }
    online_users.get(id, 'name').then(result => {
      console.log(result.data.name) // John 
    })
    ```

* `getAll()` returns an object contains all hashes with `key:hash`.

```javascript
online_users.getAll().then(users => {
  // all users
  /*
    {
      id_1: {
        name: 'John',
        family: 'Doe'
      },
      ...
    }
  */
})

```

* `delete(id)` redis return style.

* `exists(id)` redis return style.

* `count()` number of stored hashes in dictionary.

* `create(id, data<Object|String>)` returns an object of dictionary

* `update()` should be called after `get` and will `set` the hash with last changes. returns a promise.

    ### Example

    ```javascript
    online_users.get('123').then(user => {
      user.data.new_field = 'new_field';
      user.update()
    })
    ```

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