summaryrefslogtreecommitdiff
path: root/kafka/partitioner/hashed.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2014-09-10 23:31:33 -0700
committerDana Powers <dana.powers@gmail.com>2014-09-10 23:31:33 -0700
commit931670ff2d13e1e4953bbcfa4fff45d7dcb94533 (patch)
tree46a3873a5d9d653e09aaf5c7b5fc60167ea22a8c /kafka/partitioner/hashed.py
parent04dbd0e7912c43e0d5cf32b29f0250dc67937df7 (diff)
parent27e812e66bd04d3acf59ad6792b07d1c7056c036 (diff)
downloadkafka-python-931670ff2d13e1e4953bbcfa4fff45d7dcb94533.tar.gz
Merge pull request #232 from dpkp/directory_layout
Separate Consumer/Producer/Partitioner modules
Diffstat (limited to 'kafka/partitioner/hashed.py')
-rw-r--r--kafka/partitioner/hashed.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/kafka/partitioner/hashed.py b/kafka/partitioner/hashed.py
new file mode 100644
index 0000000..587a3de
--- /dev/null
+++ b/kafka/partitioner/hashed.py
@@ -0,0 +1,12 @@
+from .base import Partitioner
+
+class HashedPartitioner(Partitioner):
+ """
+ Implements a partitioner which selects the target partition based on
+ the hash of the key
+ """
+ def partition(self, key, partitions):
+ size = len(partitions)
+ idx = hash(key) % size
+
+ return partitions[idx]