 # @param {Function} callack Calls back with (err, deserializedHash)
 
 @getHash = (key, hash, callback) ->
+  return callback null, null unless client?
   client.get key, (err, json) ->
     return callback(err) if err
     if json

# @param {Object} hash

@setHash = (key, hash) ->
  serialized = {}
  serialized[k] = JSON.stringify(v) for k, v of hash
  client.set key, JSON.stringify hash

# Retrieves a serialized hash from `setHashToJSON` and deserializes it into models and
# collections. Pass in a hash of key: Model/Colllection class pairs to indicate what each

#

_ = require 'underscore'
{ NODE_ENV, DEFAULT_CACHE_TIME, REDIS_URL, DEFAULT_CACHE_TIME } = require '../config'
redis = require 'redis'
client = null

# Setup redis client
if NODE_ENV isnt "test" and REDIS_URL
  red = require("url").parse(REDIS_URL)
  client = redis.createClient(red.port, red.hostname)
  client.auth(red.auth.split(":")[1]) if red.auth

# Export the redis client
@client = client
