From 8e47e4e7c84bd2804ae726dd3cbed51a2f194ad3 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 6 Feb 2015 16:17:05 -0800 Subject: [PATCH] Add OlegDB client --- lib/oleg.moon | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/oleg.moon diff --git a/lib/oleg.moon b/lib/oleg.moon new file mode 100644 index 0000000..703c1fe --- /dev/null +++ b/lib/oleg.moon @@ -0,0 +1,30 @@ +config = require("lapis.config").get! +http = require "lapis.nginx.http" + +request = (method, table, key, value=nil) -> + oleg_res, code = http.simple { + url: "http://#{config.oleg.host}:#{config.oleg.port}/#{table}/#{key}" + method: method + body: value + } + + if code ~= 200 + return nil, code + + if not oleg_res + return nil, 404 + + oleg_res, nil + +ret = {} + +ret.get = (table, key) -> + request "GET", table, key + +ret.delete = (table, key) -> + request "DELETE" + +ret.set = (table, key, value) -> + request "POST", table, key, value + +ret