Henrik, Thank you for sharing. I have also thought about using redis for session state.
Just curious on the coding style, why did you choose to use a class? I have noticed some of your other code uses classes too. In general I think of using classes to encapsulate state or to group related functions. I tend to use picolisp in more of a functional form possibly because its a breath of fresh air after 10 years of oop in c#. I sometimes wonder when its a good fit to mix in oop in picolisp. Thanks Joe On Nov 25, 2012 2:20 PM, "Henrik Sarvell" <[email protected]> wrote: > Hi everyone, at work I use Redis ( http://redis.io/ ) for various things > such as session data, to avoid as much disk scratching as possible (I've > configured it to only live in memory). > > I thought it would be interesting to see how much work it would take to > implement a Redis client in PL, as it happens not much. > > The most interesting part of the documentation for the purpose: > http://redis.io/topics/protocol > http://redis.io/topics/data-types > > The below is by no means a complete client that can handle all scenarios > but I thought I might just put it "out there". In case someone else gets > the same idea they won't have to start from scratch. > > (class +Redis) > > (dm e> (Cmd . @) > (let? Sock (connect "localhost" 6379) > (prog1 > (out Sock > (prinl "*" (+ 1 (length (rest))) "^M") > (for Arg (append (list Cmd) (rest)) > (prinl "$" (size Arg) "^M") > (prinl (pack Arg "^M")) ) > (flush) > (in Sock > (let? Res (char) > (cond > ((= Res "+") (line T)) #status > ((= Res ":") (any (line T))) #integer > ((= Res "$") #bulk > (let Length (peek) > (if (= Length "-") > NIL > (line) > (line T) ) ) ) > ((= Res "*") #multi bulk > (let Length (any (line T)) > (if (member Length '("0" "-")) > NIL > (make > (do Length > (line) > (link (line T)) ) ) ) ) ) > (T NIL) ) ) ) ) > (close Sock) ) ) ) > > (de redis (Cmd . @) > (apply 'e> (rest) '+Redis (uppc Cmd))) > > (println (redis 'set "key" "value")) > (println (redis 'get "monkey")) > (println (redis 'get "key")) > (println (redis 'lpush "monkeys" "orangutang")) > (println (redis 'lpush "monkeys" "gorilla")) > (println (redis 'lpush "monkeys" "schimpanzee")) > (println (redis 'lrange "monkeys" 0 2)) > > > Output: > "OK" > NIL > "value" > 1 > 2 > 3 > ("schimpanzee" "gorilla" "orangutang") > >
