-
Notifications
You must be signed in to change notification settings - Fork 79
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
Key name used by Lock doesn't comply with the make_key
pattern used by Django's cache backend
#10
Comments
make_key
pattern used by the cache backendmake_key
pattern used by Django's cache backend
Hard to say at first look, but few observations:
|
I agree with the first 2 points. Specifically, the 2nd seems like a great idea :-) |
Well then, what API do you need? To check if lock is held? How about an Also, what do you think about making a PR? 😁 Just |
I really appreciate all the time you have invested in answering my reports :-) |
is_locked() could return the token. Maybe show some example code of how you Thanks, On Wed, Dec 24, 2014 at 3:12 PM, Jardel Weyrich notifications@github.com
|
This would be a simpler version of my usage:
|
What do you think of the following?
Then I'd change my sample to something like:
|
Few observations:
Ideally |
Agreed. It's way simpler.
If the library is going to assume people will use the lock value to store the holder/owner identifier (that token), I'm okay with it, otherwise these names won't make much sense.
Since the key/value should be handled as a lock, not a common key/value, the default argument doesn't make much sense indeed. I just got rid of it. Didn't put much thought.
Definitely! |
Now that I think about it more, |
If we're going to make that assumption on how people will use it, I believe |
Yes, |
Not sure I got your comment right. You meant rename |
Looks good, make it a pull request. I've added some notes about the |
Done in jweyrich@49a5e0e - amended my previous commit and force-pushed it over the previous one. |
Now it only needs some tests with the custom id :) |
So, here's a user that's using tox for the 1st time - thanks for the introduction :-) I can't seem to get it to skip those hundreds of tests from Django==1.7.1. It fails at ~1/2 of them and seem to abort before running the redis_lock tests. Any hints? The tox documentation didn't help much (to skip them), yet.
|
Tha's strange, it shouldn't collect the django tests. How did you run it? |
|
Not sure what to say, you should commit your tests so I can take a look. |
Can you make another PR with a bit of explanation about the new api in the |
Done in #12. If you feel like the text or the sample needs to be changed, please, feel free ;-) Thank you again! |
Sorry for bothering you so much :-)
I noticed the key name used by the Lock implementation is built by hand using a simple string concatenation, specifically
'lock:'+name
. This of course creates a key with this exact name, which at first seems to be the Correct Thing To Do, however, the Django cache backend employs a more convoluted logic - see Cache key transformation, which generates a key name like:1:lock:name
, where1
is a version that can be specified when creating the key, and defaults to 1 if none is informed. The backend relies on amake_key
function that by default joins a few parts (key_prefix, version, key).This brings a few complications when creating a lock and further querying its value. When we create it, its name is just
lock:foobar
, but when we query it usingcache.get('foobar')
orcache.get('lock:foobar')
, it will actually query ':<version>:<name>' instead.A few suggestions that could work (I think):
name
property on theLock
(yet, we also have signal name). Doesn't seem like a good idea though;key_func
property on theLock
class and invoke the function when generating the key name(s);make_key
implementation (reset_all
would also need it) used by the configured backend. This would act according to the configuredBACKEND
in settings, which seems like a good idea. This seems to require changes in theRedisCache.lock
(fromdjango_cache.py
) method as well, otherwise we'd have to extend theRedisCache
to pass the backend to the lock instance being created.Do you have a simpler idea?
The text was updated successfully, but these errors were encountered: