Skip to content

Commit

Permalink
ruby library client is not Redis-rb merged with RubyRedis "engine" by…
Browse files Browse the repository at this point in the history
… Brian McKinney
  • Loading branch information
antirez committed May 29, 2009
1 parent d90b352 commit 6966413
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 1,054 deletions.
19 changes: 13 additions & 6 deletions client-libraries/ruby/lib/dist_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
require 'hash_ring'
class DistRedis
attr_reader :ring
def initialize(*servers)
srvs = []
servers.each do |s|
server, port = s.split(':')
srvs << Redis.new(:host => server, :port => port)
def initialize(opts={})
hosts = []

db = opts[:db] || nil
timeout = opts[:timeout] || nil

raise Error, "No hosts given" unless opts[:hosts]

opts[:hosts].each do |h|
host, port = h.split(':')
hosts << Redis.new(:host => host, :port => port, :db => db, :timeout => timeout, :db => db)
end
@ring = HashRing.new srvs

@ring = HashRing.new hosts
end

def node_for_key(key)
Expand Down
18 changes: 6 additions & 12 deletions client-libraries/ruby/lib/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ def initialize(redis)
@redis = redis
@commands = []
end

def execute_command(data)
@commands << data
write_and_read if @commands.size >= BUFFER_SIZE
end

def finish
write_and_read

def call_command(command)
@commands << command
end

def write_and_read
@redis.execute_command(@commands.join, true)
@redis.read_socket

def execute
@redis.call_command(@commands)
@commands.clear
end

Expand Down
Loading

0 comments on commit 6966413

Please sign in to comment.