Module: Tair::Operation

Includes:
Key, Log
Included in:
Client
Defined in:
lib/tair/operation/get.rb,
lib/tair/operation/put.rb,
lib/tair/operation/decr.rb,
lib/tair/operation/incr.rb,
lib/tair/operation/count.rb,
lib/tair/operation/delete.rb,
lib/tair/operation/fetch_data_servers.rb

Instance Method Summary collapse

Methods included from Log

#colorize, included, #log_bytes, #log_time, #logger, #logger_colorize, #tair_bytes_log_file

Methods included from Key

#valid_key?

Instance Method Details

#count(key) ⇒ Object



6
7
8
# File 'lib/tair/operation/count.rb', line 6

def count(key)
  incr(key, 0, op: :count)
end

#decr(key, step = 1) ⇒ Object



6
7
8
# File 'lib/tair/operation/decr.rb', line 6

def decr(key, step=1)
  incr(key, -step, op: :decr)
end

#delete(key) ⇒ Object

TODO: support batch delete FIXME: 某些集群上存在删除失败的bug,需要找时间看一下

Raises:



8
9
10
11
12
13
14
# File 'lib/tair/operation/delete.rb', line 8

def delete(key)
  raise InvalidKeyType unless valid_key?(key)
  req = DelRequest.new(key)
  operate(:delete, req, key: key) do |res|
    DelResponse.new(res).success?
  end
end

#fetch_data_servers(group) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/tair/operation/fetch_data_servers.rb', line 6

def fetch_data_servers(group)
  log_time "fetch_data_nodes" do
    req = FetchDataServerRequest.new(group)
    config_conn.operate(req) do |res|
      # TODO: error processing
      FetchDataServerResponse.new(res).decode
    end
  end
end

#get(key) ⇒ Object Also known as: []

TODO: support batch get

Raises:



9
10
11
12
13
14
15
# File 'lib/tair/operation/get.rb', line 9

def get(key)
  raise InvalidKeyType unless valid_key?(key)
  req = GetRequest.new(key)
  operate(:get, req, key: key) do |res|
    GetResponse.new(res).value
  end
end

#incr(key, step = 1, op: :incr) ⇒ Object Also known as: increase, inc



6
7
8
9
10
11
12
13
14
# File 'lib/tair/operation/incr.rb', line 6

def incr(key, step=1, op: :incr)
  valid_key?(key)         or fail InvalidKeyType.new(key)
  valid_count_step?(step) or fail InvalidCountStep.new(step)

  req = IncrRequest.new(key, step)
  operate(op, req, key: key) do |res|
    IncrResponse.new(res).count
  end
end

#put(key, value) ⇒ Object Also known as: set, []=

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tair/operation/put.rb', line 7

def put(key, value)
  raise InvalidKeyType unless valid_key?(key)

  if value.nil?
    return delete(key)
  end

  req = PutRequest.new({key => value})

  operate(:put, req, key: key) do |res|
    PutResponse.new(res).success?
  end
end

#valid_count_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/tair/operation/incr.rb', line 17

def valid_count_step?(step)
  Fixnum === step
end