Re-adding the Redis mailing list.
On Mon, Nov 5, 2012 at 3:36 PM, Ariel Weisberg <
arielw...@gmail.com> wrote:
> Hi,
>
> Looks like I didn't include the group in my comment?
>
> Ah, I just read the excellent documentation that describes how expiration is
> implemented.
>
> The time returned from within a Lua script doesn't change right? As a user I
> would expect all keys to be expired before/after script execution and not
> during since time is "frozen".
There is nothing that stops time from progressing inside Redis while a
script is executing, and you don't need to call any time functions to
tickle the edge-case.
Imagine for a moment that you have a script that takes a variable
amount of time to execute, based on the performance of a server. Maybe
something related to a large union operation over a large number of
sets or sorted sets. If you are using key expiration in the wrong way,
you could end up with inconsistent data on your servers. As an
example, you can see different results from a master and slave of
different performance capabilities with the following:
redis.call('psetex', KEYS[1], ARGV[1], ARGV[2])
local i = 0
while redis.call('get', KEYS[1]) ~= '' do
i = i + 1
end
redis.call('set', KEYS[1], i)
return i
Call the above with...
EVAL ... 1 foo 1 bar
Depending on the performance of your server, the destination key will
have a different number.
About the only advice I can give dealing with expirations of this
nature is "don't do that".
Then again, this does offer an opportunity to create timers based on
Redis expiration, but that is a *really* bad idea.
> If a script is running any keys you set cannot be expired when the script
> executes at a replica because the time of the script by definition precedes
> the expiration time. If a key expires on access the script will never see
> the key and the result is the same at the replicas because the script runs
> with the same timestamp everywhere.
Time doesn't pause, so your premise is incorrect.
> Or do the replicas not contain the same timestamp as the master?
That too.
Regards,
- Josiah
> On Mon, Nov 5, 2012 at 4:01 PM, Josiah Carlson <
josiah....@gmail.com>
> wrote:
>>
>> Expiration is typically executed on the master with DEL during random
>> expiration or when a key that should be expired is accessed (the DEL
>> is syndicated to slaves).
>>
>> In the middle of a script, you can't really inject a DEL (because you
>> are executing a script and not individual commands), and injecting a
>> delete before the script begins execution doesn't work because you can
>> set a key with expiration.
>>
>> - Josiah
>>
>> On Mon, Nov 5, 2012 at 11:51 AM, Ariel Weisberg <
arielw...@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > You can make operations against keys with expiration deterministic by
>> > having
>> > the master manage key expiration.
>> >
>> > As long as all mutations are sequenced by the master and its replication
>> > stream you don't have to worry about asynchronous events like
>> > expiration.
>> > The tradeoff is that slaves have to maintain enough state and behavior
>> > to
>> > correctly resume where the master leaves off which means two code paths
>> > instead of one.
>> >
>> > Regards,
>> > Ariel