Skip to content

Instantly share code, notes, and snippets.

@slezica
Created August 16, 2013 22:37
Show Gist options
  • Save slezica/6254089 to your computer and use it in GitHub Desktop.
Save slezica/6254089 to your computer and use it in GitHub Desktop.
Traducción ruby - python
# Dummy
class Redis:
def send(self, method, key, args, f):
print method, key, args, f
class Nest(str):
def __init__(self, key, redis = Redis()):
super(Nest, self).__init__(key)
self.redis = redis
def __getitem__(self, key):
return self.__class__("%s:%s" % (self, key))
METHODS = [
'append', 'bitcount', 'blpop', 'brpop', 'brpoplpush', 'decr',
'decrby', 'del', 'dump', 'exists', 'expire', 'expireat', 'get', 'getbit',
'getrange', 'getset', 'hdel', 'hexists', 'hget', 'hgetall', 'hincrby',
'hincrbyfloat', 'hkeys', 'hlen', 'hmget', 'hmset', 'hset', 'hsetnx', 'hvals',
'incr', 'incrby', 'incrbyfloat', 'lindex', 'linsert', 'llen', 'lpop',
'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'move', 'persist',
'pexpire', 'pexpireat', 'psetex', 'pttl', 'publish', 'rename', 'renamenx',
'restore', 'rpop', 'rpoplpush', 'rpush', 'rpushx', 'sadd', 'scard',
'sdiff', 'sdiffstore', 'set', 'setbit', 'setex', 'setnx', 'setrange',
'sinter', 'sinterstore', 'sismember', 'smembers', 'smove', 'sort', 'spop',
'srandmember', 'srem', 'strlen', 'subscribe', 'sunion', 'sunionstore',
'ttl', 'type', 'unsubscribe', 'watch', 'zadd', 'zcard', 'zcount',
'zincrby', 'zinterstore', 'zrange', 'zrangebyscore', 'zrank', 'zrem',
'zremrangebyrank', 'zremrangebyscore', 'zrevrange', 'zrevrangebyscore',
'zrevrank', 'zscore', 'zunionstore'
]
def implement_method(method):
def impl(self, args = [], f = lambda: True):
self.redis.send(method, self, args, f)
return impl
for method in METHODS:
setattr(Nest, method, implement_method(method))
# Example:
Nest('hello').zcount('foo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment