On Wed, Mar 13, 2013 at 5:13 PM, Readis <
winson...@gmail.com> wrote:
> Hi,
>
> Since Redis always caches the script been run forever to allow evalsha, one
> concern I have is that there may be an accidental growth of memory usages
> caching them.
If the total volume of the code you generate is comparable to the size
of your data, I would suggest that you might be doing it wrong.
> For example, one may generate a Lua script to send it to the server, like
>
>> argv = []
>> lua = "...; if .. then /* some atomic/transactional and condition
>> checking operations */";
>> i = 1;
>> for (entry in list of data) {
>> argv << entry.value
>> lua += "redis.call('lpush', 'datalist', ARGV[#{i}]); " // ARGV[1],
>> ARGV[2], ...
>> }
>>
>> lua += "end;";
>>
>> redis.eval(lua, argv);
>>
> Once such a script is run against a large data set, it would be cached
> permanently. There is no way to opt-out even if we never use evalsha.
Might I suggest that you instead implement individual functions that
can test a given class of pre-conditions, load them into Redis with
'script load', then *call* them *within* Redis via f_<sha>(...)
(thanks to Fritzy
http://redisconf.com/video/nathan-fritz, jump to 9
minutes in). You may also be able to use redis.call('evalsha', <sha>,
...), but test it.
That would let you pass a list of attributes/data to validate against,
which you can then test within Redis, *without* needing code
generation.
> I think a more prudent approach would be to allow a setting for limited
> script cache and the codes can always do a fallback
>
> try {
> redis.evalsha(myScriptSHA)
> catch (e) {
> if (e.message ~= /No such SHA) // there should be some fixed error
> symbol instead of message text
> redis.eval(myScript)
> }
>
> This can be a DB setting default to unlimited so it will be backward
> compatible.
You can also clear the cache at any time with "SCRIPT FLUSH" if the
INFO output for used_memory_lua is too high, if you find the alternate
methods I offered to be insufficient. Given the fallback method you
offered (which everyone uses, as far as I can tell, though the first
pass usually includes a 'script load' to cache the sha), this is
likely the quickest and easiest way for you to address your own issue
without relying on Salvatore to change Redis.
Regards,
- Josiah