def _log_to_recent_project_actions(p, user_id, action_time, message): """Log actions that refer to projects to a queue of most recent actions. We use redis' list for that. We skip actions that refer to private projects. """ from transifex.projects.models import Project if p.private: return private_slugs = Project.objects.filter( private=True ).values_list('slug', flat=True) for slug in private_slugs: if ('/projects/p/%s/' % slug) in message: return key = 'event_feed' data = { 'name': force_unicode(p)[:200], 'user_id': user_id, 'action_time': action_time, 'message': message } try: r = TxRedisMapper() r.lpush(key, data=data) r.ltrim(key, 0, 11) except ConnectionError, e: logger.critical("Cannot connect to redis: %s" % e, exc_info=True) raise
class TestRedis(TestCase): def setUp(self): logger.critical("This will delete everything in db=1 i n redis.") self.r = TxRedisMapper(db=1) def tearDown(self): self.r.flushdb() def test_json_suffix(self): key = 'key' data = {'lang': 'en', 'code': 'en'} res = self.r.lpush(key, data=data) self.assertEquals(res, 1) res = self.r.lpop(key) self.assertEquals(res, data)
def setUp(self): logger.critical("This will delete everything in db=1 i n redis.") self.r = TxRedisMapper(db=1)