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

Support "by masterkey" #53

Open
holm opened this issue Sep 7, 2011 · 4 comments
Open

Support "by masterkey" #53

holm opened this issue Sep 7, 2011 · 4 comments

Comments

@holm
Copy link

holm commented Sep 7, 2011

It would be great if pylibmc could support the libmemcached functionality of hashing by master key instead of the actual key value. This allows to group related keys on the same memcached server, and avoid hitting many servers when getting or setting multiple values (get_multi, set_multi).

@lericson
Copy link
Owner

lericson commented Sep 7, 2011

This is a very interesting feature! Perhaps we could make a more intuitive API than to extend get/set and friends, as this breaks new ground.

with mc.master_key("somekey"):
  mc.set_multi(dict.fromkeys("abcdef", "hi"))
  mc.get_multi("cbd")

Is what I come up with spontaneously, but I don't think it'll be very nice - imagine what happens if the with block code calls into eventlet.switch, making other Python code call master_key while one is already set? Should that give an error or what?

Much rather then that the master_key function return some kind of a proxy object, but then that proxy object will inevitably behave a lot like mc and people will probably confuse the two, it's simple to forget as submc and just assume it mutates mc.

@holm
Copy link
Author

holm commented Sep 7, 2011

I think the proxy object would work well for our use-case. We are big user of multi-gets, and estimate we could save a lot of network traffic (and gain considerable performance), by hashing on a higher level.

Something like the following could be an option:

with mc.master_key("somekey") as mastered_mc:
  mastered_mc.get_multi(....)

@holm
Copy link
Author

holm commented Sep 7, 2011

... and thanks for a great library, we use it with big satisfaction.

@lericson
Copy link
Owner

lericson commented Sep 7, 2011

Hm, definitely needs a better name. There needs to be a logical name for the identifier, also what happens in this scenario:

with mc.master_key("a") as mmc:
  with mmc.master_key("b") as mmmc:
    # use mmmc

Edit: the logical thing would be for it to be equivalent to...

with mc.master_key("ab") as mmc:
  # use mmc

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

No branches or pull requests

2 participants