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)
#!/usr/bin/env python # -*- coding: utf-8 -*- import json import datetime import redis from random import randint, choice from stati_redis import RedisClient, Client stats_client = RedisClient(private_key="my_private_key", public_key="my_public_key", project="SampleProject", host="10.8.9.8", db=2) import time from contextlib import contextmanager def pretty_time(td): """Convert timedelta to pretty :param td: timedelta (t2 - t1) :return: delta string in seconds or minutes """ if td < 300: return "{0} sec".format(td) else: return "{0} min".format((td / 60.0)) @contextmanager
#!/usr/bin/env python # -*- coding: utf-8 -*- import json import datetime import redis from random import randint, choice from stati_redis import RedisClient, Client stats_client = RedisClient( private_key="my_private_key", public_key="my_public_key", project="SampleProject", host="10.8.9.8", db=2 ) import time from contextlib import contextmanager def pretty_time(td): """Convert timedelta to pretty :param td: timedelta (t2 - t1) :return: delta string in seconds or minutes """ if td < 300: return "{0} sec".format(td) else: return "{0} min".format((td / 60.0)) @contextmanager def measure_time(title, logger=None, **debug_params): t1 = time.time()
#!/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"})