Skip to content

Commit

Permalink
propery encode the script before getting the sha1 value
Browse files Browse the repository at this point in the history
it's possible a Lua script contains unicode characters. use the
client's encoding options to obtain the byte representation of
the script.
  • Loading branch information
andymccurdy committed Jul 31, 2017
1 parent 3497d8f commit 29a7ece
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2934,7 +2934,15 @@ def __init__(self, registered_client, script):
self.registered_client = registered_client
self.script = script
# Precalculate and store the SHA1 hex digest of the script.
self.sha = hashlib.sha1(b(script)).hexdigest()

if isinstance(script, basestring):
# We need the encoding from the client in order to generate an
# accurate byte representation of the script
encoding_options = registered_client.connection_pool.get_encoding()
encoding = encoding_options['encoding']
encoding_errors = encoding_options['encoding_errors']
script = script.encode(encoding, encoding_errors)
self.sha = hashlib.sha1(script).hexdigest()

def __call__(self, keys=[], args=[], client=None):
"Execute the script, passing any required ``args``"
Expand Down

0 comments on commit 29a7ece

Please sign in to comment.