This commit is contained in:
mats committed 2026-07-26 12:59:52 +02:00
1 parent 78a7d35570
commit a7b886c4c5
3 files changed
+1 -115

No files matched your search

+1 -27
View File
@@ -2,7 +2,6 @@ package inventory
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
@@ -106,26 +105,6 @@ func (s *RedisInventoryService) IncrementInventory(ctx context.Context, rdb redi
return cmd.Err()
}
func (s *RedisInventoryService) SendInventoryChanged(ctx context.Context, sku SKU, locationID LocationID) error {
key := getInventoryKey(sku, locationID)
currentValCmd := s.client.Get(ctx, key)
if err := currentValCmd.Err(); err != nil {
return err
}
currentVal, err := currentValCmd.Int64()
if err != nil {
return err
}
payloadMap := map[string]int64{key: currentVal}
payloadBytes, err := json.Marshal(payloadMap)
if err != nil {
return err
}
payload := string(payloadBytes)
cmd := s.client.Publish(ctx, "inventory_changed", payload)
return cmd.Err()
}
var (
ErrInsufficientInventory = errors.New("insufficient inventory")
ErrInvalidQuantity = errors.New("invalid quantity")
@@ -282,12 +261,7 @@ for i = 1, num_keys do
local new_val = new_values[i]
-- Set the key to its new calculated value
redis.call('SET', key, new_val)
end
local message_payload = cjson.encode(payload)
-- Publish the JSON-encoded message to the specified channel
redis.call('PUBLISH', "inventory_changed", message_payload)
redis.call('SET', key, new_val) end
-- Return 1 to indicate the operation was successful
return 1
`)