Skip to main content

Key Value Store

Overview

The Key-Value Store in RelayX provides a simple way to persist and retrieve small pieces of state that need to be shared across parts of your system.

It is designed for configuration, flags, counters, metadata, and other lightweight state that must be available quickly and consistently. It is not a database and does not provide querying, indexing, or transactions.

Before performing any key-value operations, the Key-Value Store must be explicitly initialized. All reads and writes happen through the initialized store handle.


How This Works

The Key-Value Store is scoped to your RelayX account.

When you initialize the store, the SDK establishes access permissions and prepares a client-side handle. All operations are executed directly against the RelayX backend.

Writes overwrite existing values. Reads return the most recent value. Deletes permanently remove keys.

There is no versioning, no history, and no conflict resolution beyond last-write-wins.

Success for an operation means the backend has accepted the request and applied it.


Initializing the Key-Value Store

Before using the Key-Value Store, you must initialize it from a connected client.

kv_store = await client.init_kv_store()

This returns a Key-Value Store handle that exposes all KV operations.

Initialization may fail if the client is not connected or does not have KV permissions.


Creating or Updating a Key

API Usage

await kv_store.put(key, value)

Key Rules

  • Must be a string
  • Must not be null
  • Must not be empty
  • Names can only contain: a-z, A-Z, 0-9, _, -, ., = and /

Value Rules

Values may be:

  • String
  • Number
  • Boolean
  • Object (JSON)
  • Array
  • Null

If the key does not exist, it is created.

If the key already exists, the previous value is overwritten.

The method does not return anything.

Errors

put() throws an error if:

  • The key is invalid
  • The value type is unsupported
  • The client does not have write permission

Example

await kv_store.put("config.maxRetries", 5)
await kv_store.put("featureFlags.newUI", True)
await kv_store.put("service.metadata", { "region": "ap-south-1" })

Getting a Value

API Usage

value = await kv_store.get(key)

The method returns the stored value for the given key.

Key Rules

  • Must be a string
  • Must not be null
  • Must not be empty
  • Names can only contain: a-z, A-Z, 0-9, _, -, ., = and /

Errors

get() throws an error if:

  • The key is invalid
  • The client does not have read permission

Example

retries = await kv_store.get("config.maxRetries")
print(retries)

Deleting a Key

API Usage

await kv_store.delete(key)

Deletes the key permanently from the Key-Value Store.

The method does not return anything.

Key Rules

  • Must be a string
  • Must not be null
  • Must not be empty
  • Names can only contain: a-z, A-Z, 0-9, _, -, ., = and /

Errors

delete() throws an error if:

  • The key is invalid
  • The client does not have write permission

Example

await kv_store.delete("featureFlags.newUI")

Listing All Keys

API Usage

keys = await kv_store.keys()

Returns an array of strings representing all keys currently stored.

Errors

keys() throws an error if:

  • The client does not have read permission

Example

allKeys = await kv_store.keys()
print(allKeys)

Common Mistakes

  • Assuming values are versioned or transactional
  • Using the KV Store as a database
  • Writing large payloads
  • Ignoring permission errors

Notes & Limitations

  • Last-write-wins behavior
  • No TTL or expiry
  • No atomic operations
  • No partial updates
  • Intended for small, shared state only


Need Help?

Join our Discord server, post your concern & someone from our team will help you out ✌️