meteor/miniredis

Name: miniredis

Owner: Meteor

Description: javascript in-memory implementation of Redis API with observe changes interface and reactivity

Created: 2014-06-26 22:53:50.0

Updated: 2017-06-29 12:16:51.0

Pushed: 2014-10-29 20:08:47.0

Homepage: http://atmospherejs.com/package/miniredis

Size: 364

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Miniredis

This is an all-javascript in-memory implementation of the Redis API, adapted for Meteor.

redis = new Miniredis.RedisStore;
s.set("key-1-1", "foo");
s.set("key-1-2", "bar");

You can install it by running:

meteor add slava:miniredis
Reactivity

This implementation supports Deps.js reactivity with fine-grained reactivity: if a command was run in a Deps.autorun computation, then the minimal set of dependencies will be tracked.

redis = new Miniredis.RedisStore;
s.set("key-1-1", "foo");

.autorun(function () {
nsole.log(_.pluck(redis.matching("key-1-*").fetch(), "value"));

rints ["foo"]

s.set("key-2-1", "baz");
oesn't print anything

s.set("key-1-2", "bar");
rints ["foo", "bar"]

s.set("key-1-1", "foo1");
rints ["foo1", "bar"]
Observe API

Similar to Minimongo's Cursor's, Miniredis Cursors (as returned by redis.matching("*-pattern-*") calls) can be observed with added, changed and removed callbacks.

s.matching("key-2-*").observe({
ded: function (item) { /* item: { _id, value } */ },
anged: function (item, oldItem) { /* item: { _id, value} */ },
moved: function (item) { /* item: { _id, value } */ }

You can also have an ordered observe by passing addedAt, changedAt, removedAt callbacks. The current order is the lexicographical order of keys.

s.matching("key-2-*").observe({
dedAt: function (item, atIndex, before) { /* item: { _id, value } */ },
angedAt: function (item, oldItem, atIndex) { /* item: { _id, value} */ },
movedAt: function (item, atIndex) { /* item: { _id, value } */ }

observeChanges is also implemented but it is not very different from the observe version as of yet.

You can pause/resume observers with the same API as of Minimongo:

ause observers
s.pauseObservers();
ake a lot of changes
ch(removedValues, function (value, key) {
dis.del(key);

ch(newValues, function (value, key) {
dis.set(key, value);

esume
s.resumeObservers();
Blaze compatibility

Miniredis's cursors can be observed by Blaze:

plate name="orderedList">
#each listItems}}
<div>{{_id}} - {{value}}</div>
/each}}
mplate>
avascript
late.orderedList.listItems = function () {
turn redis.matching("key-2-*");

Known Issue
Redis API compatibility

To support Meteor's latency compensation, this implementation tries to mimic the behavior of the Redis server.

Right now these Redis commands are implemented and available:

On Strings
On Hashes
On Lists
License

MIT (c) Meteor Development Group


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.