Permalink
Browse files

read servers from spymemcached

  • Loading branch information...
flyerhzm committed Jul 24, 2012
1 parent fb1b4e7 commit 1f97fb527d98e95fee4be992458ea87bdd66eb74
Showing with 4 additions and 15 deletions.
  1. +4 −8 lib/memcached.rb
  2. +0 −7 spec/memcached_spec.rb
  3. BIN target/spymemcached-ext-0.0.1.jar
View
@@ -11,6 +11,7 @@ class Memcached
include_class 'net.spy.memcached.DefaultHashAlgorithm'
include_class 'net.spy.memcached.FailureMode'
include_class 'net.spy.memcached.transcoders.SimpleTranscoder'
+ include_class 'net.spy.memcached.AddrUtil'
FLAGS = 0x0
DEFAULTS = {
@@ -22,18 +23,13 @@ class Memcached
attr_reader :default_ttl
def initialize(addresses, options={})
- @options = DEFAULTS.merge(options)
- @servers = Array(addresses).map do |address|
- host, port = address.split(":")
- InetSocketAddress.new host, port.to_i
- end
builder = ConnectionFactoryBuilder.new.
setLocatorType(Locator::CONSISTENT).
setHashAlg(DefaultHashAlgorithm::FNV1_32_HASH)
- @client = MemcachedClient.new builder.build, @servers
+ @client = MemcachedClient.new builder.build, AddrUtil.getAddresses(Array(addresses).join(' '))
+ @options = DEFAULTS.merge(options)
@default_ttl = @options[:default_ttl]
- @flags = @options[:flags]
@simple_transcoder = SimpleTranscoder.new
end
@@ -83,7 +79,7 @@ def get(key, marshal=true)
end
def servers
- @servers.map { |server| server.to_s[1..-1] }
+ @client.available_servers.map { |address| address.to_s.split("/").last }
end
def close
View
@@ -1,13 +1,6 @@
require 'spec_helper'
describe Memcached do
- context "stub memcached" do
- before { Java::NetSpyMemcached::MemcachedClient.expects(:new) }
- subject { Memcached.new(["10.0.0.1:11211", "10.0.0.2:11211"], :default_ttl => 100) }
- its(:servers) { should == ["10.0.0.1:11211", "10.0.0.2:11211"] }
- its(:default_ttl) { should == 100 }
- end
-
context "localhost" do
before :all do
@memcached = Memcached.new("127.0.0.1:11211")
Binary file not shown.

0 comments on commit 1f97fb5

Please sign in to comment.