GithubHelp home page GithubHelp logo

meteor / miniredis Goto Github PK

View Code? Open in Web Editor NEW
67.0 25.0 5.0 364 KB

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

Home Page: http://atmospherejs.com/package/miniredis

JavaScript 100.00%

miniredis's Introduction

Miniredis

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

var redis = new Miniredis.RedisStore;
redis.set("key-1-1", "foo");
redis.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.

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

Deps.autorun(function () {
  console.log(_.pluck(redis.matching("key-1-*").fetch(), "value"));
});
// prints ["foo"]

redis.set("key-2-1", "baz");
// doesn't print anything

redis.set("key-1-2", "bar");
// prints ["foo", "bar"]

redis.set("key-1-1", "foo1");
// prints ["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.

redis.matching("key-2-*").observe({
  added: function (item) { /* item: { _id, value } */ },
  changed: function (item, oldItem) { /* item: { _id, value} */ },
  removed: 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.

redis.matching("key-2-*").observe({
  addedAt: function (item, atIndex, before) { /* item: { _id, value } */ },
  changedAt: function (item, oldItem, atIndex) { /* item: { _id, value} */ },
  removedAt: 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:

// Pause observers
redis.pauseObservers();
// Make a lot of changes
_.each(removedValues, function (value, key) {
  redis.del(key);
});
_.each(newValues, function (value, key) {
  redis.set(key, value);
});
// Resume
redis.resumeObservers();

Blaze compatibility

Miniredis's cursors can be observed by Blaze:

<template name="orderedList">
  {{#each listItems}}
    <div>{{_id}} - {{value}}</div>
  {{/each}}
</template>
Template.orderedList.listItems = function () {
  return redis.matching("key-2-*");
};

Known Issue

  • on Meteor 0.8.2 returning a miniredis cursor from a template helper Blaze will not observe it properly. It is fixed on the devel branch and will be released in next Meteor version. To workaround it, return a fetched array from cursor.

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

  • set
  • get
  • del
  • exists
  • keys
  • randomkey
  • rename
  • renamenx
  • type
  • append
  • decr
  • decrby
  • getrange
  • getset
  • incr
  • incrby
  • incrbyfloat
  • mget
  • mset
  • msetnx
  • setx
  • setnx
  • setrange
  • strlen

On Hashes

  • hset
  • hsetnx
  • hget
  • hkeys
  • hvals
  • hgetall
  • hincrby
  • hincrbyfloat
  • hdel
  • hmset
  • hmget
  • hlen
  • hexists

On Lists

  • lpush
  • rpush
  • lpop
  • rpop
  • lindex
  • linsert
  • lrange
  • lset
  • ltrim
  • llen
  • lpushx
  • rpushx

License

MIT (c) Meteor Development Group

miniredis's People

Contributors

html5cat avatar justinsb avatar slava avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miniredis's Issues

Questions

  1. How can I connect to remote redis, with this package
  2. HSET function has 3 parameters "key field value", but in the package it's only 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.