RESP

is a wrapper around the Redis Serialization Protocol. You can create all types, stringify the built types into strings using str, and decode from the string protocol using from-string. Arrays are fully supported, including nested arrays.

; decoding
(RESP.from-string "+OK\r\n")       ; => (Success (Str @"OK"))
(RESP.from-string ":42\r\n")       ; => (Success (Integer 42))
(RESP.from-string "$-1\r\n")       ; => (Success (Null))

; encoding
(str &(RESP.Str @"hi"))             ; => "$2\r\nhi\r\n"
(str &(RESP.Integer 42))            ; => ":42\r\n"

; pattern matching on responses
(match (Redis.get &r @"key")
  (Result.Success resp)
    (match resp
      (RESP.Str s) (println* "got: " &s)
      (RESP.Null) (println* "not found")
      (RESP.Arr items) (println* "array of " &(Int.str (Array.length &items)))
      _ (println* "other"))
  (Result.Error e) (println* "error: " &e))

If you want your types to be supported when encoding, you’ll have to implement the interface to-redis, the signature of which is (Fn [a] RESP)).

Arr

instantiate

(Fn [(Array (Box RESP))] RESP)

creates a Arr.

Err

instantiate

(Fn [String] RESP)

creates a Err.

Integer

instantiate

(Fn [Int] RESP)

creates a Integer.

Null

instantiate

(Fn [] RESP)

creates a Null.

Str

instantiate

(Fn [String] RESP)

creates a Str.

copy

instantiate

(Fn [(Ref RESP a)] RESP)

copies a RESP.

delete

instantiate

(Fn [RESP] ())

deletes a RESP. This should usually not be called manually.

from-string

defn

(Fn [(Ref String a)] (Result RESP String))

                        (from-string s)
                    

converts a RESP string into a RESP data structure.

get-tag

instantiate

(Fn [(Ref RESP a)] Int)

Gets the tag from a RESP.

prn

instantiate

(Fn [(Ref RESP a)] String)

converts a RESP to a string.

str

defn

(Fn [(Ref RESP a)] String)

                        (str r)
                    

converts a RESP to a string.