예제 #1
0
파일: listling.py 프로젝트: dnnr/listling
 def users(self, name=''):
     """See :http:get:`/api/lists/(id)/users?name=`."""
     f = script(self.app.r, """\
         local key, name = KEYS[1], string.lower(ARGV[1])
         local users = redis.call("mget", unpack(redis.call("zrange", key, 0, -1)))
         local results = {}
         for _, user in ipairs(users) do
             if string.find(string.lower(cjson.decode(user)["name"]), name, 1, true) then
                 table.insert(results, user)
                 if #results == 10 then
                     break
                 end
             end
         end
         return results
     """)
     # Note that returned users may be duplicates because we parse them directly, skipping the
     # JSONRedis cache
     users = f(['{}.users'.format(self.id)], [name])
     return [User(app=self.app, **json.loads(user.decode())) for user in users]
예제 #2
0
 def test_script_cached(self) -> None:
     f_cached = script(self.r.r, 'return "Meow!"')
     f = script(self.r.r, 'return "Meow!"')
     self.assertIs(f, f_cached)
예제 #3
0
 def test_script(self) -> None:
     f = script(self.r.r, 'return "Meow!"')
     result = expect_type(bytes)(f()).decode()
     self.assertEqual(result, 'Meow!')
예제 #4
0
 def test_script(self) -> None:
     f = script(self.r.r, 'return "Meow!"')
     result = cast(bytes, f()).decode()
     self.assertEqual(result, 'Meow!')