{
  "id": "localaccumulateby",
  "title": "LocalAccumulateBy",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/localaccumulateby/",
  "summary": "Groups records and reduces each group to a single record per group locally on each shard.",
  "tags": [
    "docs",
    "operate",
    "stack"
  ],
  "last_updated": "2026-04-22T11:55:45+02:00",
  "page_type": "content",
  "content_hash": "f9c50059846abc24dbc0f2f388db3c2b751a8ffed89a8b416b1f7336a027efa4",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[code example]\n\nThe `localAccumulateBy` function is similar to [`accumulateBy`](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/accumulateby), except it performs the operation locally on each shard without moving data between shards.\n\nOn each shard, it iterates through the records in the pipe, groups them based on the provided extractor, and then reduces each group to a single record per group with the accumulator function.\n\nThe initial value of the accumulator is null."
    },
    {
      "id": "parameters",
      "title": "Parameters",
      "role": "parameters",
      "text": "Type parameters:\n\n| Name | Description |\n|------|-------------|\n| I | The template type of the returned builder |\n\nFunction parameters:\n\n| Name | Type | Description |\n|------|------|-------------|\n| accumulator | <nobr>AccumulateByOperation<T,​I></nobr> | A function with logic to update the accumulator value with each record |\n| extractor | ExtractorOperation<T> | Extracts a specific value from each record |"
    },
    {
      "id": "returns",
      "title": "Returns",
      "role": "returns",
      "text": "Returns a GearsBuilder object with a new template type."
    },
    {
      "id": "example",
      "title": "Example",
      "role": "example",
      "text": "[code example]"
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "java",
      "code": "public <I extends java.io.Serializable> GearsBuilder<I> localAccumulateBy​(\n\tgears.operations.ExtractorOperation<T> extractor, \n\tgears.operations.AccumulateByOperation<T,​I> accumulator)",
      "section_id": "overview"
    },
    {
      "id": "example-ex0",
      "language": "java",
      "code": "GearsBuilder.CreateGearsBuilder(reader).\n   \tlocalAccumulateBy(r->{\n   \t\treturn r.getStringVal();\n   \t},(k, a, r)->{\n   \t\tInteger ret = null;\n   \t\tif(a == null) {\n   \t\t\tret = 0;\n   \t\t}else {\n   \t\t\tret = (Integer)a;\n   \t\t}\n   \t\treturn ret + 1;\n});",
      "section_id": "example"
    }
  ]
}
