class EventMachine::Protocols::Couchbase::Node
Attributes
admin[R]
client[R]
couch[R]
direct[R]
proxy[R]
status[R]
version[R]
Public Class Methods
connect(options)
click to toggle source
# File lib/em-couchbase/node.rb, line 44 def self.connect(options) host, port = options[:direct].split(':') EventMachine.connect(host, port, self, options) end
new(options = {})
click to toggle source
# File lib/em-couchbase/node.rb, line 35 def initialize(options = {}) @data = "" # naive buffer implementation options.each do |k, v| if respond_to?(k) instance_variable_set("@#{k}", v) end end end
Public Instance Methods
==(other)
click to toggle source
# File lib/em-couchbase/node.rb, line 101 def ==(other) other = Node.new(other) if other.is_a?(Hash) self.class == other.class && self.direct == other.direct && self.couch == other.couch && self.status == other.status end
arithm(opcode, opaque, vbucket, key, options = {})
click to toggle source
# File lib/em-couchbase/node.rb, line 74 def arithm(opcode, opaque, vbucket, key, options = {}) if options.is_a?(Fixnum) options = {:delta => options} end packet = Packet.build(opaque, vbucket, opcode, key, options[:delta], options[:initial], options[:expiration], options[:cas]) client.register_packet(opaque, packet) send_data(packet) end
get(tuples, options = {})
click to toggle source
@param opaque [Fixnum] @param pairs [Array] array of tuples +[opaque, vbucket, key]+ @param options [Hash]
# File lib/em-couchbase/node.rb, line 91 def get(tuples, options = {}) packets = "" tuples.each do |opaque, vbucket, key| packet = Packet.build(opaque, vbucket, :get, key) client.register_packet(opaque, packet) packets << packet end send_data(packets) end
receive_data(data)
click to toggle source
# File lib/em-couchbase/node.rb, line 49 def receive_data(data) @data << data Packet.parse(@data) do |op, opaque, result| if result.error.class == Error::NotMyVbucket client.retry(:not_my_vbucket, opaque) else if op == :sasl_auth raise result.error unless result.success? else client.run_callback(opaque, result) end end end end
set(opaque, vbucket, key, value, options = {})
click to toggle source
# File lib/em-couchbase/node.rb, line 64 def set(opaque, vbucket, key, value, options = {}) packet = Packet.build(opaque, vbucket, :set, key, value, options[:flags], options[:expiration], options[:cas]) client.register_packet(opaque, packet) send_data(packet) end
Protected Instance Methods
authenticate()
click to toggle source
# File lib/em-couchbase/node.rb, line 111 def authenticate if client.config.sasl_password # currently Couchbase supports PLAIN only authentication # this is why it doesn't ask list of mechanisms packet = Packet.build(0, 0, :sasl_auth, "PLAIN", client.config.bucket_name, client.config.sasl_password) send_data(packet) end end
connection_completed()
click to toggle source
# File lib/em-couchbase/node.rb, line 122 def connection_completed authenticate succeed end