summaryrefslogtreecommitdiff
path: root/kafka/partitioner/hashed.py
blob: 587a3de48445ac92948baadad0c6d722514388c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
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]