Skip to content

Commit

Permalink
allow redis server to be something other localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
wllgrnt committed Oct 6, 2023
1 parent 0787d43 commit 3b9df7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion object_database/frontends/database_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ def main(argv):
help="path to (self-signed) SSL certificate",
)
parser.add_argument("--redis_port", type=int, default=None)
parser.add_argument("--redis_host", type=str, default=None)
parser.add_argument("--inmem", default=False, action="store_true")

parsedArgs = parser.parse_args(argv[1:])

if parsedArgs.inmem:
mem_store = InMemoryPersistence()
else:
mem_store = RedisPersistence(port=parsedArgs.redis_port)
mem_store = RedisPersistence(host=parsedArgs.redis_host, port=parsedArgs.redis_port)

ssl_ctx = sslContextFromCertPathOrNone(parsedArgs.ssl_path)
databaseServer = TcpServer(
Expand Down
8 changes: 7 additions & 1 deletion object_database/frontends/service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def startServiceManagerProcess(
sslPath=None,
proxyPort=None,
redisPort=None,
redisHost=None,
):
if not verbose:
kwargs = dict(stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Expand Down Expand Up @@ -102,6 +103,10 @@ def startServiceManagerProcess(
cmd.append("--redis_port")
cmd.append(str(redisPort))

if redisHost is not None:
cmd.append("--redis_host")
cmd.append(redisHost)

if logDir:
logsPath = os.path.join(tempDirectoryName, "logs")
cmd.extend(["--logdir", logsPath])
Expand Down Expand Up @@ -273,6 +278,7 @@ def main(argv=None):
help="path to (self-signed) SSL certificate",
)
parser.add_argument("--redis_port", type=int, default=None, required=False)
parser.add_argument("--redis_host", type=str, default=None, required=False)
parser.add_argument("--fd-limit", type=int, default=4096, required=False)

parser.add_argument("--max_gb_ram", type=float, default=None, required=False)
Expand Down Expand Up @@ -400,7 +406,7 @@ def shutdownCleanly(signalNumber, frame):
databaseServer = TcpServer(
ownHostname,
parsedArgs.port,
RedisPersistence(port=parsedArgs.redis_port)
RedisPersistence(host=parsedArgs.redis_host, port=parsedArgs.redis_port)
if parsedArgs.redis_port is not None
else InMemoryPersistence(),
ssl_context=ssl_ctx,
Expand Down
5 changes: 4 additions & 1 deletion object_database/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,16 @@ def delete(self, key):


class RedisPersistence(object):
def __init__(self, db=0, port=None):
def __init__(self, db=0, port=None, host=None):
self.lock = threading.RLock()
kwds = {}

if port is not None:
kwds["port"] = port

if host is not None:
kwds["host"] = host

self.redis = redis.StrictRedis(db=db, **kwds)
self.cache = {}

Expand Down

0 comments on commit 3b9df7e

Please sign in to comment.