コード例 #1
0
ファイル: stats.py プロジェクト: cchng/mutalyzer
def get_totals():
    """
    Get the total for all known counters.

    Known counters are just those that have been incremented at least once.
    """
    counters = client.keys('counter:*:total')

    pipe = client.pipeline(transaction=False)
    for counter in counters:
        pipe.get(counter)

    return {counter.split(':')[1]: int(value)
            for counter, value in zip(counters, pipe.execute())}
コード例 #2
0
def get_totals():
    """
    Get the total for all known counters.

    Known counters are just those that have been incremented at least once.
    """
    counters = client.keys('counter:*:total')

    pipe = client.pipeline(transaction=False)
    for counter in counters:
        pipe.get(counter)

    return {
        counter.split(':')[1]: int(value)
        for counter, value in zip(counters, pipe.execute())
    }
コード例 #3
0
ファイル: stats.py プロジェクト: cchng/mutalyzer
def increment_counter(counter):
    """
    Increment the specified counter.
    """
    pipe = client.pipeline(transaction=False)
    pipe.incr('counter:%s:total' % counter)

    for label, bucket, expire in INTERVALS:
        key = 'counter:%s:%s:%s' % (counter, label,
                                    unicode(time.strftime(bucket)))
        pipe.incr(key)

        # It's safe to just keep on expiring the counter, even if it already
        # had an expiration, since it is bounded by the current day. We don't
        # really mind at what time of the day the expiration will be exactly.
        pipe.expire(key, expire)

    pipe.execute()
コード例 #4
0
def increment_counter(counter):
    """
    Increment the specified counter.
    """
    pipe = client.pipeline(transaction=False)
    pipe.incr('counter:%s:total' % counter)

    for label, bucket, expire in INTERVALS:
        key = 'counter:%s:%s:%s' % (counter, label,
                                    unicode(time.strftime(bucket)))
        pipe.incr(key)

        # It's safe to just keep on expiring the counter, even if it already
        # had an expiration, since it is bounded by the current day. We don't
        # really mind at what time of the day the expiration will be exactly.
        pipe.expire(key, expire)

    pipe.execute()