Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripting with mruby #848

Closed
wants to merge 34 commits into from
Closed

scripting with mruby #848

wants to merge 34 commits into from

Conversation

tricknotes
Copy link

We have created a command REVAL to use mruby for scripting of Redis.

mruby is the lightweight implementation of the Ruby language complying to (part of) the ISO standard.
Ruby is good at processing strings, arrays, hashes, etc. with its pretty designed libraries.
With mruby, we can do complex data operations in Redis with simple scripts.

How do you think about this idea?
As this patch is still rough cutting, some works will be needed to fit with Redis.
(For example REVALSHA is not implemented. Not implemented features are listed later.)

If your feel positive about implementing scripting languages in Redis other than Lua, we would like to consider supporting JavaScript with v8.
JavaScript runs on both client-side and server-side.
If Redis supports JavaScript, we can write everything in JavaScript.

The usage of REVAL is as follows:


REVAL script numkeys key [key ...] arg [arg …]

Features

Run mruby in the context of Redis server.

> reval "[KEYS[0],KEYS[1],ARGV[0],ARGV[1]]" 2 key1 key2 first second
1) "key1"
2) "key2"
3) "first"
4) "second"

Call Redis commands from a mruby script. (same as EVAL command)

> reval "REDIS.call('set','foo','bar')" 0
OK

Conversion between mruby and Redis data types

Redis to mruby conversion table.

  • Redis integer reply -> mruby Integer
  • Redis bulk reply -> mruby String
  • Redis multi bulk reply -> mruby Array
  • Redis error reply -> mruby Exception
  • Redis Nil bulk reply and Nil multi bulk reply -> mruby nil

mruby to Redis conversion table.

  • mruby Integer -> Redis integer reply (the number is converted into an integer)
  • mruby String -> Redis bulk reply
  • mruby Array -> Redis multi bulk reply (truncated to the first nil inside the mruby array if any)
  • mruby Hash with a single ok key -> Redis status reply
  • mruby Hash with a single err key -> Redis error reply
  • mruby Error -> Redis error reply
  • mruby boolean false -> Redis Nil bulk reply
  • mruby boolean true -> Redis integer reply with value of 1.

(examples)

> reval "10" 0
(integer) 10

> reval "[1, 2, [3, 'Hello World!']]" 0
1) (integer) 1
2) (integer) 2
3) 1) (integer) 3
   2) "Hello World!"

> reval "REDIS.call('get', 'foo')" 0
"bar"

Not implemented yet

  • REVALSHA
  • REDIS.log
  • script timeout

@carlzulauf
Copy link

This is an awesome idea 👍

@antirez
Copy link
Contributor

antirez commented May 7, 2013

Hello, thanks for your great effort, but as repeated may times in the past, the scripting will be limited to a single language: Lua. Redis lua scripts are not at the level of complexity where really a language should be different from the other, given that we are talking of similar late-binding very dynamic languages. So adding support for other languages would result in zero practical improvement and great complexity added. Thanks anyway!

@antirez antirez closed this May 7, 2013
maxb-io pushed a commit to maxb-io/redis that referenced this pull request Sep 24, 2024
* Add to JSONPath filter the regexp match operator

* Improve coverage

* Minor cosmetics

* Allow match using regex pattern from a field and add end-to-end test

* Test with numeric combined in filter

* Add more tests and documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants