BankersBox - A Redis-like API for localStorage


– 163 words

Today I am happy to announce the open-sourcing of BankersBox, a javascript library I have been developing inside Twilio.

BankersBox is a Redis-like API wrapper for javascript client-side data storage. By default it uses localStorage as the persistence layer.

I have a more detailed writeup over on the Twilio Engineering Blog, and there is extensive documentation on the official BankersBox repo at GitHub.

Here are some of the things you can do with BankersBox:

var bb = new BankersBox(1);

bb.set("foo", "bar");
bb.get("foo"); // returns "bar"

bb.set("myobject", {greeting: "hello", thing: "world"});
bb.get("myobject"); // returns the object

bb.set("count", 10);
bb.incr("count"); // sets "count" to 11, returns 11

bb.incr("newcount"); // sets "newcount" to 1, returns 1

bb.lpush("mylist", "hello");
bb.lrange("mylist", 0, -1); // returns ["hello"]

bb.rpush("mylist", "world");
bb.lrange("mylist", 0, -1); // returns ["hello", "world"]

bb.sadd("myset", "apple");
bb.sadd("myset", "oragne");
bb.smembers("myset"); // returns ["apple", "orange"]
bb.sismember("myset", "apple"); // returns true
bb.sismember("myset", "lemon"); // returns false
bb.scard("myset"); // returns 2

BankersBox has an MIT license, so please fork and contribute!

— Fin.
Tagged: bankersbox javascript open-source redis twilio

Like this post? Please share the love!
blog comments powered by Disqus