Exemplo n.º 1
0
def create_event(event_sku, blocks=2, seats_per_block=32, tier="General"):
    """Create the seats blocks for the given event. 32 bits are available for
seats. This could be extended to accommodate more bits, by storing multiple
u32 fields."""
    block_name = "A"
    for _ in range(blocks):
        filled_seat_map = int(
            math.pow(2, min(seats_per_block, __max__seats_per_block__))) - 1
        vals = ["SET", "u32", 0, filled_seat_map]
        key = keynamehelper.create_key_name("seatmap", event_sku, tier,
                                            block_name)
        redis.execute_command("BITFIELD", key, *vals)
        block_name = textincr.incr_str(block_name)
Exemplo n.º 2
0
def create_seatmap(event_sku, tiers, capacity):
  """Add keys for seat reservation unit"""
  import math
  block_name = "A"
  # Use this formula if you want multiple 32bit blocks stored in a single key.
  # More compact, harder to understand
  # seats_per_block = min(max_seats_per_block, -(-capacity / tiers))
  seats_per_block = max_seats_per_block
  blocks_to_fill = -(-capacity // seats_per_block)
  to_fill = capacity
  for k in range(blocks_to_fill):
    seats_in_block = min(to_fill, seats_per_block)
    filled_seat_map = int(math.pow(2, seats_in_block))-1
    # vals = ["SET", "u32", k * seats_per_block, filled_seat_map]
    vals = ["SET", "u32", 0, filled_seat_map]
    seat_key = create_key_name("seatmap", event_sku,
                               ticket_tiers[(k % tiers) +1], block_name)
    p.execute_command("BITFIELD", seat_key, *vals)
    to_fill -= seats_in_block
    block_name = textincr.incr_str(block_name)
  p.execute()