-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add namespace support #710
Conversation
e7bbc76
to
fac5cf5
Compare
Hi @kazanz, Thanks for taking the time to put this together. I have a number of comments:
|
Hey @andymccurdy, Thank you for the feedback, all valid points. I have a few business related projects I have to work on now, but I will chip away at this when I can and update you on the progress. |
0b0bc22
to
adec138
Compare
Hello @andymccurdy Went through and overhauled the PR based on your suggestions. All functions on StrictRedis, Redis, Pubsub, Script, and Pipeline have namespacing support. Tested manually majority of the functions and wrote string based tests for all the namespacing functionality as suggested in concern 5. Took care of concerns 1, 2, 4, 6 by initializing the redis/strictredis/pubsub/pipeline classes with a namespace argument and wrapping all the functions that call out to redis with a custom I have yet to come up with a elegant solution to 7, when we blpop there is no guarentee what we are popping is keys or values, as it is appliaction dependent. Perhaps it should default to removing the namespace and a kwarg can be added to those functions to disable namespace removal. Either way have a comment in the readme warning users. Thoughts? In answer to 8. Methods like 9: Removed the prints :) 10: Here is simple benchmarking:
A little confused on comment 3? the Let me know what you think and any potential improvements you think can be made. Thanks |
Thanks @Kazanz I'll find some time today or tomorrow to review. |
@Kazanz Thanks for the updated patch. I think we're getting closer. A couple questions:
I'm going to take a stab at cleaning a few things up and hopefully get back to you tonight or tomorrow. Thanks! |
@andymccurdy Thanks for getting back, To answer your questions #1 I could be missing something as well, so please correct me if I am wrong. Take ZRANGEBYLEX command for example:
When I do a #2 And I may be misunderstanding the question, so correct me if I am wrong or not addressing the appropriate issue. When the pipeline object calls In [1]: from redis import Redis
In [2]: params = {"host": "localhost", "port": 6379, "db": 9}
In [3]: r = Redis(namespace="namespace:", **params)
In [4]: pipeline = r.pipeline()
In [5]: r2 = Redis(**params)
In [6]: pipeline.set("foo", "bar").sadd("faz", "baz").incr("auto_number").execute()
In [7]: r2.get('foo') # no namespace
In [8]: r.get('foo') # namespace
Out[8]: 'bar'
In [9]: p = pipeline.set('jar', 'jelly')
In [10]: p.execute()
In [11]: r2.get('jar') # no namespace
In [12]: r.get('jar') # namespace
Out[12]: 'jelly' |
|
Made changes as per the last suggetion. Lex was removed as it is was not needed. Now, when a response is returned in the Working code example: In [1]: from redis import Redis
In [2]: p1 = Redis(**{
"namespace": "namespace:", "host": "localhost", "port": 6379, "db": 9
}).pipeline()
In [3]: p1.set('a', '1').set('b', '2').keys().execute()
Out[3]: [True, True, ['b', 'a']]
In [4]: p2 = Redis(**{"host": "localhost", "port": 6379, "db": 9}).pipeline()
In [5]: p2.set('c', '3').set('d', '4').keys().execute()
Out[5]: [True, True, ['d', 'c', 'namespace:b', 'namespace:a']] Let me know if there is other improvements we need. |
@andymccurdy Just following up with you to see if there is you got a chance to view latest commit, and if more modifications are needed. Thanks. |
Is this something that will be implemented soon? We are very interested in using it. |
@andymccurdy we're using this in production. works great. |
Allows namespacing based on proposed syntax in this issue.
r = redis.Redis(namespace='foobar')
Changes:
redis.Redis
usesredis.namespace.NamespaceWrapper
class to format requests to and responses from redis.redis.Redis
class.