Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/redis-keyshape
Easily, consistently, clearly access redis keys.
https://github.com/mcollina/redis-keyshape
Last synced: 13 days ago
JSON representation
Easily, consistently, clearly access redis keys.
- Host: GitHub
- URL: https://github.com/mcollina/redis-keyshape
- Owner: mcollina
- Created: 2014-02-13T18:55:50.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-14T16:19:20.000Z (almost 11 years ago)
- Last Synced: 2024-12-17T15:43:05.530Z (23 days ago)
- Language: JavaScript
- Homepage:
- Size: 109 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redis-keyshape [![Code Climate](https://codeclimate.com/github/jasonkuhrt/redis-keyshape.png)](https://codeclimate.com/github/jasonkuhrt/redis-keyshape) [![Dependency Status](https://gemnasium.com/jasonkuhrt/redis-keyshape.png)](https://gemnasium.com/jasonkuhrt/redis-keyshape)
Easily, consistently, clearly access redis keys.
## Installation
```
npm install redis-keyshape
```## API
#### addKeyshape(redisClient, keyPattern)
TODO#### createKeyshape(redisClient, keyPattern)
TODO## Example
### Problem
- keyname repeated across application
- Temporary variables for key access```js
var redisClient = require('redis').createClient();var key1 = 'foo:' + foo_id;
redisClient.hget(key1, 'foo_field', function(err, foo_field){...});var key2 = 'foo:' + foo_id + ':bar:' + bar_id;
redisClient.SMEMBERS(key2, function(err, members){...});
```### Solution
```js
var redisClient = require('redis').createClient();
var keyshape = require('redis-keyshape'),
createKeyshape = keyshape.createKeyshape,
addKeyshape = keyshape.addKeyshape;// Create some keyshapes.
redisClient.foo = createKeyshape(redisClient, 'foo:%s');
redisClient.fooBar = createKeyshape(redisClient, 'foo:%s:bar:%s');// OR, augment the redisClient with keyshapes if the key pattern follows convention*.
// * https://github.com/jasonkuhrt/redis-keyshape/issues/7addKeyshape(redisClient, 'foo:%s'); // auto-exposes as redisClient.foo
addKeyshape(redisClient, 'foo:%s:bar:%s'); // auto-exposes as redisClient.foo_bar// Keyshapes take the same signature except that the key argument
// need only include the keyshape's variable.redisClient.foo.hget(foo_id, 'foo_field', function(err, foo_field){...})
// Often keyshapes require multiple variables. In such cases use an array
// to provide the keyshape variables.redisClient.foo_member.SMEMBERS([foo_id, bar_id], function(err, members){...})
```## Notes
Only works with [`node-redis`](https://github.com/mranney/node_redis).
## License
BSD-2-Clause