summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2017-07-31 16:26:52 -0400
committerAndy McCurdy <andy@andymccurdy.com>2017-07-31 16:26:52 -0400
commit29a7ecebd0f4709fc184c6af57c6eb1a59cb071e (patch)
treece0d4aad4017b5afeeaa031762dbbe664c057340
parent3497d8f6804d1fa92689931887a3e18a1cd46b87 (diff)
downloadredis-py-29a7ecebd0f4709fc184c6af57c6eb1a59cb071e.tar.gz
propery encode the script before getting the sha1 value
it's possible a Lua script contains unicode characters. use the client's encoding options to obtain the byte representation of the script.
-rwxr-xr-xredis/client.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py
index 64e9166..b3fff38 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -2934,7 +2934,15 @@ class Script(object):
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``"