npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kodb

v0.1.0

Published

A key-object interface to redis.

Downloads

5

Readme

#kodb

kodb is a simple key/object interface to redis.

While redis allows the user to store and retrieve data in a variety of different ways (strings, hashes, lists...), we often want just a way to store retrieve a JSON-encoded JavaScript object, which is what kodb allows us to do.

To manage the asynchronous interactions with the database, kodb uses promises (provided by the Q library), therefore every public method returns a promise.

##Example usage

var kodb	= require("kodb");
var Q		= require("q");
var _		= require("lodash");

var key;
var object = {
	"foo": "bar"
};

Q()
	.then(function () {
		// Connect to the database
		return kodb.connect();
	})
	.then(function () {
		// Get a unique key
		return kodb.getUniqueKey(8);
	})
	.then(function (uniqueKey) {
		key = uniqueKey;
		// Set key to object
		return kodb.set(key, object);
	})
	.then(function () {
		// Check if key exists
		return kodb.exists(key);
	})
	.then(function (exists) {
		// Get object corresponding to key
		return kodb.get(key);
	})
	.then(function (obj) {
		// Delete key
		return kodb.del(key);
	});
	.then(function () {
		// Disconnect from the database
		return kodb.disconnect();
	});

##API

#####kodb.connect(port, host, options) #####kodb.disconnect() #####kodb.get(key) #####kodb.set(key, object) #####kodb.del(key) #####kodb.exists(key) #####kodb.getUniqueKey(key)


###kodb.connect(port, host, options)

####What it does

Connects itself to the database.

####Parameters

For an explanation of its parameters, check out the node_redis module page.

####Promise behaviour

#####Fulfilled when

The connection to the database is established or was already established.

#####Rejected when

The connection to the database cannot be established.

####Fulfillment value

If the connection is successfully established, none.

If the connection was already established, the string "Already connected.".


###kodb.disconnect()

####What it does

Disconnects itself from the database.

####Paramters

Takes no parameters.

####Promise behaviour

#####Fulfilled when

The connection to the database is established or was already established.

#####Rejected when

Never (only when errors occur?).

####Fulfillment value

If the connection is successfully terminated, none.

If there was no connection, the string "Already disconnected.".


###kodb.get(key)

####What it does

Gets an object from the database.

####Paramters

A string, i.e. the key to get from the database.

####Promise behaviour

#####Fulfilled when

The object is retrieved successfully from the database.

#####Rejected when

Only when errors occur.

####Fulfillment value

If the corresponding value in the database is a JSON-encoded object, that object (already parsed).

Otherwise, undefined.


###kodb.set(key, object)

####What it does

Sets a key/object pair into the database.

####Paramters

First parameter, a string, i.e. the key at which to save the object.

Second parameter, a plain object, i.e. the object which needs to be saved.

####Promise behaviour

#####Fulfilled when

The object is saved successfully into the database.

#####Rejected when

Only when errors occur.

####Fulfillment value

None.


###kodb.del(key)

####What it does

Deletes a key/object pair from the database.

####Paramters

A string, i.e. the key of the pair which needs to be deleted.

####Promise behaviour

#####Fulfilled when

The pair is deleted successfully from the database.

#####Rejected when

Only when errors occur.

####Fulfillment value

None.


###kodb.exists(key)

####What it does

Checks if a given key already exists in the database.

####Paramters

A string, i.e. the key which needs to be checked.

####Promise behaviour

#####Fulfilled when

The database answers whether or not the given key exists.

#####Rejected when

Only when errors occur.

####Fulfillment value

True if the key exists, false if it doesn't.


###kodb.getUniqueKey([length])

####What it does

Gets a unique key, i.e. a key which does not exist yet in the database.

####Paramters

Optionally, a number, which is the length of the key to get. The max length is 1024.

####Promise behaviour

#####Fulfilled when

The unique key is found.

#####Rejected when

Only when errors occur.

####Fulfillment value

The key.