Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noteflakes/led
Redis Lua scripting using Ruby
https://github.com/noteflakes/led
Last synced: 28 days ago
JSON representation
Redis Lua scripting using Ruby
- Host: GitHub
- URL: https://github.com/noteflakes/led
- Owner: noteflakes
- Created: 2012-08-06T07:01:17.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-07-04T13:14:02.000Z (over 11 years ago)
- Last Synced: 2024-09-17T18:35:53.932Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 148 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Easy Lua scripting for Redis
============================Led makes managing Redis Lua scripts simple and easy. Features:
## Installing
```
gem install led
```## How to use it
### Install scripts as Ruby methods:
```ruby
Led.add_script(:add, 'return tonumber(ARGV[1])+tonumber(ARGV[2])')
Led.add(12, 34) # => 46
```### String interpolation for lua:
```ruby
Led.add_script(:interpolate, 'return "abc_#{ARGV[1]}"')
Led.interpolate('def') # => "abc_def"
```### Shorthand for redis calls:
```ruby
Led.add_script(:set, 'SET(ARGV[1], ARGV[2])') # silly example, I know
# same as redis.call('set', ARGV[1], ARGV[2])
```
### Reuse code by using includes:```lua
-- helpers.lua
local function add(x, y)
return x + y
end
``````lua
-- test.lua
__include 'helpers'
return add(ARGV[1], ARGV[2])
``````ruby
Led.script_dir = '.'
# once the script dir is set, scripts files are loaded automatically.
Led.test(1, 2) # => 3
```