-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.spec
32 lines (27 loc) · 1.09 KB
/
redis.spec
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
(import "strings")
(define image "quilt/redis")
(define (createMaster prefix auth)
(let ((master (sprintf "%s-ms" prefix))
(redisDocker (docker image "run")))
(setEnv redisDocker "AUTH" auth)
(setEnv redisDocker "ROLE" "master")
(label master redisDocker)))
(define (createWorkers prefix n auth master)
(let ((labelNames (strings.Range (sprintf "%s-wk" prefix) n))
(redisDockers (makeList n (docker image "run"))))
(setEnv redisDockers "MASTER" (labelHost master))
(setEnv redisDockers "AUTH" auth)
(setEnv redisDockers "ROLE" "worker")
(map label labelNames redisDockers)))
(define (New prefix nWorker auth)
(let ((master (createMaster prefix auth))
(workers (createWorkers prefix nWorker auth master)))
(connect 6379 master workers)
(connect 6379 workers master)
(hmap ("master" master)
("worker" workers))))
(define (Exclusive redisMap)
(let ((exfn (lambda (x) (labelRule "exclusive" x)))
(rules (map exfn (hmapValues redisMap)))
(plfn (lambda (x) (place x (hmapValues redisMap)))))
(map plfn rules)))