def test_redis_db(self): # Test connect db 0, 1 and default redis_dbDefault = myRedisConnect(host="127.0.0.1", port=8888, password="******",db=None) redis_db0 = myRedisConnect(host="127.0.0.1", port=8888, password="******",db=0) redis_db1 = myRedisConnect(host="127.0.0.1", port=8888, password="******",db=1) # Set and get value in 0 redis_db0.redis_set("foo","bar0") self.assertEqual(redis_db0.redis_get("foo"), "bar0") # Set value in 1 with same key redis_db1.redis_set("foo","bar1") # Get value in 0 and default self.assertEqual(redis_db0.redis_get("foo"), "bar0") self.assertEqual(redis_dbDefault.redis_get("foo"), "bar0") # Get value in 1 self.assertEqual(redis_db1.redis_get("foo"), "bar1")
def redisStartConnexion(): "Open redis connexion" redis_connexion = myRedisConnect(host=redis_host, \ port=redis_port, \ db=redis_db, \ password=redis_password) if redis_connexion._error: exit(1) return redis_connexion
def redisStartConnexion(self): "start redis connexion" redis_connexion = myRedisConnect(host=self._redis_host, port=self._redis_port, password=self._redis_password, db=self._redis_db) if redis_connexion._error: self._logger.critical("Redis connexion ERROR - Check server access or the password") exit(1) return redis_connexion
def redisStartConnexion(self): # Open redis connection redis_connection = myRedisConnect(host=self._redis_server_host, \ port=self._redis_server_port, \ socket_timeout=self._redis_server_timeout, \ password=self._redis_server_password, \ db=self._redis_server_db) if redis_connection._error: self._logger.critical("Redis server connection ERROR - " + "Check server access or the password") exit(1) return redis_connection
def workerRedis(self, threadId, sema, myHosts, simulateFileOpen=None): "Thread" #time.sleep(0) # Debug add time self._logger.debug("Thread worker " + str(threadId) + " with host : " + str(myHosts)) for hostLine in myHosts: # Get password and db host = hostLine['host'] redis_pass = None redis_db = "0" if hostLine.has_key('db'): redis_db = hostLine['db'] if hostLine.has_key('password'): redis_pass = hostLine['password'] pollerRedisConnect = myRedisConnect(host=host, port=self._redis_client_port, socket_timeout=self._redis_client_timeout, password=redis_pass,db=redis_db) # If error goto next if pollerRedisConnect._error: self._logger.error("Worker " + str(threadId) + " Redis client connection ERROR for host : " + host) continue # Get Last fetch (SERVER) and fetch new data hostDatas = {} # Get last fetch and fetch end (lastFetch, fetchEnd) = self.workerGetLastFetch(pollerRedisConnect, threadId,host) # Fetch data and info if the host have new datas if fetchEnd == None: self._logger.warning("Worker " + str(threadId) + " Redis client - TimeStamp list for " + host + " is Empty, don't fetch") else : # Fetch and write infos writedInfos = [] hostID = None writedInfos, hostID = self.workerFetchInfos(pollerRedisConnect, threadId,host) self.workerCleanInfo(writedInfos, hostID, threadId) # Fetch and write datas self.workerFetchDatas(pollerRedisConnect, threadId, host, hostID, lastFetch, fetchEnd) # Thread End sema.release()
def get_init(self): # Redis connexion with no error self._redis_connexion = myRedisConnect(host="127.0.0.1", port=8888, password="******",db=0) self.assertFalse(self._redis_connexion._error)