Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Commit

Permalink
Check number of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
blfoster committed Feb 12, 2018
1 parent b2b6786 commit fa252bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fakenewsredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ def sort(self, name, start=None, num=None, by=None, get=None, desc=False,
def eval(self, script, numkeys, *keys_and_args):
from lupa import LuaRuntime, LuaError

if numkeys > len(keys_and_args):
raise ResponseError("Number of keys can't be greater than number of args")

This comment has been minimized.

Copy link
@bmerry

bmerry Feb 12, 2018

Also check for less than 0 - I'm guessing Python will wrap it while real redis won't.

lua_runtime = LuaRuntime(unpack_returned_tuples=True)

set_globals = lua_runtime.eval(
Expand Down
4 changes: 4 additions & 0 deletions test_fakenewsredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,10 @@ def test_eval_runtime_error(self):
with self.assertRaises(ResponseError):
self.redis.eval('error("CRASH")', 0)

def test_more_keys_than_args(self):
with self.assertRaises(ResponseError):
self.redis.eval('return 1', 42)

def test_eval_global_variable(self):
# Redis doesn't allow script to define global variables
with self.assertRaises(ResponseError):
Expand Down

0 comments on commit fa252bc

Please sign in to comment.