2026-07-03 18:30:13 +02:00
2026-07-03 18:30:13 +02:00
2026-07-03 18:13:11 +02:00
2026-06-29 12:34:21 +02:00
2026-06-29 12:34:21 +02:00

Go Redis Inventory

A Go library for managing inventory using Redis.

Features

  • Get and update inventory quantities
  • Reserve inventory with atomic operations using Lua scripts
  • Temporary cart-based reservations with expiration to prevent overselling
  • Optimized available inventory calculation using maintained reservation totals
  • Listen to inventory changes via Redis pub/sub

Installation

go get git.k6n.net/mats/go-redis-inventory

Usage

Import the package:

import "git.k6n.net/mats/go-redis-inventory/pkg/inventory"

Create a Redis client and initialize the service:

client := redis.NewClient(&redis.Options{
    Addr: "localhost:6379",
})
service, err := inventory.NewRedisInventoryService(client)
if err != nil {
    log.Fatal(err)
}

For cart reservations:

cartService, err := inventory.NewRedisCartReservationService(client)
if err != nil {
    log.Fatal(err)
}

// Reserve items for a cart with 10-minute TTL
err = cartService.ReserveForCart(ctx, inventory.CartReserveRequest{
    InventoryReference: &inventory.InventoryReference{SKU: "item1", LocationID: "warehouse1"},
    CartID: "cart123",
    Quantity: 2,
    TTL: 10 * time.Minute,
})

// Get available inventory (accounting for reservations)
available, err := cartService.GetAvailableInventory(ctx, "item1", "warehouse1")

// Get reservation summary for an item
summary, err := cartService.GetReservationSummary(ctx, "item1", "warehouse1")
fmt.Printf("Reservations: %d, Next release: %v, Remaining: %d\n", summary.ReservationCount, summary.EarliestRelease, summary.RemainingItems)

Dependencies

S
Description
No description provided
Readme 64 KiB
Languages
Go 100%