-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathob-redis.el
63 lines (52 loc) · 1.63 KB
/
ob-redis.el
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
;;; ob-redis.el --- Execute Redis queries within org-mode blocks.
;; Copyright 2016 stardiviner
;; Author: stardiviner <numbchild@gmail.com>
;; Maintainer: stardiviner <numbchild@gmail.com>
;; Maintainer: nekifirus <nekifirus@gmail.com>
;; Keywords: org babel redis
;; URL: https://github.com/stardiviner/ob-redis
;; Created: 28th Feb 2016
;; Modified: 1th Dec 2019
;; Version: 0.0.2
;; Package-Requires: ((org "8"))
;;; Commentary:
;;
;; Execute Redis queries within org-mode blocks.
;; Can set parameters
;; :host - ip-address of redis host
;; :port - port of redis host
;; :db - db number in redis
;;; Code:
(require 'org)
(require 'ob)
(defgroup ob-redis nil
"org-mode blocks for Redis."
:group 'org)
(defcustom ob-redis:default-host "127.0.0.1"
"Default ip-address for redis host."
:group 'ob-redis
:type 'string)
(defcustom ob-redis:default-port 6379
"Default port for redis host."
:group 'ob-redis
:type 'integer)
(defcustom ob-redis:default-db 0
"Default Redis database."
:group 'ob-redis
:type 'integer)
;;;###autoload
(defun org-babel-execute:redis (body params)
"Org-babel redis hook.
Argument BODY body of org source block.
Argument PARAMS org-babel params."
(let* ((host (shell-quote-argument
(alist-get :host params ob-redis:default-host)))
(port (alist-get :port params ob-redis:default-port))
(db (alist-get :db params ob-redis:default-db))
(cmd (format "redis-cli -h %s -p %s -n %s" host port db)))
(org-babel-eval cmd body)))
;;;###autoload
(eval-after-load "org"
'(add-to-list 'org-src-lang-modes '("redis" . redis)))
(provide 'ob-redis)
;;; ob-redis.el ends here