memcachier / memjs

A memcache client for node using the binary protocol and SASL authentication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error not set on get?

cappelaere opened this issue · comments

in node console
$ var memjs = require('memjs')
$ var client = memjs.Client.create()
$ client.get('hello', function(err, val) { console.log("err:"+err+" - val:"+val); })

$ err:null - world
$ client.get('nohello', function(err, val) { console.log("err:"+err+"- val:"+val); })
$ err:null - null

Assuming that 'hello' was set to 'world'
First call works as advertized
Second call should fail. It returns no data and err is not set.
??

Would be nicer to return "key not found" error.
There is a big difference with a key not found and a key set to null.

Thanks,
Pat

hrm... there is no way to get a null for an existing key, only an empty string. In the memcache protocol, it is possible to set a key to the empty string (""), but not to null.

Some libraries, like Dalli for Ruby, actually serialize all values, so Ruby's nil get's serialized to the bytestring "\x04\b0". So the actual value from the perspective of memcache is non-null. MemJs is, by design, as close to the protocol as possible---you can put whatever layer on top you want.

None-the-less, I'm not sure there's any harm in also setting the err to "key not found", so I'm happy to take a pull request.