diff --git a/README.md b/README.md index 4524884..726de3a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ LedisDB now supports multiple databases as backend to store data, you can test a + Stores lots of data, over the memory limit. + Various backend database to use: LevelDB, goleveldb, LMDB, RocksDB, BoltDB, HyperLevelDB. + Supports transaction using LMDB or BotlDB. ++ Supports lua scripting. + Supports expiration and ttl. + Redis clients, like redis-cli, are supported directly. + Multiple client API supports, including Go, Python, Lua(Openresty), C/C++, Node.js. diff --git a/client/ledis-py/ledis/client.py b/client/ledis-py/ledis/client.py index a083ca6..6c8a9fb 100644 --- a/client/ledis-py/ledis/client.py +++ b/client/ledis-py/ledis/client.py @@ -905,6 +905,21 @@ class Ledis(object): def bscan(self, key, match = "", count = 10): return self.execute_command("BSCAN", key, match, count) + def eval(self, script, keys, *args): + return self.execute_command('EVAL', script, len(keys), *keys, *args) + + def evalsha(self, sha1, keys, *args): + return self.execute_command('EVALSHA', sha1, len(keys), *keys, *args) + + def scriptload(self, script): + return self.execute_command('SCRIPT LOAD', script) + + def scriptexists(self, *args): + return self.execute_command('SCRIPT EXISTS', *args) + + def scriptflush(self): + return self.execute_command('SCRIPT FLUSH') + class Transaction(Ledis): def __init__(self, connection_pool, response_callbacks): self.connection_pool = connection_pool diff --git a/client/ledis-py/tests/test_cmd_script.py b/client/ledis-py/tests/test_cmd_script.py new file mode 100644 index 0000000..b2e2f18 --- /dev/null +++ b/client/ledis-py/tests/test_cmd_script.py @@ -0,0 +1,24 @@ +# coding: utf-8 +# Test Cases for bit commands + +import unittest +import sys +sys.path.append('..') + +import ledis +from ledis._compat import b +from util import expire_at, expire_at_seconds + +l = ledis.Ledis(port=6380) + + +class TestCmdScript(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + + + \ No newline at end of file diff --git a/client/nodejs/ledis/lib/commands.js b/client/nodejs/ledis/lib/commands.js index 696bc7e..26408e2 100644 --- a/client/nodejs/ledis/lib/commands.js +++ b/client/nodejs/ledis/lib/commands.js @@ -129,4 +129,9 @@ module.exports = [ "rollback", "commit", + "eval", + "evalsha", + "script load", + "script exists", + "script flush", ]; diff --git a/client/openresty/ledis.lua b/client/openresty/ledis.lua index a25319e..2778a56 100644 --- a/client/openresty/ledis.lua +++ b/client/openresty/ledis.lua @@ -151,7 +151,14 @@ local commands = { -- [[transaction]] "begin", "commit", - "rollback" + "rollback", + + -- [[script]] + "eval", + "evalsha", + "script load", + "script exists", + "script flush" } diff --git a/cmd/ledis-cli/const.go b/cmd/ledis-cli/const.go index 48b78aa..9560c44 100644 --- a/cmd/ledis-cli/const.go +++ b/cmd/ledis-cli/const.go @@ -1,4 +1,4 @@ -//This file was generated by .tools/generate_commands.py on Wed Aug 27 2014 11:14:50 +0800 +//This file was generated by .tools/generate_commands.py on Tue Sep 02 2014 22:27:45 +0800 package main var helpCommands = [][]string{ @@ -20,6 +20,8 @@ var helpCommands = [][]string{ {"DECRBY", "key decrement", "KV"}, {"DEL", "key [key ...]", "KV"}, {"ECHO", "message", "Server"}, + {"EVAL", "script numkeys key [key ...] arg [arg ...]", "Script"}, + {"EVALSHA", "sha1 numkeys key [key ...] arg [arg ...]", "Script"}, {"EXISTS", "key", "KV"}, {"EXPIRE", "key seconds", "KV"}, {"EXPIREAT", "key timestamp", "KV"}, @@ -72,6 +74,9 @@ var helpCommands = [][]string{ {"SCAN", "key [MATCH match] [COUNT count]", "KV"}, {"SCARD", "key", "Set"}, {"SCLEAR", "key", "Set"}, + {"SCRIPT EXISTS", "script [script ...]", "Script"}, + {"SCRIPT FLUSH", "-", "Script"}, + {"SCRIPT LOAD", "script", "Script"}, {"SDIFF", "key [key ...]", "Set"}, {"SDIFFSTORE", "destination key [key ...]", "Set"}, {"SELECT", "index", "Server"}, diff --git a/doc/commands.json b/doc/commands.json index e6ad2e2..370d588 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -580,5 +580,36 @@ "arguments": "[section]", "group": "Server", "readonly": true + }, + + "EVAL": { + "arguments": "script numkeys key [key ...] arg [arg ...]", + "group": "Script", + "readonly": false + }, + + "EVALSHA": { + "arguments": "sha1 numkeys key [key ...] arg [arg ...]", + "group": "Script", + "readonly": false + }, + + "SCRIPT LOAD": { + "arguments": "script", + "group": "Script", + "readonly": false + }, + + "SCRIPT EXISTS": { + "arguments": "script [script ...]", + "group": "Script", + "readonly": false + }, + + "SCRIPT FLUSH": { + "arguments" : "-", + "group": "Script", + "readonly": false } + } diff --git a/doc/commands.md b/doc/commands.md index fe5437f..d3c3b39 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -70,7 +70,7 @@ Table of Contents - [SINTERSTORE destination key [key ...]](#sinterstore-destination-key-key-) - [SISMEMBER key member](#sismember-key-member) - [SMEMBERS key](#smembers-key) - - [SREM key member [member]](#srem-key-member-member-) + - [SREM key member [member ...]](#srem-key-member-member-) - [SUNION key [key ...]](#sunion-key-key-) - [SUNIONSTORE destination key [key ...]](#sunionstore-destination-key-key-) - [SCLEAR key](#sclear-key) @@ -133,7 +133,12 @@ Table of Contents - [BEGIN](#begin) - [ROLLBACK](#rollback) - [COMMIT](#commit) - +- [Script](#script) + - [EVAL script numkeys key [key ...] arg [arg ...]](#eval-script-numkeys-key-key--arg-arg-) + - [EVALSHA sha1 numkeys key [key ...] arg [arg ...]](#evalsha-sha1-numkeys-key-key--arg-arg-) + - [SCRIPT LOAD script](#script-load-script) + - [SCRIPT EXISTS script [script ...]](#script-exists-script-script-) + - [SCRIPT FLUSH](#script-flush) ## KV @@ -2562,4 +2567,21 @@ ledis> GET HELLO "WORLD" ``` +## Script + +LedisDB's script is refer to Redis, you can see more [http://redis.io/commands/eval](http://redis.io/commands/eval) + +You must notice that executing lua will block any other write operations. + +### EVAL script numkeys key [key ...] arg [arg ...] + +### EVALSHA sha1 numkeys key [key ...] arg [arg ...] + +### SCRIPT LOAD script + +### SCRIPT EXISTS script [script ...] + +### SCRIPT FLUSH + + Thanks [doctoc](http://doctoc.herokuapp.com/)