Database Reference
In-Depth Information
First, Redis configuration parameters are added to the arguments for the
server in dashboard/index.js :
var argv = require('optimist')
.usage("Usage: $0")
.options("port",{alias:"P",default:3000})
.options("redis",{alias:"r"})
.options("counters",{alias:"c",default:"counters"})
.argv
;
These are used to drive the selection of the appropriate counter library:
var counters = argv.redis ?
require('./lib/counters-redis')(
argv.redis,
{counters:argv.counters})
: require('./lib/counters');
Theinterfacecodehasalreadybeenwritteninacallbackstyle,sonochanges
are required to that portion of the interface. Likewise, both the SSE and
WebSocket interfaces have been implemented to respond to events emitted
by the Counter class. The only thing that needs to be implemented is the
new Counter class itself.
Rather than simply creating a singleton object, the new Counter class
needs to take in parameters that identify the location of the Redis server.
This is used to construct two Redis connections. The first, called client ,
is used for all normal Redis operations. The second, called pubsub , is used
to handle the event delivery for Redis operations. The reason two client
connections are used is because Node's Redis client is placed into a special
mode when the subscribe command is used; that mode prevents the
client from executing normal Redis operations, found in dashboard/lib/
counters-redis/index.js :
function Counter(host,options) {
//Returns the singleton instance if it exists
if(arguments.callee.__instance) {
return arguments.callee.__instance;
Search WWH ::




Custom Search