Skip to content

Add generate_sync method to tarantool.Connection class #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tarantool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)


def connect(host="localhost", port=33013):
def connect(host="localhost", port=33013, user=None, password=None):
'''\
Create a connection to the Tarantool server.

Expand All @@ -37,6 +37,8 @@ def connect(host="localhost", port=33013):
'''

return Connection(host, port,
user=user,
password=password,
socket_timeout=SOCKET_TIMEOUT,
reconnect_max_attempts=RECONNECT_MAX_ATTEMPTS,
reconnect_delay=RECONNECT_DELAY,
Expand Down
6 changes: 6 additions & 0 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,9 @@ def space(self, space_name):
:rtype: `Space` instance
'''
return Space(self, space_name)

def generate_sync(self):
"""\
Need override for async io connection
"""
return 0
20 changes: 16 additions & 4 deletions tarantool/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,27 @@ class Request(object):
def __init__(self, conn):
self._bytes = None
self.conn = conn
self._sync = None

def __bytes__(self):
return self._bytes
__str__ = __bytes__

@classmethod
def header(cls, length):
header = msgpack.dumps({ IPROTO_CODE : cls.request_type,
IPROTO_SYNC : 0})
@property
def sync(self):
'''\
:type: int

Required field in the server request.
Contains request header IPROTO_SYNC.
'''
return self._sync

def header(self, length):
self._sync = self.conn.generate_sync()
header = msgpack.dumps({IPROTO_CODE: self.request_type,
IPROTO_SYNC: self._sync})

return msgpack.dumps(length + len(header)) + header

class RequestInsert(Request):
Expand Down
10 changes: 10 additions & 0 deletions tarantool/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def code(self):
'''
return self._code

@property
def sync(self):
'''\
:type: int

Required field in the server response.
Contains response header IPROTO_SYNC.
'''
return self._sync

@property
def return_code(self):
'''\
Expand Down