Added redis config logic
This commit is contained in:
parent
da12d6628d
commit
b38a9b2fd3
@ -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;
|
@ -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)
|
||||
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user