Files
deb-python-kafka/kafka/partitioner/hashed.py
2014-09-10 22:14:29 -07:00

13 lines
318 B
Python

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]