0.4.0 • Published 10 years ago

redis-keyshape v0.4.0

Weekly downloads
4
License
-
Repository
github
Last release
10 years ago

redis-keyshape Code Climate Dependency Status

Easily, consistently, clearly access redis keys. Works with node-redis.

Installation

npm install redis-keyshape

API

addKeyshape(db, keyPattern)

TODO

Example

Problem

  • keyname repeated across application
  • Temporary variables for key access
var db = require('redis').createClient();

var key1 = 'foo:' + foo_id;
db.hget(key1, 'foo_field', function(err, foo_field){...});

var key2 = 'foo:' + foo_id + ':bar:' + bar_id;
db.smembers(key2, function(err, members){...});

Solution

var db = require('redis').createClient();
var redisKeyshape = require('redis-keyshape'),

// Augment the db with keyshapes if the key pattern follows convention*.
// * https://github.com/jasonkuhrt/redis-keyshape/issues/7
redisKeyshape(db, 'foo:%s'); // auto-exposes as db.foo
redisKeyshape(db, 'foo:%s:bar:%s'); // auto-exposes as db.foo_bar

// Keyshapes take the same signature except that the key argument
// need only include the keyshape's variable.
db.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.
db.foo_member.smembers([foo_id, bar_id], function(err, members){...})

License

BSD-2-Clause

0.4.0

10 years ago

0.3.0

10 years ago