def difference(self, other): """Performs a diff on two sets.""" newset = DataType.get(self.type)(self.client) if self.client._is_redis_item(other): self.client.sdiffstore(newset.key, self.key, other.key) else: self._execute_script('difference_struct', newset.key, self.key, self._create_unique_key(), [self.client.encode(item) for item in other]) return newset
def intersection(self, other): """Performs an intersection on two sets.""" newset = DataType.get(self.type)(self.client) if self.client._is_redis_item(other): self.client.sinterstore(newset.key, self.key, other.key) else: self._execute_script('intersection_struct', newset.key, self.key, self._create_unique_key(), [self.client.encode(item) for item in other]) return newset
def symmetric_difference(self, other): """Returns a set of elements on one set or the other.""" # Remember to check whether 'other' is a Redis set or normal Python set. newset = DataType.get(self.type)(self.client) if self.client._is_redis_item(other): self._execute_script('symmetric_difference_redis', newset.key, self.key, other.key) else: self._execute_script('symmetric_difference_struct', newset.key, self.key, self._create_unique_key(), [self.client.encode(item) for item in other]) return newset
def copy(self): """Copies the set.""" newset = DataType.get(self.type)(self.client) self.client.sunionstore(newset.key, self.key) return newset