def _store(self, cmd, key, val, expire=0, cas=0, expected=(MEMCACHED_SUCCESS, )): if not self.check_key(key): return False if cmd in ('append', 'prepend') and type(val) != type(''): return False val, flag = prepare(val, self.comp_threshold) if cmd == 'add': ret = c.memcached_add(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'replace': ret = c.memcached_replace(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'cas': ret = c.memcached_cas(self.mc, key, len(key), val, len(val), expire, flag, cas) elif cmd == 'append': ret = c.memcached_append(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'prepend': ret = c.memcached_prepend(self.mc, key, len(key), val, len(val), expire, flag) else: raise Exception, "invalid cmd %s" % cmd return int(ret in expected)
def _store_multi(self, cmd, keys, val): if type(val) != type(''): sys.stderr.write("[cmemcached]%s only support string: %s" % (cmd, key)) return 0 self.set_behavior(BEHAVIOR_NOREPLY, 1) self.set_behavior(BEHAVIOR_BUFFER_REQUESTS, 1) for key in keys: if cmd == 'append': c.memcached_append(self.mc, key, len(key), val, len(val), 0, 0) elif cmd == 'prepend': c.memcached_prepend(self.mc, key, len(key), val, len(val), 0, 0) retval = c.memcached_flush_buffers(self.mc) self.set_behavior(BEHAVIOR_NOREPLY, 0) self.set_behavior(BEHAVIOR_BUFFER_REQUESTS, 0) return retval == MEMCACHED_SUCCESS
def _store(self, cmd, key, val, expire=0, cas=0, expected=(MEMCACHED_SUCCESS,)): if not self.check_key(key): return False if cmd in ('append', 'prepend') and type(val) != type(''): return False val, flag = prepare(val, self.comp_threshold) if cmd == 'add': ret = c.memcached_add(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'replace': ret = c.memcached_replace(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'cas': ret = c.memcached_cas(self.mc, key, len(key), val, len(val), expire, flag, cas) elif cmd == 'append': ret = c.memcached_append(self.mc, key, len(key), val, len(val), expire, flag) elif cmd == 'prepend': ret = c.memcached_prepend(self.mc, key, len(key), val, len(val), expire, flag) else: raise Exception, "invalid cmd %s" % cmd return int(ret in expected)