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

Implement transparent key prefixing #95

Closed
dguo opened this issue Jul 9, 2015 · 7 comments
Closed

Implement transparent key prefixing #95

dguo opened this issue Jul 9, 2015 · 7 comments

Comments

@dguo
Copy link
Contributor

dguo commented Jul 9, 2015

Hi, I noticed that you have this feature on the roadmap, and I'd like to help implement it. Do you have any ideas about how it will work?

@luin
Copy link
Collaborator

luin commented Jul 10, 2015

That will be great. We can give user an option to specify a key prefix:

var redis = new Redis({ keyPrefix: 'app1:' });

and then the keys of every command sent by this instance should get a prefix of 'app1:'. For instance:

  1. redis.set('foo', 'bar') will actually send SET app1:foo bar;
  2. redis.blpop('key1', 'key2', 'key3', 0) will actually send BLPOP app1:key1 app1:key2 app1:key3 0;

@luin
Copy link
Collaborator

luin commented Jul 10, 2015

We already have a method Command#getKeys for getting keys in a command(https://github.com/luin/ioredis/blob/master/lib/command.js#L85).

@dguo
Copy link
Contributor Author

dguo commented Jul 10, 2015

Sounds good. What's your opinion on giving the user flexibility for commands that have multiple keys? So something like:

var redis = new Redis({keyPrefix: ['app1:', 'app2:', 'app3:']});
redis.blpop('key1', 'key2', 'key3', 0);  // BLPOP app1:key1 app2:key2 app3:key3 0

Or maybe even allow the user to dynamically set the prefix?

var redis = new Redis({keyPrefix: 'foo:'});
redis.blpop({keyPrefix: ['app1:', 'app2:', 'app3:']}, 'key1', 'key2', 'key3', 0);

I'm not sure how useful this would be.

@luin
Copy link
Collaborator

luin commented Jul 11, 2015

I prefer to keeping this option simple. My intention to add keyPrefix option is to allow multiple apps using one Redis server.keyPrefix is used as a namespace, so a single string is enough.

@dguo
Copy link
Contributor Author

dguo commented Jul 12, 2015

Ok, that's reasonable. I'll start working on it.

@luin luin closed this as completed in 374c188 Jul 23, 2015
luin added a commit that referenced this issue Jul 23, 2015
Add support for transparent key prefixing. Close #95
@Delagen
Copy link

Delagen commented May 10, 2016

scanstream match option does not use this prefix

@luin
Copy link
Collaborator

luin commented May 10, 2016

@Delagen This has already been discussed. Refer to #239 for more information.

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

3 participants