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 for get_by_key and set_by_key operations #176

Open
dterei opened this issue Jan 23, 2015 · 2 comments
Open

Support for get_by_key and set_by_key operations #176

dterei opened this issue Jan 23, 2015 · 2 comments

Comments

@dterei
Copy link

dterei commented Jan 23, 2015

Libmemcached support memcached_get_by_key and memcached_set_by_key. These can be useful for implementing some specific caching and usage strategies with memcached.

It would be awesome if pylibmc supported these.

@lericson
Copy link
Owner

lericson commented Feb 2, 2015

There is an earlier discussion about this and how the API would look. Do you have any suggestions? How do we keep the API from becoming too crowded?

@dterei
Copy link
Author

dterei commented Feb 2, 2015

It seems to me there are three approaches. I don't properly know python, so not sure if all three are achievable in the language:

1. More functions

Simply add-in new functions. This is perhaps the least attractive, since you'd basically nearly double the size of the API. i.e.,

set_by_key(hash_key, key, value, options)
get_by_key(hash_key, key, value)
touch_by_key(hash_key, key, value)
...

2. New option argument

Extend all functions to take an optional argument, hash_key that indicates what value should be used to choose the server to speak to.

set(key, value, hash_key=k)

3. Subclass or lambda

Say an API like:

mc_k = mc.with_hash_key(hkey)
mc_k.set(key, value) // set using hkey as the hashing key

mc.set(key, value) // set using default hashing, (i.e., key as the hash key)

This is nice since it composes well, doesn't complicate the API much.

A similar idea would take a lambda instead:

mc.with_hash_key(hkey, lambda mck:
        mck.set(key, value)
)

I think the subclass idea seems the nicest to me. Haven't thought it through completely if there are any issues with it.

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

2 participants