fix for new carp
This commit is contained in:
@@ -4,13 +4,13 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="../style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<a href="http://github.com/carp-lang/Carp">
|
<a href="https://veitheller/git/carpentry/redis">
|
||||||
<img src="logo.png">
|
<img src="">
|
||||||
</a>
|
</a>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
redis
|
redis
|
||||||
@@ -53,7 +53,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Array String)] RESP)
|
(Fn [(Array String)] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [String] RESP)
|
(Fn [String] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [Int] RESP)
|
(Fn [Int] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [] RESP)
|
(Fn [] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [String] RESP)
|
(Fn [String] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref RESP a)] RESP)
|
(Fn [(Ref RESP a)] RESP)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
defn
|
defn
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref String a)] (Result RESP String))
|
(Fn [(Ref String a)] (Result RESP String))
|
||||||
</p>
|
</p>
|
||||||
<pre class="args">
|
<pre class="args">
|
||||||
(from-string s)
|
(from-string s)
|
||||||
@@ -193,7 +193,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref RESP a)] Int)
|
(Fn [(Ref RESP a)] Int)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
instantiate
|
instantiate
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref RESP a)] String)
|
(Fn [(Ref RESP a)] String)
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
|
|||||||
defn
|
defn
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref RESP a)] String)
|
(Fn [(Ref RESP a)] String)
|
||||||
</p>
|
</p>
|
||||||
<pre class="args">
|
<pre class="args">
|
||||||
(str r)
|
(str r)
|
||||||
|
514
docs/Redis.html
514
docs/Redis.html
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="../style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
(Project.config "docs-directory" "./docs/")
|
(Project.config "docs-directory" "./docs/")
|
||||||
(Project.config "docs-logo" "")
|
(Project.config "docs-logo" "")
|
||||||
(Project.config "docs-url" "https://veitheller/git/carpentry/redis")
|
(Project.config "docs-url" "https://veitheller/git/carpentry/redis")
|
||||||
(Project.config "docs-styling" "style.css")
|
(Project.config "docs-styling" "../style.css")
|
||||||
(Project.config "docs-prelude" "is a collection of modules for talking
|
(Project.config "docs-prelude" "is a collection of modules for talking
|
||||||
to Redis.
|
to Redis.
|
||||||
|
|
||||||
|
82
redis.carp
82
redis.carp
@@ -1,4 +1,4 @@
|
|||||||
(load "git@github.com:carpentry-org/sockets@master")
|
(load "git@github.com:carpentry-org/sockets@0.0.2")
|
||||||
|
|
||||||
(deftype RESP
|
(deftype RESP
|
||||||
(Null [])
|
(Null [])
|
||||||
@@ -30,11 +30,12 @@
|
|||||||
(if (starts-with? s "-1\r\n")
|
(if (starts-with? s "-1\r\n")
|
||||||
(Success (Null))
|
(Success (Null))
|
||||||
(let [splt (split #"\r\n" s)
|
(let [splt (split #"\r\n" s)
|
||||||
l &(unsafe-first &splt)]
|
l (unsafe-first &splt)]
|
||||||
(if (not (num? l))
|
(match (from-string l)
|
||||||
(Error @"Error decoding bulk string: does not start with length!")
|
(Maybe.Nothing) (Error @"Error decoding bulk string: does not start with length!")
|
||||||
(Success (Str
|
(Maybe.Just il)
|
||||||
(String.prefix &(join "\r\n" &(suffix &splt 1)) (from-string l))))))))
|
(Success (Str
|
||||||
|
(String.prefix &(join "\r\n" &(suffix &splt 1)) il)))))))
|
||||||
|
|
||||||
(hidden agg)
|
(hidden agg)
|
||||||
(private agg)
|
(private agg)
|
||||||
@@ -56,42 +57,49 @@
|
|||||||
(if (starts-with? s "*0\r\n")
|
(if (starts-with? s "*0\r\n")
|
||||||
(Success (Null))
|
(Success (Null))
|
||||||
(let [splt (split #"\r\n" &(chomp s))
|
(let [splt (split #"\r\n" &(chomp s))
|
||||||
sl &(unsafe-first &splt)]
|
sl (unsafe-first &splt)]
|
||||||
(if (not (num? sl))
|
(match (from-string sl)
|
||||||
(Error @"Error decoding array: does not start with length!")
|
(Maybe.Nothing)
|
||||||
(let-do [l (from-string sl)
|
(Error @"Error decoding array: does not start with length!")
|
||||||
a (Array.allocate l)
|
(Maybe.Just l)
|
||||||
idx 0
|
(let-do [a (Array.allocate l)
|
||||||
err ""]
|
idx 0
|
||||||
(for [i 0 (- (length &splt) 1)]
|
err ""]
|
||||||
; TODO: have nested structures
|
(for [i 0 (- (length &splt) 1)]
|
||||||
(let-do [el (unsafe-nth &splt (+ i 1))]
|
; TODO: have nested structures
|
||||||
(case (head el)
|
(let-do [el (unsafe-nth &splt (+ i 1))]
|
||||||
\$
|
(case (head el)
|
||||||
(let [il (from-string &(tail el))]
|
\$
|
||||||
(if (= -1 il)
|
(match (from-string &(tail el))
|
||||||
(aset-uninitialized! &a idx @"")
|
(Maybe.Nothing)
|
||||||
(let-do [rest (suffix &splt (+ i 2))]
|
(aset-uninitialized! &a idx @"")
|
||||||
(aset-uninitialized! &a idx (String.prefix &(join "\r\n" &rest) il))
|
(Maybe.Just il)
|
||||||
(set! i (+ i (agg &rest il))))))
|
(let-do [rest (suffix &splt (+ i 2))]
|
||||||
\*
|
(aset-uninitialized! &a idx (String.prefix &(join "\r\n" &rest) il))
|
||||||
(do
|
(set! i (+ i (agg &rest il)))))
|
||||||
(set! err "TODO: cannot deal with nested arrays")
|
\*
|
||||||
(break))
|
(do
|
||||||
(aset-uninitialized! &a idx (chomp el)))
|
(set! err "TODO: cannot deal with nested arrays")
|
||||||
(set! idx (inc idx))))
|
(break))
|
||||||
(if (= err "")
|
(aset-uninitialized! &a idx (chomp el)))
|
||||||
(Success (Arr a))
|
(set! idx (inc idx))))
|
||||||
(Error @err)))))))
|
(if (= err "")
|
||||||
|
(Success (Arr a))
|
||||||
|
(Error @err)))))))
|
||||||
|
|
||||||
(doc from-string "converts a RESP string into a `RESP` data structure.")
|
(doc from-string "converts a RESP string into a `RESP` data structure.")
|
||||||
(defn from-string [s]
|
(defn from-string [s]
|
||||||
(if (empty? s)
|
(if (empty? s)
|
||||||
(Success (Null))
|
(Success (Null))
|
||||||
(case (head s)
|
(case (head s)
|
||||||
\+ (Success (Str (unsafe-first &(split #"\r\n" &(tail s)))))
|
\+ (Success (Str @(unsafe-first &(split #"\r\n" &(tail s)))))
|
||||||
\- (Success (Err (unsafe-first &(split #"\r\n" &(tail s)))))
|
\- (Success (Err @(unsafe-first &(split #"\r\n" &(tail s)))))
|
||||||
\: (Success (Integer (from-string &(unsafe-first &(split #"\r\n" &(tail s))))))
|
\:
|
||||||
|
(match (from-string (unsafe-first &(split #"\r\n" &(tail s))))
|
||||||
|
(Maybe.Nothing)
|
||||||
|
(Error @"Could not parse integer in result.")
|
||||||
|
(Maybe.Just i)
|
||||||
|
(Success (Integer i)))
|
||||||
\$ (decode-bulk-string &(tail s))
|
\$ (decode-bulk-string &(tail s))
|
||||||
\* (decode-arr &(tail s))
|
\* (decode-arr &(tail s))
|
||||||
(Error (fmt "Malformed RESP data: got %s" s)))))
|
(Error (fmt "Malformed RESP data: got %s" s)))))
|
||||||
@@ -101,10 +109,12 @@
|
|||||||
|
|
||||||
(defmodule String
|
(defmodule String
|
||||||
(defn to-redis [s] (RESP.Str s))
|
(defn to-redis [s] (RESP.Str s))
|
||||||
|
(implements to-redis String.to-redis)
|
||||||
)
|
)
|
||||||
|
|
||||||
(defmodule Int
|
(defmodule Int
|
||||||
(defn to-redis [s] (RESP.Integer s))
|
(defn to-redis [s] (RESP.Integer s))
|
||||||
|
(implements to-redis Int.to-redis)
|
||||||
)
|
)
|
||||||
|
|
||||||
(deftype Redis [
|
(deftype Redis [
|
||||||
|
Reference in New Issue
Block a user