class ThingWithRedis
constructor: (@config) ->
@redis = require('redis').createClient()
push: (key, object) ->
@redis.set(key, object)
fetch: (key, amount) ->
@redis.get key, (err, replies) ->
console.log "|#{replies}|"
module.exports = ThingWithRedis
#if you uncomment these lines and run this file, redis works
#twr = new ThingWithRedis('some config value')
#twr.push('key1', 'hello2')
#twr.fetch('key1', 1)
#twr.redis.quit()
但从测试中:
ThingWithRedis = require '../thing_with_redis'
assert = require('assert')
describe 'ThingWithRedis', ->
it 'should return the state pushed on', ->
twr = new ThingWithRedis('config')
twr.push('key1', 'hello1')
twr.fetch('key1', 1)
assert.equal(1, 1)
你永远不会看到'hello1'被打印出来。
但是当我直接运行咖啡 thing_with_redis.coffee 并且底线未注释时,您确实看到打印了“hello2”。
这是我跑步的时候:
mocha --compilers 咖啡:咖啡脚本
redis 似乎只是停止工作。有任何想法吗?