Class: TableStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tablestore-ruby-sdk.rb

Constant Summary collapse

DEFAULT_ENCODING =
'utf8'
DEFAULT_SOCKET_TIMEOUT =
50
DEFAULT_MAX_CONNECTION =
50
DEFAULT_LOGGER_NAME =
'tablestore-client'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, access_key_id, access_key_secret, instance_name, **kwargs) ⇒ TableStore



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tablestore-ruby-sdk.rb', line 16

def initialize(base_url, access_key_id, access_key_secret, instance_name, **kwargs)
  # 初始化TableStoreClient实例。
  # end_point是TableStoreClient服务的地址(例如 'http://instance.cn-hangzhou.TableStoreClient.aliyun.com'),必须以'http://'或'https://'开头。
  # access_key_id是访问TableStoreClient服务的accessid,通过官方网站申请或通过管理员获取。
  # access_key_secret是访问TableStoreClient服务的accesskey,通过官方网站申请或通过管理员获取。
  # instance_name是要访问的实例名,通过官方网站控制台创建或通过管理员获取。
  # sts_token是访问TableStoreClient服务的STS token,从STS服务获取,具有有效期,过期后需要重新获取。
  # encoding请求参数的字符串编码类型,默认是utf8。
  # socket_timeout是连接池中每个连接的Socket超时,单位为秒,可以为int或float。默认值为50。
  # max_connection是连接池的最大连接数。默认为50,
  # logger_name用来在请求中打DEBUG日志,或者在出错时打ERROR日志。
  # retry_policy定义了重试策略,默认的重试策略为 DefaultRetryPolicy。你可以继承 RetryPolicy 来实现自己的重试策略,请参考 DefaultRetryPolicy 的代码。

  #self.validate_parameter(end_point, access_key_id, access_key_secret, instance_name)
  #sts_token = kwargs.get('sts_token')

  self.base_url            = base_url
  self.access_key_id       = access_key_id
  self.access_key_secret   = access_key_secret
  self.instance_name       = instance_name

  #示例:创建一个TableStoreClient实例
  # from tablestore.client import TableStoreClient
  # client = TableStoreClient('your_instance_endpoint', 'your_user_id', 'your_user_key', 'your_instance_name')
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def access_key_id
  @access_key_id
end

#access_key_secretObject

Returns the value of attribute access_key_secret.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def access_key_secret
  @access_key_secret
end

#base_urlObject

Returns the value of attribute base_url.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def base_url
  @base_url
end

#instance_nameObject

Returns the value of attribute instance_name.



14
15
16
# File 'lib/tablestore-ruby-sdk.rb', line 14

def instance_name
  @instance_name
end

Instance Method Details

#_batch_get_row(request) ⇒ Object



74
75
76
77
78
79
# File 'lib/tablestore-ruby-sdk.rb', line 74

def _batch_get_row(request)
  api_name = 'BatchGetRow'
  body = TableStoreClient.new.make_batch_get_row(request)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_batch_get_row(response.body)
end

#_batch_write_row(request) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/tablestore-ruby-sdk.rb', line 81

def _batch_write_row(request)
  api_name = 'BatchWriteRow'
  body = TableStoreClient.new.make_batch_write_row(request)
  response = post_request(body, api_name)
  if response.code == 200
    'write succeed!'
  end
end

#_get_range(request) ⇒ Object



42
43
44
45
46
47
# File 'lib/tablestore-ruby-sdk.rb', line 42

def _get_range(request)
  api_name = 'GetRange'
  body = TableStoreClient.new.encode_get_range_request(request)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_get_range_request(api_name, response.headers, response.body)
end

#_get_row(table_name, primary_key, columns_to_get = nil, column_filter = nil, max_version = 1) ⇒ Object



58
59
60
61
62
63
# File 'lib/tablestore-ruby-sdk.rb', line 58

def _get_row(table_name, primary_key, columns_to_get=nil, column_filter=nil, max_version=1)
  api_name = 'GetRow'
  body = TableStoreClient.new.encode_get_row(table_name, primary_key, columns_to_get, column_filter, max_version)
  response = post_request(body, api_name)
  TableStoreClient.new.decode_get_row(response.body)
end

#_put_row(table_name, row, condition) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/tablestore-ruby-sdk.rb', line 49

def _put_row(table_name, row, condition)
  api_name = 'PutRow'
  body = TableStoreClient.new.encode_put_row(table_name, row, condition)
  response = post_request(body, api_name)
  if response.code == 200
    'write succeed!'
  end
end

#_update_row(table_name, row, condition) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/tablestore-ruby-sdk.rb', line 65

def _update_row(table_name, row, condition)
  api_name = 'UpdateRow'
  body = TableStoreClient.new.encode_update_row(table_name, row, condition)
  response = post_request(body, api_name)
  if response.code == 200
    'update succeed!'
  end
end