-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lisp
43 lines (36 loc) · 1.39 KB
/
utils.lisp
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
(in-package #:issr)
(defun server-uuid ()
(let ((filename
(merge-pathnames
"issr/uuid.txt"
(or (uiop:getenvp "XDG_DATA_HOME")
"~/.local/share/"))))
(unless (uiop:directory-exists-p (pathname-directory filename))
(ensure-directories-exist filename))
(if (uiop:file-exists-p filename)
(uiop:read-file-string filename)
(with-open-file (out filename
:direction :output
:if-does-not-exist :create)
(let ((uuid (princ-to-string (uuid:make-v4-uuid))))
(write-sequence uuid out))))))
(defun destination-parts (destination)
(typecase destination
(integer
(values "localhost" destination))
(string
(let ((parts (str:split ":" destination :omit-nulls t)))
(values (first parts)
(parse-integer (second parts)))))))
(defun issr-keys (main-key &rest keys)
(->> keys
(map 'list (compose 'str:downcase 'princ-to-string))
(cons (str:concat "issr-" (princ-to-string main-key)))
(str:join ":")))
(defvar *redis-destination* "localhost:6379")
(defvar *redis-password* nil)
(defmacro with-redis-connection (&body body)
`(multiple-value-bind (redis-host redis-port)
(destination-parts *redis-destination*)
(redis:with-connection (:host redis-host :port redis-port :auth *redis-password*)
,@body)))