Skip to content
Snippets Groups Projects
Commit eb8a1282 authored by Devin Burke's avatar Devin Burke Committed by Udai Singh
Browse files

Added support to specify the redis database index. Valid indices are integers from 0 to 15

parent 643e8743
No related branches found
No related tags found
1 merge request!5Added support to specify the redis database index. Valid indices are integers from 0 to 15
......@@ -187,7 +187,7 @@ class BlissdataDispatcher:
motors: List[str]
detectors: List[str]
def __init__(self, host: str = "localhost", port: int = 6379):
def __init__(self, host: str = "localhost", port: int = 6379, index: int = 0):
"""
Initializes the dispatcher with a connection to the Redis server.
......@@ -197,6 +197,8 @@ class BlissdataDispatcher:
The hostname of the Redis server (default is "localhost").
port : int, optional
The port number of the Redis server (default is 6379).
index : int, optional
The index of the Redis database to use (default is 0).
"""
# Initialize some instance variables
self.exception_handler = ExceptionHandler("Error in connecting to redis server")
......@@ -208,13 +210,20 @@ class BlissdataDispatcher:
_logger.info("Connecting to redis server")
if index not in range(16):
self.exception_handler(
ValueError(
"Invalid Redis database index. Must be an integer between 0 and 15."
)
)
try:
self._data_store = DataStore(f"redis://{host}:{port}", init_db=True)
self._data_store = DataStore(f"redis://{host}:{port}/{index}", init_db=True)
except OSError as e:
self.exception_handler(e)
except RuntimeError:
try:
self._data_store = DataStore(f"redis://{host}:{port}")
self._data_store = DataStore(f"redis://{host}:{port}/{index}")
except RuntimeError as exc:
self.exception_handler(exc)
......
......@@ -96,6 +96,15 @@ def parse_args(args):
help="redis connection port",
)
parser.add_argument(
"--redis-index",
"--redis_index",
dest="redis_index",
default=0,
type=int,
help="redis db index",
)
parser.add_argument(
"--zmq-host",
"--zmq_host",
......@@ -161,12 +170,16 @@ def main() -> None:
setup_logging(args.loglevel)
_logger.info("starting bluesky_blissdata")
_logger.info(f"Connection to redis sever: {args.redis_host}:{args.redis_port}")
_logger.info(
f"Connection to redis sever: {args.redis_host}:{args.redis_port}/{args.redis_index}"
)
_logger.info(f"Connection to zmq sever: {args.zmq_host}:{args.zmq_port}")
# Initialize RemoteDispatcher for Bluesky
d = RemoteDispatcher((args.zmq_host, args.zmq_port))
post_document = BlissdataDispatcher(args.redis_host, args.redis_port)
post_document = BlissdataDispatcher(
args.redis_host, args.redis_port, args.redis_index
)
# Subscribe the BlissdataDispatcher to the RemoteDispatcher
d.subscribe(post_document)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment