Skip to content

Feature: Key wrapper #132

Description

@vanatd

Hi guys, i'm thinking about feature to add to memjs, but i want to discuss it with you.

For example, i have several clients for different cases, but they work with one memcached server (not server.js) and i want their keys be unique.
Or i'm working with one version api then i switch to new version and don't want change previous data in case if i need to go back to old version of API.

So, my proposal to add some kind of keyWrapperFn to options and provide a possibility to change keys centralized for all methods and not to create some kind of Proxy etc.

// .....

var noopKeyWrapper = function(key){ return key; }

var Client = function(servers, options) {
  this.servers = servers;
  this.seq = 0;
  this.options = merge(options || {},
    {failoverTime: 60, retries: 2, retry_delay: 0.2, expires: 0, logger: console});
  
  this.keyWrapper = this.options.keyWrapper || noopKeyWrapper; 
  this.serializer = this.options.serializer || noopSerializer;
};

// .....

Client.prototype.get = function(key, callback) {
  // .....

  var request = makeRequestBuffer(0, this.keyWrapper(key), '', '', this.seq);
  
  // .....
}

Client.prototype.set = function(key, value, options, callback) {
  // .....
  var request = makeRequestBuffer(opcode, this.keyWrapper(key), serialized.extras, serialized.value, this.seq);
  // .....
}

@alevy @saschat What do you think about it? Should I create PR for it or just deal with it in my code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions