This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from joshuah/0.2
0.2.0
- Loading branch information
Showing
9 changed files
with
427 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
examples | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var util = require('util'); | ||
var RedisPool = require('../index'); | ||
|
||
var LOG_MESSAGE = "Available: %s, Pool Size: %s"; | ||
|
||
var redisSettings = { | ||
// Use TCP connections for Redis clients. | ||
host: "127.0.0.1", | ||
port: 6379, | ||
// Set a redis client option. | ||
auth_pass: "dingbats" // Authenticate using the password dingbats... | ||
} | ||
|
||
var poolSettings = { | ||
// Set the max milliseconds a resource can go unused before it should be destroyed. | ||
idleTimeoutMillis: 5000, | ||
max: 5 | ||
// Setting min > 0 will prevent this application from ending. | ||
}; | ||
|
||
// Create the pool. | ||
var pool = RedisPool(redisSettings, poolSettings); | ||
|
||
// Get connection errors for logging... | ||
pool.on("error", function(reason) { | ||
console.log("Connection Error:", reason); | ||
}) | ||
|
||
pool.acquire(clientConnection); | ||
function clientConnection(err, client) { | ||
console.log(err) | ||
// Issue the PING command. | ||
client.ping(getPingResponse); | ||
|
||
function getPingResponse(err, response) { | ||
console.log("getPingResponse", err, response); | ||
setTimeout(delayResponse, 2500); | ||
} | ||
function delayResponse() { | ||
// Release the client after 2500ms. | ||
pool.release(client); | ||
} | ||
} | ||
|
||
// Setup up a poller to see how many objects are in the pool. Close out when done. | ||
var poller = setInterval(pollRedisPool, 500) | ||
|
||
function pollRedisPool() { | ||
console.log(util.format(LOG_MESSAGE, pool.availableObjectsCount(), pool.getPoolSize())); | ||
if (pool.availableObjectsCount() == 0 && pool.getPoolSize() == 0) { | ||
clearInterval(poller); | ||
console.log('There are no more requests in this pool, the program should exit now...'); | ||
} | ||
} | ||
|
||
|
||
|
||
|
Oops, something went wrong.