Skip to content

Commit

Permalink
Python3 client support binary write (apache#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smityz committed Apr 14, 2021
1 parent 61007fc commit f8e5d0b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 88 deletions.
15 changes: 4 additions & 11 deletions pypegasus/base/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions pypegasus/pgclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def update_cfg(self, resp):

def get_hash_key_pid(self, hash_key):
if six.PY3 and isinstance(hash_key, six.string_types):
hash_key = hash_key.encode("utf8")
hash_key = hash_key.encode("UTF-8")
hash_value = PegasusHash.default_hash(hash_key)
pidx = hash_value % self.get_partition_count()
return gpid(self.app_id, pidx)
Expand Down Expand Up @@ -552,9 +552,9 @@ class Pegasus(object):
def generate_key(cls, hash_key, sort_key):
# assert(len(hash_key) < sys.maxsize > 1)
if six.PY3 and isinstance(hash_key, six.string_types):
hash_key = hash_key.encode("utf8")
hash_key = hash_key.encode("UTF-8")
if six.PY3 and isinstance(sort_key, six.string_types):
sort_key = sort_key.encode("utf8")
sort_key = sort_key.encode("UTF-8")

# hash_key_len is in big endian
hash_key_len = len(hash_key)
Expand Down Expand Up @@ -663,8 +663,8 @@ def ttl(self, hash_key, sort_key, timeout=0):
"""
Get ttl(time to live) of the data.
:param hash_key: (str) which hash key used for this API.
:param sort_key: (str) which sort key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sort_key: (bytes) which sort key used for this API.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
else the timeout value specified to create the instance will be used.
Expand All @@ -685,8 +685,8 @@ def exist(self, hash_key, sort_key, timeout=0):
"""
Check value exist.
:param hash_key: (str) which hash key used for this API.
:param sort_key: (str) which sort key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sort_key: (bytes) which sort key used for this API.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
else the timeout value specified to create the instance will be used.
Expand All @@ -700,12 +700,12 @@ def get(self, hash_key, sort_key, timeout=0):
"""
Get value stored in <hash_key, sort_key>.
:param hash_key: (str) which hash key used for this API.
:param sort_key: (str) which sort key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sort_key: (bytes) which sort key used for this API.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
else the timeout value specified to create the instance will be used.
:return: (tuple<error_types.code.value, str>) (code, value).
:return: (tuple<error_types.code.value, bytes>) (code, value).
code: error_types.ERR_OK.value when data got succeed, error_types.ERR_OBJECT_NOT_FOUND.value when data not found.
value: data stored in this <hash_key, sort_key>
"""
Expand All @@ -722,9 +722,9 @@ def set(self, hash_key, sort_key, value, ttl=0, timeout=0):
"""
Set value to be stored in <hash_key, sort_key>.
:param hash_key: (str) which hash key used for this API.
:param sort_key: (str) which sort key used for this API.
:param value: (str) value to be stored under <hash_key, sort_key>.
:param hash_key: (bytes) which hash key used for this API.
:param sort_key: (bytes) which sort key used for this API.
:param value: (bytes) value to be stored under <hash_key, sort_key>.
:param ttl: (int) ttl(time to live) in seconds of this data.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
Expand All @@ -746,8 +746,8 @@ def remove(self, hash_key, sort_key, timeout=0):
"""
Remove the entire <hash_key, sort_key>-value in pegasus.
:param hash_key: (str) which hash key used for this API.
:param sort_key: (str) which sort key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sort_key: (bytes) which sort key used for this API.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
else the timeout value specified to create the instance will be used.
Expand All @@ -768,7 +768,7 @@ def sort_key_count(self, hash_key, timeout=0):
"""
Get the total sort key count under the hash_key.
:param hash_key: (str) which hash key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
else the timeout value specified to create the instance will be used.
Expand All @@ -788,7 +788,7 @@ def multi_set(self, hash_key, sortkey_value_dict, ttl=0, timeout=0):
"""
Set multiple sort_keys-values under hash_key to be stored.
:param hash_key: (str) which hash key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sortkey_value_dict: (dict) <sort_key, value> pairs in dict.
:param ttl: (int) ttl(time to live) in seconds of these data.
:param timeout: (int) how long will the operation timeout in milliseconds.
Expand Down Expand Up @@ -818,7 +818,7 @@ def multi_get(self, hash_key,
"""
Get multiple values stored in <hash_key, sortkey> pairs.
:param hash_key: (str) which hash key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sortkey_set: (set) sort keys in set.
:param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit.
:param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit.
Expand Down Expand Up @@ -858,9 +858,9 @@ def multi_get_opt(self, hash_key,
"""
Get multiple values stored in hash_key, and sort key range in [start_sort_key, stop_sort_key) as default.
:param hash_key: (str) which hash key used for this API.
:param start_sort_key: (str) returned k-v pairs is start from start_sort_key.
:param stop_sort_key: (str) returned k-v pairs is stop at stop_sort_key.
:param hash_key: (bytes) which hash key used for this API.
:param start_sort_key: (bytes) returned k-v pairs is start from start_sort_key.
:param stop_sort_key: (bytes) returned k-v pairs is stop at stop_sort_key.
:param multi_get_options: (MultiGetOptions) configurable multi_get options.
:param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit.
:param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit.
Expand Down Expand Up @@ -898,7 +898,7 @@ def get_sort_keys(self, hash_key,
"""
Get multiple sort keys under hash_key.
:param hash_key: (str) which hash key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit.
:param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit.
:param timeout: (int) how long will the operation timeout in milliseconds.
Expand All @@ -916,7 +916,7 @@ def multi_del(self, hash_key, sortkey_set, timeout=0):
"""
Remove multiple entire <hash_key, sort_key>-values in pegasus.
:param hash_key: (str) which hash key used for this API.
:param hash_key: (bytes) which hash key used for this API.
:param sortkey_set: (set) sort keys in set.
:param timeout: (int) how long will the operation timeout in milliseconds.
if timeout > 0, it is a timeout value for current operation,
Expand Down Expand Up @@ -947,9 +947,9 @@ def get_scanner(self, hash_key,
Get scanner for hash_key, start from start_sort_key, and stop at stop_sort_key.
Whether the scanner include the start_sort_key and stop_sort_key is configurable by scan_options
:param hash_key: (str) which hash key used for this API.
:param start_sort_key: (str) returned scanner is start from start_sort_key.
:param stop_sort_key: (str) returned scanner is stop at stop_sort_key.
:param hash_key: (bytes) which hash key used for this API.
:param start_sort_key: (bytes) returned scanner is start from start_sort_key.
:param stop_sort_key: (bytes) returned scanner is stop at stop_sort_key.
:param scan_options: (ScanOptions) configurable scan options.
:return: (PegasusScanner) scanner, instance of PegasusScanner.
"""
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
setup(
name='pypegasus',
version=pypegasus.__version__,
install_requires=['twisted>=17.9.0', 'aenum>=2.0.9', 'thrift>=0.9.3', 'pyopenssl>=17.5.0'],
install_requires=['Twisted==21.2.0', 'aenum==3.0.0', 'thrift==0.13.0', 'pyOpenSSL==20.0.1','cryptography==3.2'],
packages=find_packages(),
package_data={'': ['logger.conf']},
platforms='any',
url='https://github.com/XiaoMi/pegasus-python-client',
license='Apache License 2.0',
author='Lai Yingchun',
author_email='laiyingchun@xiaomi.com',
description='python client for xiaomi/pegasus',
description='python3 client for apache/incubator-pegasus',
classifiers=[
'Development Status :: 4 - Beta',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries'
],
zip_safe=False
Expand Down
Loading

0 comments on commit f8e5d0b

Please sign in to comment.