https://github.com/michaelmior/locomotor
:bullettrain_front: Automatically translate Redis access in Python :snake: to server side scripts in Lua
https://github.com/michaelmior/locomotor
lua redis stored-procedures
Last synced: 18 days ago
JSON representation
:bullettrain_front: Automatically translate Redis access in Python :snake: to server side scripts in Lua
- Host: GitHub
- URL: https://github.com/michaelmior/locomotor
- Owner: michaelmior
- Created: 2015-11-18T23:01:43.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2021-06-01T23:03:25.000Z (almost 4 years ago)
- Last Synced: 2025-04-15T04:13:28.806Z (18 days ago)
- Topics: lua, redis, stored-procedures
- Language: Python
- Homepage: https://michaelmior.github.io/locomotor/
- Size: 1.37 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Locomotor
[](https://travis-ci.org/michaelmior/locomotor)
Locomotor aims to automatically translate Python code which makes requests to a [Redis](https://redis.io/) server into equivalent [Lua](https://www.lua.org/) code which is executed using the [EVAL](https://redis.io/commands/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.```python
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`](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.