102 Commits

Author SHA1 Message Date
antirez
6fe9430644 EVAL errors are more clear now. 2012-04-13 15:12:16 +02:00
antirez
8b54e65163 Use Lua tostring() before concatenation. 2012-04-13 14:54:49 +02:00
antirez
dd17378956 mt.declared is no longer needed.
Lua global protection can now be simpified becuase we no longer have the
global() function. It's useless to occupy memory with this table, it is
also not faster because the metamethods we use are only called when a
global object does not exist or we are trying to create it from a
script.
2012-04-13 13:36:08 +02:00
antirez
c13d275cd0 Stop access to global vars. Not configurable.
After considering the interaction between ability to delcare globals in
scripts using the 'global' function, and the complexities related to
hanlding replication and AOF in a sane way with globals AND ability to
turn protection On and Off, we reconsidered the design. The new design
makes clear that there is only one good way to write Redis scripts, that
is not using globals. In the rare cases state must be retained across
calls a Redis key can be used.
2012-04-13 13:26:59 +02:00
antirez
c498315ec9 Globals protection global() function modified for speed and correctness. 2012-04-13 12:13:02 +02:00
antirez
65a6863cac Scripting: globals protection can now be switched on/off. 2012-04-13 11:23:45 +02:00
antirez
b5fc1508d2 Protect globals access in Lua scripting. 2012-03-29 12:02:28 +02:00
Nathan Fritz
eeb331cd21 added redis.sha1hex(string) as lua scripting function.
(The original implementation was modified by @antirez to conform Redis
coding standards.)
2012-03-28 20:37:40 +02:00
antirez
a15f004026 Support for read-only slaves. Semantical fixes.
This commit introduces support for read only slaves via redis.conf and CONFIG GET/SET commands. Also various semantical fixes are implemented here:

1) MULTI/EXEC with only read commands now work where the server is into a state where writes (or commands increasing memory usage) are not allowed. Before this patch everything inside a transaction would fail in this conditions.

2) Scripts just calling read-only commands will work against read only
slaves, when the server is out of memory, or when persistence is into an
error condition. Before the patch EVAL always failed in this condition.
2012-03-20 17:32:48 +01:00
antirez
1d8a84d4f0 Lua_cmsgpack added to Redis scripting. 2012-02-24 15:45:16 +01:00
lsbardel
35a943766b added lua struct c extension 2012-02-13 21:05:21 +00:00
antirez
67c4a45d53 Now Lua scripts dispatch Redis commands properly calling the call() function. In order to make this possible call() was improved with a new flags argument that controls how the Redis command is executed. 2012-02-02 16:30:52 +01:00
antirez
4a6e6ac8e6 SORT is now more deterministic: does not accept to compare by score items that have scores not representing a valid double. Also items with the same score are compared lexycographically. At the same time the scripting side introduced the ability to sort the output of SORT when sort uses the BY <constant> optimization, resulting in no specific ordering. Since in this case the user may use GET, and the result of GET can be null, converted into false as Lua data type, this commit also introduces the ability to sort Lua tables containining false, only if the first (faster) attempt at using just table.sort with a single argument fails. 2012-02-01 15:22:28 +01:00
antirez
1a786437db Order output of commands returning random arrays using table.sort when called from Lua, partially fixing issue #165. The issue is yet not completely fixed since we can't add the REDIS_CMD_SORT_FOR_SCRIPT flag in SORT currently, both because it may contain NULLs and because it is not cool to re-sort everything at every call when instead this should be sorted only if BY <constant> is used. 2012-01-31 16:09:21 +01:00
Jakub Wieczorek
d64463bd05 Lua reports line numbers off by one in error messages 2012-01-29 14:53:49 +01:00
antirez
194a790664 New script timeout semantics and SCRIPT KILL implemented. SHUTDOWN NOSAVE and SHUTDOWN SAVE implemented. 2011-11-18 14:10:48 +01:00
antirez
2cdb8a7afe If a Lua script executes for more time than the max time specified in the configuration Redis will log a warning, and will start accepting queries (re-entering the event loop), returning -SLOWSCRIPT error for all the commands but SHUTDOWN that remains callable. 2011-10-27 14:49:10 +02:00
antirez
42fc41efb5 Don't timeout scripts if the instance is a slave. 2011-10-25 19:54:10 +02:00
antirez
efd6ecaa17 SCRIPT LOAD now returns the SHA1 instead of +OK 2011-10-25 14:46:15 +02:00
antirez
4ed00fae19 Fixes for the scripting refactoring and new commands. Tests for the new features. 2011-10-25 11:19:15 +02:00
antirez
67a9a651b9 SCRIPT LOAD implemented, scripting eval command refactoring. 2011-10-25 10:25:59 +02:00
antirez
5e56ae9885 SCRIPT command for introspection and control of the scripting environment. 2011-10-24 22:47:00 +02:00
antirez
7a34a833a7 Redis.call is now split into two variants of the same function. Redis.call will raise an error by default. Redis.pcall will return the error object instead. 2011-10-20 16:02:23 +02:00
antirez
db3738932d JSON support for Lua scripting, based on work from @lp, thanks!. We are using the good and fast cjson by Mark Pulford. 2011-10-19 16:42:10 +02:00
antirez
357f49db2f replaced redisAssert() with redisAssertWithInfo() in a shitload of places. 2011-10-04 18:43:03 +02:00
antirez
8f4045ff11 Scripting engine now only loads selected libraries, using code originally contributed by @loopole. 2011-09-27 18:46:23 +02:00
antirez
dec78a35a5 Return errors if a write command is called inside a Lua script after a random command was called. See https://github.com/antirez/redis/issues/95 for more information. 2011-09-27 15:30:31 +02:00
antirez
cd80380f20 Deny commands flagged as REDIS_CMD_NOSCRIPT from Lua scripts 2011-09-27 13:57:10 +02:00
antirez
66b7c21fc7 Lua math.random and math.randomseed replaced with our own version based on redisSrand48(). Seed initialized to the same value at every EVAL/EVALSHA call. 2011-09-23 15:40:58 +02:00
antirez
3aa9917e6e Replicate EVALSHA as EVAL taking a dictionary of sha1 -> script source code. 2011-07-13 15:38:03 +02:00
antirez
cfd32c162f Make sure error and status replies emitted by Lua scripts can never have more than a newline, otherwise it is a protocol violation and clients will desync. 2011-05-25 12:32:50 +02:00
antirez
92aa248ab7 Fix for wrong error level detection in redis.log() 2011-05-25 12:32:50 +02:00
antirez
6e6b7fcc10 All commands exported by Redis to Lua scripts are now inside the redis table. Implemented redis.log() function. 2011-05-25 12:32:50 +02:00
antirez
a044ec4e39 EVALSHA implemented 2011-05-25 12:32:49 +02:00
antirez
a073438a52 Now it is possible to return multi bulks of multi bulks from Lua, just returning tables of tables. The new conversion of the Null bulk and multi bulk type is the Lua false type. 2011-05-25 12:32:49 +02:00
antirez
98af129deb for performance reasons only set the debug hook if the time limit is enabled. 2011-05-25 12:32:49 +02:00
antirez
4f89275a16 Lua max exec time fixes: redisLog() to log the event moved before the lua_error() call that does a long jump so never returns. Aesthetic fixes in error message. 2011-05-25 12:32:49 +02:00
antirez
2ccb8cf33f call the Lua hook with minor frequency. It is already enough to call it every 100000 istructions for near millisecond precision. 2011-05-25 12:32:48 +02:00
antirez
6f6559e47e Lua scripts max execution time 2011-05-25 12:32:48 +02:00
antirez
b37b6f8ce6 call lua_gc() for incremental garbage collection. Likely there is to tune this at some point. 2011-05-25 12:32:48 +02:00
antirez
218852a836 Lua scripting: Honor SELECT command in both ways 2011-05-25 12:32:47 +02:00
antirez
e4c113dc8a Fixed a problem in the script engine that crashed the server if the reply was not stored just int the static buffer of the client structure. 2011-05-25 12:32:47 +02:00
antirez
3993a9a702 Status replies converted in a special way like errors in the Lua <-> Redis conversion code. 2011-05-25 12:32:47 +02:00
antirez
31d3c2fb22 Fixed nul bulk parsing in Redis protocol to Lua type convertion. Check for bad Lua types as arguements of the redis() Lua command. 2011-05-25 12:32:46 +02:00
antirez
ce70f9aba7 Multi bulk to Lua table now working 2011-05-25 12:32:46 +02:00
antirez
3c836ffe5a Fixed arity detection of Redis command executed from Lua script. Error reporting from Lua fixed. More work on the Redis reply to lua conversion code. 2011-05-25 12:32:45 +02:00
antirez
a55dcc3808 full conversion from Lua return value to redis reply. Partial conversion from Redis reply to Lua type. 2011-05-25 12:32:45 +02:00
antirez
4fdcf75a85 pupulate the Lua global tables KEYS and ARGV before executing the script 2011-05-25 12:32:45 +02:00
antirez
d8cdc503e7 function to access to Redis command from Lua renamed from r() to redis() 2011-05-25 12:32:45 +02:00
antirez
2039ac2211 Correctly glue the reply buffer. For now returned as it is to Lua, but will be converted into Lua native type later. 2011-05-25 12:32:44 +02:00