def test_list_or_args(self): bfoo = b('foo') ufoo = u('foo') # first record is a text instance self.assertEquals(list_or_args(ufoo, []), [ufoo]) self.assertEquals(list_or_args(ufoo, [ufoo]), [ufoo, ufoo]) # first record is a list self.assertEquals(list_or_args([ufoo], [ufoo]), [ufoo, ufoo]) # first record is a binary instance self.assertEquals(list_or_args(bfoo, []), [bfoo]) self.assertEquals(list_or_args(bfoo, [bfoo]), [bfoo, bfoo])
def mget(self, keys, *args): args = list_or_args(keys, args) commands = [] for arg in args: commands.append(('MGET', arg)) results = self._execute_multi_command_with_poller('MGET', commands) return [results[k] for k in args]
def mget(self, keys, *args): """ Returns a list of values ordered identically to ``keys`` Cluster impl: Itterate all keys and send GET for each key. This will go alot slower than a normal mget call in StrictRedis. This method is no longer atomic. """ return [self.get(arg) for arg in list_or_args(keys, args)]
def _rc_mget(self, keys, *args): """ Returns a list of values ordered identically to ``*args`` """ args = list_or_args(keys, args) result = [] for key in args: result.append(self.get(key)) return result
def _rc_sunionstore(self, dst, src, *args): """ Store the union of sets ``src``, ``args`` into a new set named ``dest``. Returns the number of keys in the new set. """ args = list_or_args(src, args) result = self.sunion(*args) if result is not set([]): return self.sadd(dst, *list(result)) return 0
def sunion(self, keys, *args): """ Return the union of sets specified by ``keys`` Cluster impl: Querry all keys, union and return result """ k = list_or_args(keys, args) res = self.smembers(k[0]) for arg in k[1:]: res = res | self.smembers(arg) return res
def sdiff(self, keys, *args): """ Return the difference of sets specified by ``keys`` Cluster impl: Querry all keys and diff all sets and return result """ k = list_or_args(keys, args) res = self.smembers(k[0]) for arg in k[1:]: res = res - self.smembers(arg) return res
def _rc_sunion(self, src, *args): """ Returns the members of the set resulting from the union between the first set and all the successive sets. """ args = list_or_args(src, args) src_set = self.smembers(args.pop(0)) if src_set is not set([]): for key in args: src_set.update(self.smembers(key)) return src_set
def _sinter(keys, *args): with self._lock.writer(): keys = list_or_args(keys, args) sets = [self._assert_set(self._cache.get(self._to_str(key), None)) for key in keys] if sets: i = sets[0] for s in sets[1:]: i = i.intersection(s) return i else: return set()
def sunionstore(self, dest, keys, *args): keys = list_or_args(keys, args) return super().sunion(self.make_key(dest), self.make_keys(keys))
def execute(self, command, params=()): try: args = list_or_args(command, params) return self.cursor.execute_command(*args) except RedisError as e: raise utils.DatabaseError(*tuple(e))
def mget(self, keys, *args): args = list_or_args(keys, args) return Promise.all([self.get(arg) for arg in args])
def assert_not_in_reserved_namespace(names, *args): names = list_or_args(names, args) if any(RedizConventions.sep() in name for name in names): raise Exception("Operation attempted with a name that uses " + RedizConventions.sep())
def sunion(self, keys, *args): keys = list_or_args(keys, args) return super().sunion(self.make_keys(keys))
def hmget(self, name, keys, *args): keys = list_or_args(keys, args) return super().hmget(self.make_key(name), self.make_keys(keys))