Unexpected results in Ruby+C memcache library

rm_memcached at cheapcomplexdevices.com rm_memcached at cheapcomplexdevices.com
Tue Nov 22 15:57:17 PST 2005


Short summary:
  * Thanks for the Ruby/memcache library Sean.
  * I think I found a bug in the ruby/C binding
  * Patch attached.


Back in Jan, Sean Chittenden wrote:
>Subject: memcache API happiness for C and Ruby users...
>...
>I'm pleased to announce the availability of ruby-memcache:
>...
>Let me know if anyone has any Q's or bugs,

I'm getting some odd results when I try to get multiple 
values using "get_a" from your ruby/c memcache library.

This Ruby program is giving me an expected result when
fetching an array of results from memcache
#######################
 require 'memcache'                    # require library
 mc = Memcache.new                     # create class
 mc.add_server('127.0.0.1:11211')      # just one server
 a = (1..10).map{|x| x.to_s}           # test array
 a.each{|x| mc[x] = x}                 # insert test values
 p a            # ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
 p mc.get_a(*a) # ["1", "2", "3", "4", "5", "6", "7", "8", "9", "1"]
#######################

I expected "10" at the end of that second array.

I'm using:
 http://people.freebsd.org/~seanc/libmemcache/libmemcache-1.4.0.b9.tar.bz2
 http://rubyforge.org/frs/download.php/2484/ruby-memcache-0.1.0.tar.bz2
and the code looks the same to me as the head revision here:
 http://rubyforge.org/cgi-bin/viewcvs.cgi/memcache/?cvsroot=memcache#dirlist 

I think the patch below fixes the problem for me:

#####################################################################

> diff -c memcache.c.orig memcache.c
*** memcache.c.orig     Tue Jan  4 23:52:43 2005
--- memcache.c  Tue Nov 22 15:46:43 2005
***************
*** 218,224 ****
    ret = rb_ary_new2(argc);
    req = mc_req_new();
    for (i = 0; i < (u_int32_t)argc; i++) {
!     res = mc_req_add(req, RSTRING(argv[i])->ptr, RSTRING(argv[0])->len);
      mc_res_free_on_delete(res, 0);
    }

--- 218,224 ----
    ret = rb_ary_new2(argc);
    req = mc_req_new();
    for (i = 0; i < (u_int32_t)argc; i++) {
!     res = mc_req_add(req, RSTRING(argv[i])->ptr, RSTRING(argv[i])->len);
      mc_res_free_on_delete(res, 0);
    }

#####################################################################

  Ron


More information about the memcached mailing list