Hacker News new | past | comments | ask | show | jobs | submit login
Python Datastructures Backed by Redis (lethain.com)
42 points by twampss on Sept 5, 2010 | hide | past | favorite | 7 comments



The redis python client already uses an API that maps 1:1 with Redis which makes it simple to read the redis docs and get going.

Store a dictionary:

    import redis
    r = redis.Redis()
    r.hmset('key', dict(foo='bar', n=42))
Store a single value in a dictionary/hash:

    r.hset('key', 'foo', 'buz')


Seeing that Redis is a datastructure storage mechanism, I guess it shouldn't shock anyone that it maps well to existing datastructure interfaces. Maybe the more interesting aspect here is the power of having datastructure-aware datastores as opposed to trying to hide the implementation details behind (potentially) leaky abstractions.


I can sort of see the benefit of using it as a serialization format. Use it to replace the db for some things or instead of a configuration file. It might be nicer to send it to a data store then have to write into a file...

However, doesn't this turn it into the mother-of-all global variables? (Actually, if it's outside of the globe, and outside of the system, can we call them galactic variables?) With in-memory lists, the scoping is relatively well defined. It seems like the temptation to take this too far would be great.


@lethain - you beauty. Nice work. The thing is - it is not surprising that redis maps well with the python DS. It is that after reading this it occurred to me how powerful having Persistent DS(Not in the Functional DS sense but in data storage sense) can simplify web programming.


redis-objects does a pretty good job of this for Ruby: http://github.com/nateware/redis-objects


I did something very similar a while back (redis_wrap): http://amix.dk/blog/post/19508


I wonder how hard this would be to do this for something like clojure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: