def test_key_hashing(self): # hashing disabled rs = Rediset(hash_generated_keys=False) key = rs.create_key('foo') self.assertEqual(key, 'foo') key = rs.create_key('foo', generated=True) self.assertEqual(key, 'rediset:foo') # hashing enabled rs = Rediset(hash_generated_keys=True) key = rs.create_key('foo') self.assertEqual(key, 'foo') key = rs.create_key('foo', generated=True) self.assertEqual(key, 'rediset:acbd18db4cc2f85cedef654fccc4a4d8')
def test_default_caching_and_override(self): self.rediset = Rediset(key_prefix=self.PREFIX, default_cache_seconds=10) s1 = self.rediset.Set('key1') s2 = self.rediset.Set('key2') intersection = self.rediset.Intersection(s1, s2) self.assertEqual(intersection.cache_seconds, 10) intersection = self.rediset.Intersection(s1, s2, cache_seconds=5) self.assertEqual(intersection.cache_seconds, 5)
def __init__(self): try: self._delay_logger = open( os.path.join(ROOT_LOG, DELAY_LOG + '.log'), 'a') self._error_logger = open( os.path.join(ROOT_LOG, ERROR_LOG + '.log'), 'a') except IOError: raise LogFileException, 'Failed to open log file' self._redis_client = redis.Redis(host=REDIS_HOST, port=int(REDIS_PORT)) self.downloaded_url = Rediset( hash_generated_keys=True, redis_client=self._redis_client).Set('downloaded_url_set') self.todownload_url_queue = Queue('todownload_url_queue', host=REDIS_HOST, port=REDIS_PORT) self.todownload_url_set = Rediset( hash_generated_keys=True, redis_client=self._redis_client).Set('todownload_url_set') self._rlock = gevent.coros.RLock()
def test_key_generation(self): rs = Rediset(key_prefix='some-prefix') key = rs.create_key('foo') self.assertEqual(key, 'some-prefix:foo')
def setUp(self): self.rediset = Rediset(key_prefix=self.PREFIX) self.rediset.redis = Mock(wraps=self.rediset.redis)