Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Ceryx is configured with the following environment variables:
- `CERYX_REDIS_PASSWORD`: Optional password to use for authenticating with Redis (default: None)
- `CERYX_REDIS_PORT`: The where Redis should be reached (default: `6379`)
- `CERYX_REDIS_PREFIX`: The prefix to use in Ceryx-related Redis keys (default: `ceryx`)
- `CERYX_REDIS_TIMEOUT`: The timeout for all Redis operations, including the intial connection to Redis, specified in milliseconds (default: `100`)
- `CERYX_SSL_DEFAULT_CERTIFICATE`: The path to the fallback SSL certificate (default: `/etc/ceryx/ssl/default.crt` — randomly generated at build time)
- `CERYX_SSL_DEFAULT_KEY`: The path to the fallback SSL certificate key (default: `/etc/ceryx/ssl/default.key` — randomly generated at build time)

Expand Down
5 changes: 3 additions & 2 deletions api/ceryx/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ def from_config(path=None):
settings.REDIS_PASSWORD,
0,
settings.REDIS_PREFIX,
settings.REDIS_TIMEOUT,
)

def __init__(self, host, port, password, db, prefix):
self.client = redis.StrictRedis(host=host, port=port, password=password, db=db)
def __init__(self, host, port, password, db, prefix, timeout):
self.client = redis.StrictRedis(host=host, port=port, password=password, db=db, socket_timeout=timeout, socket_connect_timeout=timeout)
self.prefix = prefix

def _prefixed_key(self, key):
Expand Down
1 change: 1 addition & 0 deletions api/ceryx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
REDIS_PORT = int(os.getenv("CERYX_REDIS_PORT", 6379))
REDIS_PASSWORD = os.getenv("CERYX_REDIS_PASSWORD", None)
REDIS_PREFIX = os.getenv("CERYX_REDIS_PREFIX", "ceryx")
REDIS_TIMEOUT = int(os.getenv("CERYX_REDIS_TIMEOUT", 100)) * 0.001 # Python Redis client requires units of seconds
3 changes: 2 additions & 1 deletion ceryx/nginx/conf/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env CERYX_REDIS_PREFIX;
env CERYX_REDIS_HOST;
env CERYX_REDIS_PASSWORD;
env CERYX_REDIS_PORT;
env CERYX_REDIS_TIMEOUT;

events {
worker_connections 1024;
Expand Down Expand Up @@ -54,4 +55,4 @@ http {
include mime.types;
include ceryx.conf;
include ../sites-enabled/*;
}
}
3 changes: 2 additions & 1 deletion ceryx/nginx/lualib/ceryx/redis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local prefix = utils.getenv("CERYX_REDIS_PREFIX", "ceryx")
local host = utils.getenv("CERYX_REDIS_HOST", "127.0.0.1")
local port = utils.getenv("CERYX_REDIS_PORT", 6379)
local password = utils.getenv("CERYX_REDIS_PASSWORD", nil)
local timeout = utils.getenv("CERYX_REDIS_TIMEOUT", 100) -- 100 ms

local exports = {}

Expand All @@ -13,7 +14,7 @@ function exports.client()
ngx.log(ngx.DEBUG, "Preparing Redis client.")

local red = redis:new()
red:set_timeout(100) -- 100 ms
red:set_timeout(timeout)

local res, err = red:connect(host, port)

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
CERYX_DOCKERIZE_EXTRA_ARGS: -no-overwrite
CERYX_REDIS_HOST: ${CERYX_REDIS_HOST:-redis}
CERYX_REDIS_PORT: ${CERYX_REDIS_PORT:-6379}
CERYX_REDIS_TIMEOUT: ${CERYX_REDIS_TIMEOUT:-100}
command:
- usr/local/openresty/bin/openresty
- -g
Expand All @@ -32,6 +33,7 @@ services:
CERYX_DEBUG: ${CERYX_DEBUG:-false}
CERYX_REDIS_HOST: ${CERYX_REDIS_HOST:-redis}
CERYX_REDIS_PORT: ${CERYX_REDIS_PORT:-6379}
CERYX_REDIS_TIMEOUT: ${CERYX_REDIS_TIMEOUT:-100}

redis:
image: redis:3.2.11-alpine
Expand Down