[go: nahoru, domu]

Skip to content

🚅 Automatically translate Redis access in Python 🐍 to server side scripts in Lua

Notifications You must be signed in to change notification settings

michaelmior/locomotor

Repository files navigation

Locomotor

Build Status

Locomotor aims to automatically translate Python code which makes requests to a Redis server into equivalent Lua code which is executed using the EVAL command. This can result in significants speedups in the case where the code makes multiple requests since it avoids round trips between the server and the client.

Currently some minor work is required on the Python side. First, you should isolate the code which you want to run as a Lua script in a single function where one of the parameters is a connection to the Redis server. Then simply add the annotation @locomotor.redis_server to the function.

from locomotor import redis_server

@redis_server(redis_objs=['redis'])
def get_many(redis, count):
    values = []
    for i in range(count):
        values.append(redis.get('KEY' + str(i)))

    return values

In this case, note that the parameter identifying the Redis server object was manually specified. This is required if the heuristics used by Locomotor can't reliably determine how the server is accessed. See bench/tpcc.py for an example of this determination being done automatically.

There are many limitations on the code which can be translated. Most of these are because certain Python constructs haven't been implemented. If you hit such a case, you'll see an UntranslatableCodeException. Even if the code does appear translate correctly, you'll want to thoroughly test the translated version version.

About

🚅 Automatically translate Redis access in Python 🐍 to server side scripts in Lua

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages