Added redis config logic

This commit is contained in:
Mario de Frutos 2015-11-16 14:01:51 +01:00
parent da12d6628d
commit b38a9b2fd3
3 changed files with 22 additions and 1 deletions

View File

@ -5,7 +5,26 @@ RETURNS boolean AS $$
return False
else:
from cartodb_geocoder import redis_helper
redis_connection = redis_helper.RedisHelper('localhost', 6379, 5).redis_connection()
config_params = plpy.execute("select c.host, c.port, c.timeout, c.db from cdb_geocoder_server._get_redis_conf() c;")[0]
redis_connection = redis_helper.RedisHelper(config_params['host'], config_params['port'], config_params['db']).redis_connection()
GD[user_id] = {'redis_connection': redis_connection}
return True
$$ LANGUAGE plpythonu;
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
host text,
port int,
timeout float,
db text
);
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf()
RETURNS cdb_geocoder_server._redis_conf_params AS $$
conf = plpy.execute("SELECT cdb_geocoder_server._config_get('redis_conf') conf")[0]['conf']
if conf is None:
plpy.error("There is no redis configuration defined")
else:
import json
params = json.loads(conf)
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'db': params['db'] }
$$ LANGUAGE plpythonu;

View File

@ -2,6 +2,7 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text)
RETURNS Geometry AS $$
from cartodb_geocoder import quota_service
plpy.debug('Entering geocode_admin0_polygons')
plpy.debug('user_id = %s' % user_id)

View File

@ -15,5 +15,6 @@ class RedisHelper:
return self.__create_redis_connection()
def __create_redis_connection(self):
#TODO Change to use Sentinel
pool = redis.ConnectionPool(host=self.host, port=self.port, db=self.db)
return redis.Redis(connection_pool=pool)