Example #1
0
    def test_pubsub(self):

        check_pubsub = self.redis.pubsub()
        check_pubsub.psubscribe("gottwall:*")
        next(check_pubsub.listen())

        cli = RedisClient(
            private_key=private_key,
            public_key=public_key,
            project=project,
            host=HOST)
        ts = datetime.utcnow()

        self.assertEquals("gottwall:{0}:{1}:{2}".format(project, public_key, private_key), cli.channel)
        cli.incr(name="orders", value=2, timestamp=ts, filters={"current_status": "Completed"})

        message = next(check_pubsub.listen())

        self.assertEquals(message['channel'], 'gottwall:{0}:{1}:{2}'.format(project, public_key, private_key))

        notification_message = json.loads(message['data'])
        self.assertEquals(notification_message['type'], 'notification')

        data_dict = json.loads(self.redis.spop(cli.data_key))
        self.assertTrue(data_dict['name'], 'orders')
        self.assertTrue(data_dict['timestamp'], ts.strftime("%Y-%m-%dT%H:%M:%S"))
        self.assertTrue(data_dict['filters']['current_status'], 'Completed')

        self.assertEquals(self.redis.scard(cli.data_key), 0)
Example #2
0
    t1 = time.time()
    print(('Started "{0}" at {1}'.format(title, time.ctime(t1))))
    yield
    t2 = time.time()
    print(('Finished "{0}" at {1} for the time {2}'.\
          format(title, time.ctime(t2), pretty_time(t2-t1))))


with measure_time("Test stats"):
    for x in range(100000):
        stats_client.incr(
            choice(["APIv1", "APIv2", "APIv3"]),
            timestamp=datetime.datetime(choice([2012, 2013]), randint(1, 12),
                                        randint(1, 27)) +
            datetime.timedelta(days=randint(1, 4)),
            value=randint(1, 10),
            filters={
                choice(["status"]):
                choice(["200", "403", "500", "404", "401", "201"]),
                "users":
                choice(["anonymouse", "registered"])
            })
        print(x)

with measure_time("Test stats"):
    for x in range(1000000):
        stats_client.incr("Actions",
                          timestamp=datetime.datetime(choice(
                              [2012, 2013]), randint(1, 12), randint(1, 27)) +
                          datetime.timedelta(days=randint(1, 4)),
                          value=randint(1, 5),
                          filters={
Example #3
0
@contextmanager
def measure_time(title, logger=None, **debug_params):
    t1 = time.time()
    print('Started "{0}" at {1}'.format(title, time.ctime(t1)))
    yield
    t2 = time.time()
    print('Finished "{0}" at {1} for the time {2}'.format(title, time.ctime(t2), pretty_time(t2 - t1)))


with measure_time("Test stats"):
    for x in xrange(100000):
        stats_client.incr(
            choice([u"APIv1", "APIv2", "APIv3"]),
            timestamp=datetime.datetime(choice([2012, 2013]), randint(1, 12), randint(1, 27))
            + datetime.timedelta(days=randint(1, 4)),
            value=randint(1, 10),
            filters={
                choice(["status"]): choice(["200", "403", "500", "404", "401", "201"]),
                "users": choice(["anonymouse", "registered"]),
            },
        )
        print(x)


with measure_time("Test stats"):
    for x in xrange(1000000):
        stats_client.incr(
            u"Actions",
            timestamp=datetime.datetime(choice([2012, 2013]), randint(1, 12), randint(1, 27))
            + datetime.timedelta(days=randint(1, 4)),
            value=randint(1, 5),
            filters={"views": choice(["products", "special page"]), "voting": choice(["up", "down"])},
Example #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
stati_redis.example
~~~~~~~~~~~~~

Stati example to use Redis pub/sub transport

:copyright: (c) 2012 by GottWall team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
:github: http://github.com/GottWall/stati-redis-python
"""

from stati_redis import RedisClient

private_key = "gottwall_privatekey"
public_key = "project_public_key"
project = "test_gottwall_project"

host = "10.8.9.8"

cli = RedisClient(
    private_key=private_key,
    public_key=public_key,
    project=project, db=2,
    host=host)

cli.incr(metric="orders", value=2, filters={"current_status": "Completed"})