package main import ( "context" "log" "git.tornberg.me/go-cart-actor/pkg/inventory" "github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9/maintnotifications" ) func main() { var ctx = context.Background() rdb := redis.NewClient(&redis.Options{ Addr: "10.10.3.18:6379", Password: "slaskredis", // no password set DB: 0, // use default DB MaintNotificationsConfig: &maintnotifications.Config{ Mode: maintnotifications.ModeDisabled, }, }) s, err := inventory.NewRedisInventoryService(rdb, ctx) if err != nil { log.Fatalf("Unable to connect to inventory redis: %v", err) return } rdb.Pipelined(ctx, func(p redis.Pipeliner) error { s.UpdateInventory(p, "1", "1", 10) s.UpdateInventory(p, "2", "2", 20) s.UpdateInventory(p, "3", "3", 30) s.UpdateInventory(p, "4", "4", 40) return nil }) err = s.ReserveInventory( inventory.ReserveRequest{ SKU: "1", LocationID: "1", Quantity: 3, }, inventory.ReserveRequest{ SKU: "2", LocationID: "2", Quantity: 15, }, inventory.ReserveRequest{ SKU: "3", LocationID: "3", Quantity: 25, }, ) if err != nil { log.Printf("Unable to reserve inventory: %v", err) } v, err := s.GetInventory("1", "1") if err != nil { log.Printf("Unable to get inventory: %v", err) return } log.Printf("Inventory after reservation: %v", v) }