Skip to content

Commit 12f45ee

Browse files
authored
Removing duplication of Script class (#1751)
1 parent 884f7ad commit 12f45ee

File tree

1 file changed

+0
-36
lines changed

1 file changed

+0
-36
lines changed

redis/client.py

-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from itertools import chain
22
import copy
33
import datetime
4-
import hashlib
54
import re
65
import threading
76
import time
@@ -15,7 +14,6 @@
1514
ConnectionError,
1615
ExecAbortError,
1716
ModuleError,
18-
NoScriptError,
1917
PubSubError,
2018
RedisError,
2119
ResponseError,
@@ -1896,37 +1894,3 @@ def watch(self, *names):
18961894
def unwatch(self):
18971895
"Unwatches all previously specified keys"
18981896
return self.watching and self.execute_command('UNWATCH') or True
1899-
1900-
1901-
class Script:
1902-
"An executable Lua script object returned by ``register_script``"
1903-
1904-
def __init__(self, registered_client, script):
1905-
self.registered_client = registered_client
1906-
self.script = script
1907-
# Precalculate and store the SHA1 hex digest of the script.
1908-
1909-
if isinstance(script, str):
1910-
# We need the encoding from the client in order to generate an
1911-
# accurate byte representation of the script
1912-
encoder = registered_client.connection_pool.get_encoder()
1913-
script = encoder.encode(script)
1914-
self.sha = hashlib.sha1(script).hexdigest()
1915-
1916-
def __call__(self, keys=[], args=[], client=None):
1917-
"Execute the script, passing any required ``args``"
1918-
if client is None:
1919-
client = self.registered_client
1920-
args = tuple(keys) + tuple(args)
1921-
# make sure the Redis server knows about the script
1922-
if isinstance(client, Pipeline):
1923-
# Make sure the pipeline can register the script before executing.
1924-
client.scripts.add(self)
1925-
try:
1926-
return client.evalsha(self.sha, len(keys), *args)
1927-
except NoScriptError:
1928-
# Maybe the client is pointed to a different server than the client
1929-
# that created this instance?
1930-
# Overwrite the sha just in case there was a discrepancy.
1931-
self.sha = client.script_load(self.script)
1932-
return client.evalsha(self.sha, len(keys), *args)

0 commit comments

Comments
 (0)