Skip to content

Commit

Permalink
Merge pull request #7 from ContextLogic/binary_type
Browse files Browse the repository at this point in the history
Properly handle binary data types
  • Loading branch information
kahuang authored Oct 5, 2017
2 parents d203836 + ad81e7d commit 93bd42f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tornadoasyncmemcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,17 @@ def _set(self, cmd, key, val, expire, callback, cas=None):
# does. Ideally we should be raising an exception here.
val = six.text_type(val).encode('ascii')

if not isinstance(val, six.binary_type):
data = six.text_type(data).encode('ascii')

extra = ''
if cas is not None:
extra += ' ' + cas

fullcmd = (cmd + b' ' + key + b' ' + six.text_type(flags).encode('ascii') +
b' ' + six.text_type(expire).encode('ascii') +
b' ' + six.text_type(len(val)).encode('ascii') + extra +
b'\r\n' + six.text_type(val).encode('ascii'))
b'\r\n' + val)

response = server.send_cmd(fullcmd, callback=partial(
self._set_send_cb, server=server, callback=callback))
Expand Down

0 comments on commit 93bd42f

Please sign in to comment.