Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/sw/redis++/async_redis_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ class AsyncRedisCluster {

AsyncSubscriber subscriber(const StringView &hash_tag);

template <typename Callback>
void for_each(Callback &&cb) {
assert(_pool);
_pool->update();

auto pools = _pool->pools();
for (auto &pool : pools) {
auto connection = std::make_shared<GuardedAsyncConnection>(pool);

auto ar = AsyncRedis(connection);
cb(ar);
}
}

template <typename Result, typename ...Args>
auto command(const StringView &cmd_name, const StringView &key, Args &&...args)
-> typename std::enable_if<!IsInvocable<typename LastType<Args...>::type,
Expand Down
12 changes: 12 additions & 0 deletions src/sw/redis++/async_shards_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ ConnectionOptions AsyncShardsPool::connection_options() {
return _connection_options(slot);
}

std::vector<AsyncConnectionPoolSPtr> AsyncShardsPool::pools() {
std::lock_guard<std::mutex> lock(_mutex);

std::vector<AsyncConnectionPoolSPtr> nodes;
nodes.reserve(_pools.size());
for (const auto &pool : _pools) {
nodes.push_back(pool.second);
}

return nodes;
}

ConnectionOptions AsyncShardsPool::_connection_options(Slot slot) {
std::lock_guard<std::mutex> lock(_mutex);

Expand Down
2 changes: 2 additions & 0 deletions src/sw/redis++/async_shards_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class AsyncShardsPool {

ConnectionOptions connection_options();

std::vector<AsyncConnectionPoolSPtr> pools();

private:
struct RedeliverEvent {
std::string key;
Expand Down