redis-array

0.0.4 • Public • Published

node-redis-array

Basic implementation of RedisArray for NodeJS to be compatible with phpredis

Install with: npm install redis-array

Creating an array

var RedisArray = require('redis-array');
var ra = new RedisArray([{ host: "host1", port: 6379 }, { host: "host2", port: 6379 }]);

Key hashing

By default node-redis-array will try to find a substring enclosed in curly braces within the key name, and use it to distribute the data.

For instance, the keys "{user:1}:name" and "{user:1}:email" will be stored on the same server as only "user:1" will be hashed.

Usage

Redis arrays can be used just as Redis objects:

ra.set("user1:name", "Joe", function(e, reply) {
  // do somethig
});
ra.get("user2:name", function(e, reply) {
  // do something
});

Running KEYS() on a RedisArray object will execute the command on each node and return an associative array of keys, indexed by host name.

Array info

RedisArray objects provide several methods to help understand the state of the cluster. These methods start with an underscore.

  • ra._hosts() → returns a list of hosts for the selected array.
  • ra._target(key) → returns the host to be used for a certain key.
  • ra._instance(host) → returns a redis instance connected to a specific node; use with _target to get a single Redis object.

Readme

Keywords

none

Package Sidebar

Install

npm i redis-array

Weekly Downloads

0

Version

0.0.4

License

GPL-2.0

Last publish

Collaborators

  • yatsukhnenko