Nikhil Marathe, Newlisp Bindings for Redis Database

Featuring the Dragonfly web framework

Nikhil Marathe, Newlisp Bindings for Redis Database

Postby Kazimir Majorinc » Thu Jan 21, 2010 2:05 pm

Kazimir Majorinc
 
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia

Re: Nikhil Marathe, Newlisp Bindings for Redis Database

Postby itistoday » Fri Jan 22, 2010 7:56 pm

Neat, thanks for sharing this.
Get your Objective newLISP groove on.
itistoday
 
Posts: 413
Joined: Sun Dec 02, 2007 5:10 pm
Location: I'm sitting right next to you. :)

Re: Nikhil Marathe, Newlisp Bindings for Redis Database

Postby jazper » Tue May 01, 2012 8:22 pm

I was really pleased to find this, and I am very keen to use it. However, to quote the old song "I can't get started". I have started redis-server, and have redis-cli running. Then I try to run the little sample from redis.lsp:
Code: Select all
(load "/home/myname/newlisp-redis/redis.lsp")
 (setf 'conn (redis))
 (:ping redis)
the error is:
Code: Select all
ERR: list expected in function : : ((host "localhost") (port 6379))

Looking at the code in redis.lsp, it appears those two are supplied already in the definition:
Code: Select all
;; @syntax (redis [host] [port])
;; Creates a new connection to a Redis instance
;; @return a new connection object or nil on error
(define (redis:redis (host "localhost") (port 6379))
  (let (sock (net-connect host port))
    (if (nil? sock)
      nil
      (list redis sock ""))))

The first line works. It returns
Code: Select all
(redis 3 "")
which is consistent with what redis-cli responds when a connection is made.

Can someone please help?
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: Nikhil Marathe, Newlisp Bindings for Redis Database

Postby Lutz » Tue May 01, 2012 10:05 pm

I think redis.lsp is based on an older version of newLISP previous to 10.2 (after March 2010). In version 10.2 FOOP (the object system in newLISP) was changed to allow referencing the target object via a 'self' keyword. (self) returns the object of the message which can be changed when using destructive functions.

As an example:

Code: Select all
; pre 10.2 of newLISP
(define (redis:query r command-str)
  (net-send (r 1) (append command-str redis:CRLF))
  (redis:read r))

; post 10.2 of newLISP (March 2010)
(define (redis:query command-str) ; the object r does not appear here
  (net-send (self 1) (append command-str redis:CRLF))
  (:read (self)))  ; message calls always must start with : colon


Basically inside the FOOP function definition the object is referenced by (self) which can be indexed too, e.g. (self 1) for the first member of the object after the class symbol in the obj list.

The message function call:

Code: Select all
(:<message> <target-obj> <arg-1> <arg-2> ...)


and the definition of <message>:

Code: Select all
(define (<class>:<message <arg-1> <arg-2>)
; reference <target-obj> using (self)
)


The constructors have not changed.

See also here:

http://www.newlisp.org/downloads/previo ... lease.html
Lutz
 
Posts: 5253
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Nikhil Marathe, Newlisp Bindings for Redis Database

Postby jazper » Wed May 02, 2012 2:10 pm

Thanks once again, Lutz.

I have not done any FOOP. Seems like I am about to start! Because it appears a few tweaks of redis.lsp will be needed.
jazper
 
Posts: 91
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa


Return to So, what can you actually DO with newLISP?

Who is online

Users browsing this forum: No registered users and 1 guest

cron