Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait_until_loaded option #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/Redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sub new {
and $self->{$_} = $args{$_} for
qw(password on_connect name no_auto_connect_on_new cnx_timeout
write_timeout read_timeout sentinels_cnx_timeout sentinels_write_timeout
sentinels_read_timeout no_sentinels_list_update);
sentinels_read_timeout no_sentinels_list_update wait_until_loaded);

$self->{reconnect} = $args{reconnect} || 0;
$self->{every} = $args{every} || 1000;
Expand Down Expand Up @@ -612,6 +612,15 @@ sub __build_sock {
};
}

## WIP: not sure if we need to do this before AUTH above...
## It all depends if AUTH also returns LOADING (theoretically, there
## is no need, password is configuration, not DB)
if ($self->{wait_until_loaded}) {
local $@;
require Time::HiRes;
while ( !eval{ $self->exists("42"); 1 } && $@ =~ m/LOADING/ ) { Time::HiRes::usleep(100_000); }
}

$self->__on_connection;

return;
Expand Down Expand Up @@ -1161,6 +1170,16 @@ successful connection. The C<< on_connect >> attribute is used to provide the
code reference, and it will be called with the first parameter being the Redis
object.

If the Redis server has just started, it will not be available to
execute your commands until it ends loading the database snapshot from
disk into memory. On those situations, most commands will return an error.
You can use the option C<< wait_until_loaded >> to force Redis.pm to not
return from connect until the server has finished loading.

Note: for now, due to the lack of support form the redis-server to wait
until the DB is loaded, this command is implemented using a test-sleep-loop,
wasting your CPU.

You can also provide C<< no_auto_connect_on_new >> in which case C<<
new >> won't call C<< $obj->connect >> for you implicitly, you'll have
to do that yourself. This is useful for figuring out how long
Expand Down