Giter Club home page Giter Club logo

rebridge's Introduction

Rebridge

npm

Rebridge is a transparent Javascript-Redis bridge. You can use it to create JavaScript objects that are automatically synchronized to a Redis database.

Install

npm install rebridge

##Usage

var Rebridge = require("rebridge");

// Rebridge takes care of the Redis connection automatically,
// but you can pass an existing Redis client object if you wish.
var db = Rebridge();

db.hello = {world: ["foo", "bar"]};
// The change will be written to the database in real time.

console.log(db.hello.world);
// Prints ["foo", "bar"]

Requirements

Rebridge uses ES6 Proxy objects, so it requires at least Node 6.

Limitations

Rebridge objects can't contain functions, circular references, and in general everything for which x === JSON.parse(JSON.stringify(x)) doesn't hold true.

  • Obviously, you cannot write directly to db (i.e. you can't do var db = Rebridge(); db = "e").

Notable users

Rebridge is used successfully in crisbal/Telegram-Bot-Node@es6 to create a transparent data store for each plugin.

How it works

Rebridge() returns an ES6 Proxy object around {}. When you try to read one of its properties, the getter intercepts the call, retrieves and deserializes the result from the database, and returns that instead; the same happens when you write to it.

The Proxy will forward the native methods and properties transparently, so that the objects it returns should behave the same native objects; if this is not the case, file an issue on GitHub.

First-level objects (eg. db.foo) correspond to keys in the Redis database; they are serialized using JSON. When requesting deeper objects (eg. db.foo.bar.baz), the first-level object (db.foo) is deserialized to a native object, which is then accessed in the standard way.

rebridge's People

Contributors

capacitorset avatar

Watchers

 avatar

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.