Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Redis standalone caching library for Node.JS and also cache engine for [cacheman](https://github.com/cayasso/cacheman).

Edit: Implemented ioredis to the library and allowed Cluster connections.

## Instalation

``` bash
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"devDependencies": {
"mocha": "*",
"pre-commit": "1.2.2",
"redis": "^2.8.0"
"ioredis": "^4.14.0"
},
"dependencies": {
"each": "1.2.1",
"parse-redis-url": "0.0.2"
},
"peerDependencies": {
"redis": "2.x"
"ioredis": "^4.14.0"
},
"pre-commit": [
"test"
Expand Down
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* Module dependencies.
*/

const redis = require('redis')
const Redis = require('ioredis')
const parser = require('parse-redis-url')
const each = require('each')

/**
* Module constants.
*/

const parse = parser(redis).parse
const parse = parser(Redis).parse
const noop = () => {}

class RedisStore {
Expand All @@ -28,17 +28,19 @@ class RedisStore {
options = parse(options)
}

const { port, host, client, setex, password, database, prefix } = options
const { port, host, client, setex, password, database, prefix, cluster} = options

if ('function' === typeof setex) {
this.client = options
} else if (client) {
this.client = client
} else if (!port && !host) {
this.client = redis.createClient()
} else {
} else if (!port && !host && !cluster) {
this.client = new Redis();
} else if(!cluster) {
const opts = Object.assign({}, options, { prefix: null })
this.client = redis.createClient(port, host, opts)
this.client = new Redis(port, host, opts)
}else {
this.client = new Redis.Cluster(...cluster)
}

if (password) {
Expand All @@ -50,6 +52,7 @@ class RedisStore {
if (database) {
this.client.select(database, (err) => {
if (err) throw err
this.client.selected_db = database
})
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const redis = require('redis')
const redis = require('ioredis')
const Cache = require('../src')

const uri = 'redis://127.0.0.1:6379/5'
Expand Down