Add namespace option to allow segmenting keys #89

merged 3 commits into from Mar 13, 2013


None yet
3 participants

I have added a 'namespace' option when initializing the memcache client. It adds a sentinel to all key access. This allows multiple servers to talk to the same daemon without key collisions.


ronkorving commented Mar 13, 2013

I actually do the same thing myself (outside of node-memcached), but it's true that if the library would provide for this, it would remove the need for this added layer. I do think that multiget responses should strip the namespace though. Your patch doesn't do that, does it?

Good catch! I was not stripping the sentinel off on the multiget return. I have fixed that and added a test case for that.

This is not 100% safe, is it? The location of this namespace may only be at character 0, right?
Perhaps this would be more reliable:

if (ns_key.substr(0, memcached.namespace.length) === memcached.namespace) {
  ns_key = ns_key.substr(memcached.namespace.length);

For the sake of performance, I would only do this operation if a namespace has been set. Other wise it will just be a pointless iteration that doesn't help you in any way.

Also @ronkorving I'm not sure how unsave it is as replace only removes the first found value.'foofoo'.replace('foo', '') === 'foo'.

Good point, and I guess multigets can only return namespaced keys, as that's the only thing queried for. I stand corrected.

I have conditionalized the key munging for multi get to only run if a namespace is actually set.


3rd-Eden commented Mar 13, 2013

i'll see if I can merge this in tonight

@3rd-Eden 3rd-Eden added a commit that referenced this pull request Mar 13, 2013

@3rd-Eden 3rd-Eden Merge pull request #89 from BoboFraggins/master
Add namespace option to allow segmenting keys

@3rd-Eden 3rd-Eden merged commit 99f5ce8 into 3rd-Eden:master Mar 13, 2013

1 check passed

default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment