Skip to content

Commit

Permalink
better design
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Manzanares committed Jul 20, 2012
1 parent b7c58e8 commit 77da488
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,43 @@ default port

var connect = require('connect'),
RedisStore = require('connect-redis')(connect),
redisClient = require('heroku-redis-client')();
redis = require('heroku-redis-client');


connect.createServer(
connect.cookieParser(),
connect.session({ store: new RedisStore({ client: redisClient }), secret: 'keyboard cat' })
connect.session({ store: new RedisStore({ client: redis.createClient() }), secret: 'keyboard cat' })
);

See https://github.com/visionmedia/connect-redis/ for information on how to use the returned redisClient as your session store

### Using redis as your data store

var redisClient = require('heroku-redis-client')()
var redis = require('heroku-redis-client'),
redisClient = redis.createClient();
redisClient.set('key', 'value');

See https://github.com/mranney/node_redis for information on how to use the returned redisClient
See https://github.com/mranney/node_redis for information on how to use the wrapped redis

## Source

var redis = require('redis'),
url = require('url');

module.exports = function () {
exports.createClient = function (port_arg, host_arg, options) {
var client;
if (process.env.REDISTOGO_URL) {
var redisURL = url.parse(process.env.REDISTOGO_URL);
client = redis.createClient(redisURL.port, redisURL.hostname);
client = redis.createClient(redisURL.port, redisURL.hostname, options);
client.auth(redisURL.auth.split(":")[1]);
} else {
client = redis.createClient();
client = redis.createClient(port_arg, host_arg, options);
}

return client;
}
};

exports.redis = redis;


## License
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
var redis = require('redis'),
url = require('url');

module.exports = function () {
exports.createClient = function (port_arg, host_arg, options) {
var client;
if (process.env.REDISTOGO_URL) {
var redisURL = url.parse(process.env.REDISTOGO_URL);
client = redis.createClient(redisURL.port, redisURL.hostname);
client = redis.createClient(redisURL.port, redisURL.hostname, options);
client.auth(redisURL.auth.split(":")[1]);
} else {
client = redis.createClient();
client = redis.createClient(port_arg, host_arg, options);
}

return client;
}
};

exports.redis = redis;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heroku-redis-client",
"version": "0.1.1",
"version": "0.2.0",
"description": "redis client that works with heroku redis to go",
"main": "index.js",
"homepage": "https://github.com/cmanzana/heroku-redis-client",
Expand Down
8 changes: 6 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
var tap = require('tap');
var redis = require('../index');

tap.test('load works', function (t) {
var redisClient = require('../index')();
var redisClient = redis.createClient();

t.ok(redisClient, "object loaded");
t.ok(redisClient, "local client created");
t.equal(redisClient.port, 6379);
t.equal(redisClient.host, "127.0.0.1");

t.ok(redis.redis, "redis object available");

t.end();

redisClient.quit();
Expand Down

0 comments on commit 77da488

Please sign in to comment.