node-payments
Version:
node-payments is a express based facade to multiple payment services.
84 lines (73 loc) • 1.76 kB
text/coffeescript
_ = require( "lodash" )
module.exports = class RedisHashStore extends require( "../basic" )
defaults: =>
return super,
hkey: "nodepaymentexample"
host: "localhost"
port: 6379
options: {}
redis: null
constructor: ->
super
# just a simulation to globaly handle server powered stores
= false
return
connect: =>
if .redis?.constructor?.name is "RedisClient"
= .redis
else
try
redis = require("redis")
catch _err
return
= redis.createClient( .port or 6379, .host or "127.0.0.1", .options or {} )
= .connected or false
.on "connect", =>
= true
return
.on "error", ( err )=>
if err.message.indexOf( "ECONNREFUSED" )
= false
else
return
return
get: ( id, cb )=>
process.nextTick =>
.hget .hkey, id, ( err, data )=>
if err
cb( err )
return
cb( null, JSON.parse( data ) )
return
return
return
set: ( payment, cb )=>
process.nextTick =>
.hset .hkey, payment.id, payment.toString(), ( err, done )=>
if err
cb( err )
return
"saved", payment.id, payment.toString()
cb( null )
return
return
return
destroy: ( payment, cb )=>
process.nextTick =>
"destroy", payment.id
.hdel .hkey, payment.id, ( err, done )=>
cb( err )
return
return
return
clear: ( cb )=>
"clear"
.del .hkey, ( err, done )=>
cb( err )
return
return