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()
但是從測試:爲什麼redis命令不能在我的咖啡腳本文件的mocha測試中工作?
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'打印。
這是當我運行:
摩卡咖啡--compilers:咖啡腳本
Redis的似乎只是停止工作。有任何想法嗎?