Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Key wrapper #132

Open
vanatd opened this issue Sep 10, 2020 · 0 comments
Open

Feature: Key wrapper #132

vanatd opened this issue Sep 10, 2020 · 0 comments

Comments

@vanatd
Copy link
Contributor

vanatd commented Sep 10, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant