Skip to content

Commit

Permalink
Merge pull request #281 from tom-binary/bugfix/config_keyspace_notifi…
Browse files Browse the repository at this point in the history
…cations

Fix Redis keyspace notifications for Myriad::Config
  • Loading branch information
tom-binary committed Mar 27, 2023
2 parents c0203d6 + 49718f3 commit 010160b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Revision history for {{$dist->name}}
to load and use the XS versions for better performance
- Future::AsyncAwait::Hooks now available (for suspend/resume blocks) when using `:v2`

[Bugs fixed]
- handle keyspace notifications properly for config changes in Redis

1.001 2022-11-11 09:42:07+08:00 Asia/Singapore
[Bugs fixed]
- Latest Future (and Future::XS) were failing tests due to `Future->needs_all`
Expand Down
4 changes: 2 additions & 2 deletions lib/Myriad/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ async method listen_for_updates () {
})->resolve->completed->retain->on_fail(sub {
$log->warnf('Config: config updates listener failed - %s', shift);
});
} catch {
$log->trace('Config: transport does not support keyspace notifications');
} catch ($e) {
$log->tracef('Config: transport does not support keyspace notifications: %s', $e);
}
} else {
$log->warn('Config: Storage is not initiated, cannot listen to config updates');
Expand Down
36 changes: 15 additions & 21 deletions lib/Myriad/Transport/Redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -733,28 +733,22 @@ async method zrange ($k, @v) {
}

async method watch_keyspace($pattern) {
my $sub;
if ($clientside_cache_size) {
# Net::Async::Redis will handl the connection in this case
$sub = $redis->clientside_cache_events->map(sub {
$_ =~ s/$prefix\.//;
return $_;
});
} else {
# Keyspace notification is a psubscribe
my $instance = await $self->borrow_instance_from_pool;
$sub = await $instance->watch_keyspace($self->apply_prefix($pattern));

$sub = $sub->events->map(sub {
$_->{channel} =~ s/__key.*:$prefix\.//;
return $_->{channel};
});

$sub->on_ready(sub {
$self->return_instance_to_pool($instance);
});
}
# Net::Async::Redis will handl the connection in this case
return $redis->clientside_cache_events->map(sub {
return s/^$prefix\.//r;
}) if $clientside_cache_size;

# Keyspace notification is a psubscribe
my $instance = await $self->borrow_instance_from_pool;
my $sub = (await $instance->watch_keyspace(
$self->apply_prefix($pattern)
))->map(sub {
my $chan = $_->{channel} =~ s/__key.*:$prefix\.//r;
return $chan;
});
$sub->on_ready($self->$curry::weak(sub {
shift->return_instance_to_pool($instance);
}));
return $sub;
}

Expand Down

0 comments on commit 010160b

Please sign in to comment.