Class: TableStore
- Inherits:
-
Object
- Object
- TableStore
- 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 Method Summary collapse
- #_batch_get_row(request) ⇒ Object
- #_batch_write_row(request) ⇒ Object
- #_get_range(request) ⇒ Object
- #_get_row(table_name, primary_key, columns_to_get = nil, column_filter = nil, max_version = 1) ⇒ Object
- #_put_row(table_name, row, condition) ⇒ Object
-
#initialize(end_point, access_key_id, access_key_secret, instance_name, **kwargs) ⇒ TableStore
constructor
A new instance of TableStore.
Constructor Details
#initialize(end_point, access_key_id, access_key_secret, instance_name, **kwargs) ⇒ TableStore
Returns a new instance of TableStore.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tablestore-ruby-sdk.rb', line 15 def initialize(end_point, 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') #示例:创建一个TableStoreClient实例 # from tablestore.client import TableStoreClient # client = TableStoreClient('your_instance_endpoint', 'your_user_id', 'your_user_key', 'your_instance_name') end |
Instance Method Details
#_batch_get_row(request) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/tablestore-ruby-sdk.rb', line 59 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
66 67 68 69 70 71 72 73 |
# File 'lib/tablestore-ruby-sdk.rb', line 66 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
36 37 38 39 40 41 |
# File 'lib/tablestore-ruby-sdk.rb', line 36 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
52 53 54 55 56 57 |
# File 'lib/tablestore-ruby-sdk.rb', line 52 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
43 44 45 46 47 48 49 50 |
# File 'lib/tablestore-ruby-sdk.rb', line 43 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 |