From 9e6714e2fae9c4b4cd887734dbdda9fad33af96f Mon Sep 17 00:00:00 2001 From: Honza Kral Date: Wed, 22 May 2013 20:30:38 +0200 Subject: [PATCH] Add a RandomSelector --- elasticsearch/connection_pool.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/elasticsearch/connection_pool.py b/elasticsearch/connection_pool.py index 64bdb13c..c7541e15 100644 --- a/elasticsearch/connection_pool.py +++ b/elasticsearch/connection_pool.py @@ -12,6 +12,14 @@ class ConnectionSelector(object): self.connection_opts = opts +class RandomSelector(ConnectionSelector): + """ + Select a connection at random + """ + def select(self, connections): + return random.choice(connections) + + class RoundRobinSelector(ConnectionSelector): " Default selector using round-robin. " def __init__(self, opts):