152 Commits

Author SHA1 Message Date
antirez
6f659f34cf EVAL errors are more clear now. 2012-04-13 15:12:16 +02:00
antirez
3a02140415 Use Lua tostring() before concatenation. 2012-04-13 14:54:49 +02:00
antirez
d86c4a7bf0 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
6663653f51 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
c9edd1b28a Globals protection global() function modified for speed and correctness. 2012-04-13 12:13:02 +02:00
antirez
37b29ef2fa Scripting: globals protection can now be switched on/off. 2012-04-13 11:23:45 +02:00
antirez
0cdecca141 Protect globals access in Lua scripting. 2012-03-29 12:02:28 +02:00
Nathan Fritz
52ae8af807 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
f3fd419fc9 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
63505e0b59 Lua_cmsgpack added to Redis scripting. 2012-02-24 15:45:16 +01:00
lsbardel
2f75bbab02 added lua struct c extension 2012-02-13 21:05:21 +00:00
antirez
ce8b772be7 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
2c861050c1 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
548efd91e5 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
4d776dba3c Lua reports line numbers off by one in error messages 2012-01-29 14:53:49 +01:00
antirez
4ab8695d53 New script timeout semantics and SCRIPT KILL implemented. SHUTDOWN NOSAVE and SHUTDOWN SAVE implemented. 2011-11-18 14:10:48 +01:00
antirez
115e3ff39e 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
e089e61019 Don't timeout scripts if the instance is a slave. 2011-10-25 19:54:10 +02:00
antirez
e5abf6ef19 SCRIPT LOAD now returns the SHA1 instead of +OK 2011-10-25 14:46:15 +02:00
antirez
e8c993f0fb Fixes for the scripting refactoring and new commands. Tests for the new features. 2011-10-25 11:19:15 +02:00
antirez
a9b07ac459 SCRIPT LOAD implemented, scripting eval command refactoring. 2011-10-25 10:25:59 +02:00
antirez
070e39454d SCRIPT command for introspection and control of the scripting environment. 2011-10-24 22:47:00 +02:00
antirez
9ed32ba083 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
15108778d5 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
eab0e26e03 replaced redisAssert() with redisAssertWithInfo() in a shitload of places. 2011-10-04 18:43:03 +02:00
antirez
002d5626e0 Scripting engine now only loads selected libraries, using code originally contributed by @loopole. 2011-09-27 18:46:23 +02:00
antirez
9f772cc237 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
15ef605340 Deny commands flagged as REDIS_CMD_NOSCRIPT from Lua scripts 2011-09-27 13:57:10 +02:00
antirez
e108bab043 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
4dd444bb4a Replicate EVALSHA as EVAL taking a dictionary of sha1 -> script source code. 2011-07-13 15:38:03 +02:00
antirez
3bb818df40 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
e927a24610 Fix for wrong error level detection in redis.log() 2011-05-25 12:32:50 +02:00
antirez
288f811fea 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
7229d60d03 EVALSHA implemented 2011-05-25 12:32:49 +02:00
antirez
82c6b8257a 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
da386cdf33 for performance reasons only set the debug hook if the time limit is enabled. 2011-05-25 12:32:49 +02:00
antirez
87c219243c 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
bcc72bc381 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
eeffcf380f Lua scripts max execution time 2011-05-25 12:32:48 +02:00
antirez
40531be0e3 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
c2a7dd85ae Lua scripting: Honor SELECT command in both ways 2011-05-25 12:32:47 +02:00
antirez
09ab5591fa 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
0d916763af Status replies converted in a special way like errors in the Lua <-> Redis conversion code. 2011-05-25 12:32:47 +02:00
antirez
379789cc52 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
10a6da7af4 Multi bulk to Lua table now working 2011-05-25 12:32:46 +02:00
antirez
3791000f15 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
532e0f5ded 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
4ae5b5e163 pupulate the Lua global tables KEYS and ARGV before executing the script 2011-05-25 12:32:45 +02:00
antirez
00b7541b21 function to access to Redis command from Lua renamed from r() to redis() 2011-05-25 12:32:45 +02:00
antirez
7156f43c04 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