def append(self, hcont, value, score = None): assert hcont.target_type is self.target_type assert type(value) is self.target_type or (hasattr(value, 'model') and value.model is self.target_type) if self.target_has_id: value = value.oid assert value is not None if not self.index_key: self.raw_append(ds, hcont, value, score) elif self.unique_index: #TODO watch (optimistic lock) to allow multithread? if ds.hexists(self.index_key, value): raise UniqueError(self.index_key, value) else: pl = ds.pipeline(True) self.raw_append(pl, hcont, value, score) pl.hset(self.index_key, value, hcont.owner_id) pl.execute() else: pl = ds.pipeline(True) self.raw_append(pl, hcont, value, score) ikey = self.index_key + ':' + str(value) pl.sadd(ikey, hcont.owner_id) pl.execute()
def __check_unique(self, fld, val): # TODO watch (optimistic lock) to allow multithread? k = "u:{0}:{1}".format(self.modname, fld) if ds.hexists(k, val): raise UniqueError(k, val)