libmemcached api

Notices and updates
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

libmemcached api

Post by Jeff »

I've added a module to use the libmemcached C/C++ library to Artful Code. It's a dev release, but the functions that are finished are working reliably.

http://static.artfulcode.net/newlisp/memcached.lsp.html
memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Good work Jeff - you're really productive at the moment! I'm struggling to keep up with you...

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Actually, I've just been documenting and posting a lot of the code that I've got lying around :)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Re: libmemcached api

Post by methodic »

Hi Jeff.

Thanks for the code... unfortunately I don't seem to be able to get it working correctly under 10.1.7. I load the .lsp file, do a memcached:init, memcached:add-server (I know the server is running and works)... and then when I do a memcached:get-key <some_key> that I know for sure doesn't exist, the function returns true.

Code: Select all

> (load "memcached.lsp")
MAIN
> (memcached:init)
true
> (memcached:add-server "localhost" 11211)
true
> (memcached:get-key "doesnt_exist")
true
Am I doing something wrong/stupid? :)

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Re: libmemcached api

Post by Jeff »

Without checking the code again, it looks like you are doing things right. Unfortunately, I do not have a lot of time for personal projects at the moment. If you can find the bug and fix it, I would be happy to update the sources on my site and google projects.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Re: libmemcached api

Post by methodic »

Sure, I will dig into it and see what's going on. I just wanted to make sure it wasn't PEBKAC. :)

methodic
Posts: 58
Joined: Tue May 10, 2005 5:04 am

Re: libmemcached api

Post by methodic »

Hey Jeff:

This seems to work for me:

Code: Select all

(define (get-key key , res (value-length 0) (flags 0))
  (when MEMCACHED
    (setq res (memcached_get MEMCACHED
                             key (length key)
                             (address value-length)
                             (address flags)
                             (address MEMCACHED_RETURN)))
    ;(unless (zero? res) (get-string res))))
    (if (zero? res)
      nil
      (get-string res))))
I commented out the unless in case you wanted to format it differently.

Code: Select all

> (load "memcached.lsp")
MAIN
> (memcached:init)
true
> (memcached:add-server "localhost" 11211)
true
>  (memcached:get-key "TEST")
nil
>  (memcached:set-key "TEST" "testing" 60)
"testing"
>  (memcached:get-key "TEST")
"testing"
> (sleep 60000)
60000
>  (memcached:get-key "TEST")
nil
Hope this was helpful, thanks!!

Locked