Skip to content

semaphore

Category: Graph, synchronization, and network
Wire type: semaphore
Construction: CREATE

These types cover graph adjacency, atomic coordination, synchronization, rate limiting, and network values.

Use the top-level CREATE command to initialize this structured value. The example shows its construction options.

Terminal window
amaquet-cli -uri amaquet://127.0.0.1:13378 CREATE '{"key":"example:semaphore","type":"semaphore","options":{"limit":2}}'

Example CREATE options: {"limit":2}. Omitted fields use server defaults.

ACQUIRE, TRY_ACQUIRE, RELEASE, STATS.

See the complete operation contract for exact arguments, defaults, results, and whether a listed GET is the top-level key command or a type-specific OP. It also identifies read-only operations and documents validation, lazy maintenance, and key-version behavior.

The following examples use the public amaquet-cli JSON command format. Replace example:semaphore with the key used by your application.

Use the payload below to initialize this type before issuing reads or type-specific operations.

This payload initializes the value and must complete before its type-specific operations are used.

{
"key": "example:semaphore",
"type": "semaphore",
"options": {
"limit": 2
}
}

Each request uses the OP envelope. The response is the type-specific value described in the complete operation contract.

Takes no arguments and returns immediate boolean.

{
"key": "example:semaphore",
"operation": "TRY_ACQUIRE",
"args": {}
}

Takes no arguments and returns {limit,in_use}.

{
"key": "example:semaphore",
"operation": "STATS",
"args": {}
}

Takes no arguments and returns boolean; false when no permit is held.

{
"key": "example:semaphore",
"operation": "RELEASE",
"args": {}
}

Takes no arguments and waits for a permit before returning true.

{
"key": "example:semaphore",
"operation": "ACQUIRE",
"args": {}
}

GET reads the current value without changing it:

{
"key": "example:semaphore"
}

These commands apply to the key regardless of its registered type:

  • TYPE: {"key":"example:semaphore"} — returns the wire type.
  • EXISTS: {"key":"example:semaphore"} — reports whether the key exists.
  • EXPIRE: {"key":"example:semaphore","ttl_ms":5000} — assigns a five-second TTL.
  • TTL: {"key":"example:semaphore"} — returns the remaining TTL in milliseconds.
  • PERSIST: {"key":"example:semaphore"} — removes the TTL.
  • DEL: {"keys":["example:semaphore"]} — deletes the key.

For defaults, validation, result shapes, and persistence classification, see the complete operation contract.

The key participates in TYPE, EXISTS, TTL, EXPIRE, PERSIST, and DEL. Top-level GET returns the type’s direct public value or a synchronized snapshot.