Merge pull request 'Autostart a redis instance in nix shell.' (#22) from redis/nixshell-redis-autostart into redis/connection-pool
Reviewed-on: #22pull/23/head
commit
60919b88b9
|
@ -136,7 +136,7 @@ def get_system_provider_info() -> SystemProviderInfo:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return SystemProviderInfo(
|
return SystemProviderInfo(
|
||||||
provider=user_data["server"]["provider"],
|
provider=user_data["server"]["provider"],
|
||||||
id="UNKNOWN"
|
id="UNKNOWN",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ Redis pool module for selfprivacy_api
|
||||||
"""
|
"""
|
||||||
import redis
|
import redis
|
||||||
from selfprivacy_api.utils.singleton_metaclass import SingletonMetaclass
|
from selfprivacy_api.utils.singleton_metaclass import SingletonMetaclass
|
||||||
|
from os import environ
|
||||||
|
|
||||||
REDIS_SOCKET = "/run/redis-sp-api/redis.sock"
|
REDIS_SOCKET = "/run/redis-sp-api/redis.sock"
|
||||||
|
|
||||||
|
@ -13,10 +14,18 @@ class RedisPool(metaclass=SingletonMetaclass):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._pool = redis.ConnectionPool.from_url(
|
if "USE_REDIS_PORT" in environ.keys():
|
||||||
f"unix://{REDIS_SOCKET}",
|
self._pool = redis.ConnectionPool(
|
||||||
decode_responses=True,
|
host="127.0.0.1",
|
||||||
)
|
port=int(environ["USE_REDIS_PORT"]),
|
||||||
|
decode_responses=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
self._pool = redis.ConnectionPool.from_url(
|
||||||
|
f"unix://{REDIS_SOCKET}",
|
||||||
|
decode_responses=True,
|
||||||
|
)
|
||||||
self._pubsub_connection = self.get_connection()
|
self._pubsub_connection = self.get_connection()
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
|
|
|
@ -64,9 +64,14 @@ pkgs.mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
sp-python
|
sp-python
|
||||||
pkgs.black
|
pkgs.black
|
||||||
|
pkgs.redis
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
PYTHONPATH=${sp-python}/${sp-python.sitePackages}
|
PYTHONPATH=${sp-python}/${sp-python.sitePackages}
|
||||||
|
# envs set with export and as attributes are treated differently.
|
||||||
|
# for example. printenv <Name> will not fetch the value of an attribute.
|
||||||
|
export USE_REDIS_PORT=6379
|
||||||
|
redis-server --port $USE_REDIS_PORT >/dev/null &
|
||||||
# maybe set more env-vars
|
# maybe set more env-vars
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue