lib/memcached_test/memcached.rb in memcached_test-0.1.0 vs lib/memcached_test/memcached.rb in memcached_test-1.0.0
- old
+ new
@@ -34,65 +34,65 @@
return result
end
def set(key, flags, exptime, bytes, data)
if @cache.key?(key)
- item = Memcached_item.new(flags, exptime, bytes, @cache[key].cas + 1, data)
+ item = Memcached_item.new(flags, exptime, bytes, @cache[key].cas.to_i + 1, data[0, bytes.to_i])
@cache[key] = item
return "STORED\r\n"
else
- item = Memcached_item.new(flags, exptime, bytes, 1, data)
+ item = Memcached_item.new(flags, exptime, bytes, 1, data[0, bytes.to_i])
@cache[key] = item
return "STORED\r\n"
end
end
def add(key, flags, exptime, bytes, data)
if @cache.key?(key)
return "NOT_STORED\r\n"
else
- item = Memcached_item.new(flags, exptime, bytes, 1, data)
+ item = Memcached_item.new(flags, exptime, bytes, 1, data[0, bytes.to_i])
@cache[key] = item
return "STORED\r\n"
end
end
def replace(key, flags, exptime, bytes, data)
if @cache.key?(key)
- item = Memcached_item.new(flags, exptime, bytes, @cache[key].cas + 1, data)
+ item = Memcached_item.new(flags, exptime, bytes, @cache[key].cas + 1, data[0, bytes.to_i])
@cache[key] = item
return "STORED\r\n"
else
return "NOT_STORED\r\n"
end
end
- def append(key, flags, exptime, bytes, data)
+ def append(key, bytes, data)
if @cache.key?(key)
item_old = @cache[key]
- item_new = Memcached_item.new(flags, exptime, bytes, @cache[key].cas + 1, item_old.data + data)
+ item_new = Memcached_item.new(item_old.flags, item_old.exptime, item_old.bytes.to_i + bytes.to_i, @cache[key].cas + 1, item_old.data + data[0, bytes.to_i])
@cache[key] = item_new
return "STORED\r\n"
else
return "NOT_STORED\r\n"
end
end
- def prepend(key, flags, exptime, bytes, data)
+ def prepend(key, bytes, data)
if @cache.key?(key)
item_old = @cache[key]
- item_new = Memcached_item.new(flags, exptime, bytes, @cache[key].cas + 1, data + item_old.data)
+ item_new = Memcached_item.new(item_old.flags, item_old.exptime, item_old.bytes.to_i + bytes.to_i, @cache[key].cas + 1, data[0, bytes.to_i] + item_old.data)
@cache[key] = item_new
return "STORED\r\n"
else
return "NOT_STORED\r\n"
end
end
def cas(key, flags, exptime, bytes, cas, data)
if @cache.key?(key)
- if @cache[key].cas == cas
- item = Memcached_item.new(flags, exptime, bytes, cas, data)
+ if @cache[key].cas == cas.to_i
+ item = Memcached_item.new(flags, exptime, bytes, cas.to_i + 1, data[0, bytes.to_i])
@cache[key] = item
return "STORED\r\n"
else
return "EXISTS\r\n"
end
\ No newline at end of file