Пример #1
 def run_benchmark(self):
     group_names = [group['name'] for group in self.ARGUMENTS]
     group_values = [group['values'] for group in self.ARGUMENTS]
     for value_set in itertools.product(*group_values):
         pairs = list(izip(group_names, value_set))
         arg_string = ', '.join(['%s=%s' % (p[0], p[1]) for p in pairs])
         sys.stdout.write('Benchmark: %s... ' % arg_string)
         kwargs = dict(pairs)
         setup = functools.partial(self.setup, **kwargs)
         run = functools.partial(self.run, **kwargs)
         t = timeit.timeit(stmt=run, setup=setup, number=1000)
         sys.stdout.write('%f\n' % t)
Пример #2
    def sort(self, name, start=None, num=None, by=None, get=None, desc=False, alpha=False, store=None, groups=None):
        """Sort and return the list, set or sorted set at ``name``.

        :start: and :num:
            allow for paging through the sorted data

            allows using an external key to weight and sort the items.
            Use an "*" to indicate where in the key the item value is located

            allows for returning items from external keys rather than the
            sorted data itself.  Use an "*" to indicate where int he key
            the item value is located

            allows for reversing the sort

            allows for sorting lexicographically rather than numerically

            allows for storing the result of the sort into the key `store`

            A full implementation of the server side sort mechanics because many of the
            options work on multiple keys that can exist on multiple servers.
        if (start is None and num is not None) or \
           (start is not None and num is None):
            raise RedisError("RedisError: ``start`` and ``num`` must both be specified")
            data_type = b(self.type(name))

            if data_type == b("none"):
                return []
            elif data_type == b("set"):
                data = list(self.smembers(name))[:]
            elif data_type == b("list"):
                data = self.lrange(name, 0, -1)
                raise RedisClusterException("Unable to sort data type : {0}".format(data_type))
            if by is not None:
                # _sort_using_by_arg mutates data so we don't
                # need need a return value.
                self._sort_using_by_arg(data, by, alpha)
            elif not alpha:
            if desc:
                data = data[::-1]
            if not (start is None and num is None):
                data = data[start:start + num]

            if get:
                data = self._retrive_data_from_sort(data, get)

            if store is not None:
                if data_type == b("set"):
                    self.rpush(store, *data)
                elif data_type == b("list"):
                    self.rpush(store, *data)
                    raise RedisClusterException("Unable to store sorted data for data type : {0}".format(data_type))

                return len(data)

            if groups:
                if not get or isinstance(get, basestring) or len(get) < 2:
                    raise DataError('when using "groups" the "get" argument '
                                    'must be specified and contain at least '
                                    'two keys')
                n = len(get)
                return list(izip(*[data[i::n] for i in range(n)]))
                return data
        except KeyError:
            return []