summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Greenberg <bgreenberg@eventbrite.com>2017-06-15 12:07:36 -0700
committerBen Greenberg <bgreenberg@eventbrite.com>2017-06-15 12:07:36 -0700
commit94975d310353a656fb12fd68cdd2f2a4ca5ae502 (patch)
treedec3a7c8be93505d5f9838ba837f2d286175f9cd
parentf49f7d27592a5ed1e7f27f032c1e54d646154c89 (diff)
downloadredis-py-94975d310353a656fb12fd68cdd2f2a4ca5ae502.tar.gz
Encode script string before hashing. Remove the "if not script.sha" block from script_load_for_pipeline because its condition will not be true, and because scripts are loaded during execute()
-rwxr-xr-xredis/client.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/redis/client.py b/redis/client.py
index 385579a..1a6beb7 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -2907,13 +2907,7 @@ class BasePipeline(object):
return self.watching and self.execute_command('UNWATCH') or True
def script_load_for_pipeline(self, script):
- "Make sure scripts are loaded prior to pipeline execution"
- # we need the sha now so that Script.__call__ can use it to run
- # evalsha.
- if not script.sha:
- script.sha = self.immediate_execute_command('SCRIPT', 'LOAD',
- script.script,
- **{'parse': 'LOAD'})
+ "Make sure scripts can be loaded prior to pipeline execution"
self.scripts.add(script)
@@ -2933,7 +2927,7 @@ class Script(object):
def __init__(self, registered_client, script):
self.registered_client = registered_client
self.script = script
- self.sha = hashlib.sha1(script).hexdigest()
+ self.sha = hashlib.sha1(script.encode('utf-8')).hexdigest()
def __call__(self, keys=[], args=[], client=None):
"Execute the script, passing any required ``args``"
@@ -2949,5 +2943,6 @@ class Script(object):
except NoScriptError:
# Maybe the client is pointed to a differnet server than the client
# that created this instance?
+ # Overwrite the sha just in case there was a discrepancy
self.sha = client.script_load(self.script)
return client.evalsha(self.sha, len(keys), *args)