Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
prefixed proxies #1
This works great for my purposes, hopefully you find it useful as well. I use redis to record object attributes using a standard prefix; that is, my object
For reasons of object orientation, I want to be able to do:
p = Proxy() class Person(object): def __init__(self, id, name): ... self.pp = p.prefixed('person:%d:' % id) p['name'] = name # stored as 'person::name'
The pull request contains code that lets me do exactly that.
FWIW, I plan to use this in a sneakier way, inspired by sqlalchemy: I define class properties that automagically use the underlying redis backing store. That allows me to do something like this:
class Person(object, RedisMixin): name = RedisProperty('name') def __init__(self, id, name): self.id = id self.prefix = 'person:%d:' % self.id self.name = name # name is automatically backed by redis
Code to do that isn't in this pull request because I haven't finished it yet.
redish is really useful, btw! I'm also a happy user of celery.
Hey, excellent stuff. It looks like you're thinking along the same lines I was.
So before pulling this, I ask that you take a look at the experiments I did in my own fork (especially as regards keyspaces). I kept it over in my own space for a while to see how it worked in my own projects, and it's been working well.
Also, I wrote up the keyspaces (which in my case are formatstrings instead of prefixes) in the docs directory:
I expose a few variations, accounting for different ways people might use it. I'm still in the process of discovering some patterns myself, which is why I hadn't pulled it into ask's repository just yet.
atl, I think your format string thing is right on. I've actually now changed my "prefixed" to "namespaced," which emulates the behavior of keyspaces. I prefer the "class abstraction" to the "named keyspace" abstraction, but your solution does that too, and is definitely a superset of mine.
I've added two commits to my fork:
The first implements namespaced instead of prefixed.
The second is all contained in "redish/mixin.py" It lets you declare object properties that are automatically backed by redis namespaced objects. Its just a couple lines of code, but I think its a really powerful abstraction. Its totally trivial to reimplement this using keyspaces instead.
My prefixed/namespaced code represents just a couple of minutes of poking around in a codebase I'd never touched before. I'm sure keyspace is more robust. But please do pull one of them into ask's tree! I'll implement mixin.py using whichever flavor you prefer.
I'm really psyched to have found this project, and I'd love to hack on it some more.
This comment has been minimized.
This comment has been minimized.
egradman, I'm really excited that someone else is 1) looking at proxy.py and 2) was thinking along the same lines for layering namespaces on top of it.
I've just merged the branch that I wrote, am familiar with, and have tested. I'm very eager to see what you can build on top of that. I'm not sure what ask's policy is on adding contributors, but he was generous in adding me, I hope he could do the same for you.