def handler(ctrl, message): _name = message.get('db', 'default') _ns = API.ns_of( message['table'], message['pid']) src = API.db(_name) rs = src.select_from(message['table'], message['pid']) if not rs: return -1 if not rs.get('queue',None) or \ not rs.get('timeout', None) or \ not rs.get('cron_handler', None) or \ not rs.get('retry', None): src.delete_from( message['table'], message['pid'] ) return -2 _retry = src.redis().hincrby( _ns , 'retry', -1) if _retry<1 : src.delete_from( message['table'], message['pid'] ) return -1 API.expire(message, rs['timeout']) API.queue_push( rs['queue'], { 'pid': message['pid'], 'table': message['table'], 'handler': rs['cron_handler'], })
def __init__(self, dbname, name, timeout): self._timeout = timeout self._dbname = dbname self._keyname = name self._redis = API.redis(self._dbname) self._ns = { 'data': API.ns_of(self._keyname), }
def testNs(self): rs = API.ns_of('a') tools.eq_('test:a', rs) rs = API.ns_of('a', 'b') tools.eq_('test:a:b', rs)
def _hgetall(self): return self.db.redis().hgetall(API.ns_of('myhash'))
def cache_zset(ctrl, message): _name = message.get('db', 'default') API.redis(_name).zrem( API.ns_of( message['zset'] ), message['value'] )
def cache_hash(ctrl, message): _name = message.get('db', 'default') API.redis(_name).hdel( API.ns_of( message['hash'] ), message['field'] )
def testNs(self): rs = API.ns_of('a') tools.eq_('test:a', rs) rs = API.ns_of('a','b') tools.eq_('test:a:b', rs)