Page 1 of 1

libmemcached api

Posted: Mon Jul 21, 2008 8:09 pm
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.

Posted: Tue Jul 22, 2008 7:20 am
by cormullion
Good work Jeff - you're really productive at the moment! I'm struggling to keep up with you...

Posted: Tue Jul 22, 2008 11:41 am
by Jeff
Actually, I've just been documenting and posting a lot of the code that I've got lying around :)

Re: libmemcached api

Posted: Tue Dec 15, 2009 5:06 am
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? :)

Re: libmemcached api

Posted: Tue Dec 15, 2009 11:51 am
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.

Re: libmemcached api

Posted: Tue Dec 15, 2009 1:57 pm
by methodic
Sure, I will dig into it and see what's going on. I just wanted to make sure it wasn't PEBKAC. :)

Re: libmemcached api

Posted: Thu Dec 17, 2009 5:56 pm
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!!