       callback = args.shift()
 
     # FIXME this is not atomic, is it a problem?
-    app.redis.client.get key, (err, oldValue) ->
+    app.redis.client.get buildKey(key), (err, oldValue) ->
       data = new Data(key, oldValue)
       if value?
         data.setValue(value)

          app.redis.client.publish("newData", @key)
          app.redis.client.sadd(KEYS_SET_NAME, @key)
        else
          app.redis.client.publish(@key, @value)

        app.redis.client.set @key, @value, (=> callback(@) if callback?)

      @

  Data.find = (pattern, callback) ->

    foundRecord = (key) ->
      app.redis.client.get key, (err, value) ->
        error = "Record not found" unless value?
        callback(new Data(key, value), error) if callback?


globalEventEmitter = new EventEmitter()
events = {}

KEYS_SET_NAME = 'topics'

module.exports = (app) ->

