-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.mojo
66 lines (51 loc) · 1.62 KB
/
config.mojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from libc import exit
from algorithm import num_cores
from os import getenv
# firedis config defaults
alias FIREDIS_MAX_CLIENTS = 128
alias FIREDIS_CORE_MULTIPLIER = 1000
alias FIREDIS_PORT = 6379
alias FIREDIS_HOST = "0.0.0.0"
struct FiredisConfig:
"""
Firedis configuration struct.
"""
var max_clients: Int
var core_multiplier: Int
var workers: Int
var port: UInt16
var host: StringRef
fn __init__(
inout self: Self,
max_clients: Int,
core_multiplier: Int,
workers: Int,
port: UInt16,
host: StringRef,
):
self.max_clients = max_clients
self.core_multiplier = core_multiplier
self.workers = workers
self.port = port
self.host = host
fn load_config() -> FiredisConfig:
try:
var max_clients = atol(getenv("MAX_CLIENTS", "-1"))
var core_multiplier = atol(getenv("CORE_MULTIPLIER", "-1"))
var port = atol(getenv("PORT", "-1"))
let host = getenv("HOST", FIREDIS_HOST)
if port == -1:
port = FIREDIS_PORT
if core_multiplier == -1:
core_multiplier = FIREDIS_CORE_MULTIPLIER
if max_clients == -1:
max_clients = FIREDIS_MAX_CLIENTS
var workers = (num_cores() * core_multiplier)
if workers > max_clients:
workers = max_clients
return FiredisConfig(max_clients, core_multiplier, workers, port, host)
except e:
print("> failed to start firedis:", e.value)
print("> error loading configuration, exiting...")
exit(-1)
return FiredisConfig(-1, -1, -1, 0, "")