def _add_to_ev(self, data, subject=None): gkey = mkname("events") pkey = mkname("events", user_id(subject)) pipe = self.client.pipeline() pipe.lpush(gkey, data) pipe.lpush(pkey, data) pipe.execute(callback=lambda x: None)
def _counter_get(self, user, counter, callback): def parse(res): if isinstance(res, basestring): try: callback(int(res)) except ValueError: callback(float(res)) elif res is None: callback(0) else: callback(res) hash_name = mkname("counter", user_id(user)) self.client.hget(hash_name, counter, callback=parse)
def _counter_get(self, user, counter, callback): hash_name = mkname("counter", user_id(user)) res = self.client.hget(hash_name, counter) if isinstance(res, string_types): try: callback(int(res)) except ValueError: callback(float(res)) elif res is None: callback(0) else: callback(res)
def _counter_add(self, user, counter, amount, callback): hash_name = mkname("counter", user_id(user)) res = self.client.hincrby(hash_name, counter, amount) callback(res)
def add_badge(self, user, badge, callback): key = mkname("badges", user_id(user)) success = self.client.sadd(key, badge.badge_id) == 1 callback(success)
def add_badge(self, user, badge, callback): def parse(n): callback(n == 1) key = mkname("badges", user_id(user)) self.client.sadd(key, badge.badge_id, callback=parse)