fiorix/txredisapi — pull request #38 by tpena (2013-01-24 09:37:21+00:00)
Title: Replaced key and argument passing to eval() and evalsha() - use two separate parameters for keys and values instead of dict

This is an API breaking change, but unfortunately, I didn't see a clean way of getting around this. The problem is that the current API to eval() and evalsha() both take a dict containing both the keys and arguments, but this has 1 fundamental flaw: Retrieving the items from a dict is not guaranteed to result in the items being returned in insertion order, but rather random. This is just a fact with most types of hashes unless you explicitly use an ordered dict.

The only clean way I can see of supporting keys and arguments as expected by the script is to have two parameters: keys and args.

Also extended test cases.

As a side note, if you want to check the original test_scripting.py test case, change line 51 from

self._check_eval_result(d, r)

to

self.assertEqual(r, ['key1', 'key2', 'first', 'second'])

and assuming that you are running on cpython, it should break. The _check_eval_result() method is using the dict.items() method to read the values out of the dict - of course, the values are read out in the same way as they were when they were sent to Redis, so the result is the same. However, the result should actually be 'key1', 'key2', 'first', 'second' and not 'key2', 'key1', 'second', 'first' which is what is actually sent.