GithubHelp home page GithubHelp logo

isabella232 / curator-3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pombredanne/curator

0.0 0.0 0.0 224 KB

Python helper for working with lua scripts in redis.

License: MIT License

Python 96.58% Lua 3.42%

curator-3's Introduction

Curator

A python helper to make it easier to work with lua scripts in redis.

Inspired by/python port of Shopify's wolverine.

Usage

  1. Ensure you have redis 2.6 or higher installed:
redis-server -v
  1. Install curator:
pip install https://github.com/mhahn/[email protected]
  1. Add your lua scripts to a directory, ie:
-- app/lua_scripts/util/mexists.lua
local exists = {}
local existence
for _, key in ipairs(KEYS) do
  table.insert(exists, redis.call('exists', key))
end
return exists
  1. Configure and call Curator in your code:
from redis import Redis
from curator import Curator

# this should happen when you start your server
curator = Curator(
    package='app',
    scripts_dir='lua_scripts',
    redis_client=Redis(),
)

print curator.util.mexists(keys=['key1', 'key2', 'key3'])
# [0, 1, 0]

Methods are available on curator based on the directory structure of the scripts_dir.

Nested Lua Scripts

For lua scripts with shared code, Curator supports jinja templating.

If your app has lua scripts at

  • app/lua_scripts/do_something.lua
  • app/lua_scripts/do_something_else.lua

that both have shared lua code, you can factor it out into a lua "partial":

  • app/lua_scripts/shared/_common.lua
-- app/lua_scripts/shared/_common.lua
local function complex_redis_command(key, value)
  local dict = {}
  dict[key] = value
end
-- app/lua_scripts/do_something.lua
{% include 'shared/_common.lua' %}
complex_redis_command("foo", "bar")
return true
-- app/lua_scripts/do_something_else.lua
{% include 'shared/_common.lua' %}
complex_redis_command("bar", "baz")
return false
  • partials are loaded relative to the scripts_dir location you instantiate Curator with.

More information

For more information on scripting redis with lua, refer to redis' excellent documentation: http://redis.io/commands/eval

curator-3's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.