Skip to main content
Version: 1.11.x

Data Management With ReductStore

ReductStore provides a set of methods to manage data in the database. This guide provides an overview of typical data management operations in ReductStore and explains how to perform them using the ReductStore SDKs or the HTTP API.

Changing Labels​

ReductStore doesn't allow you to change the contents of records, but it does allow you to change the labels of existing records. You can add, remove or update labels for a single record or for a batch of records to avoid HTTP requests overhead.

note

You should send a label as an empty string to remove it.

import time
import asyncio
from reduct import Client, Bucket, Batch


async def main():
# Create a client instance, then get or create a bucket
async with Client("http://127.0.0.1:8383", api_token="my-token") as client:
bucket: Bucket = await client.create_bucket("my-bucket", exist_ok=True)

# Send some records to the "py-example" entry with labels
ts = time.time()
await bucket.write(
"py-example",
b"Some binary data",
ts,
labels={"key1": "value1", "key2": "value2"},
)
await bucket.write(
"py-example",
b"Some binary data",
ts + 1,
labels={"key1": "value1", "key2": "value2"},
)

# Update labels of a record: remove "key2" and update "key1"
await bucket.update("py-example", ts, labels={"key1": "new-value", "key2": ""})
async with bucket.read("py-example", ts) as record:
assert record.labels["key1"] == "new-value"
assert "key2" not in record.labels

# Update labels in a batch
batch = Batch()
batch.add(ts, labels={"key1": "new-value", "key2": ""})
batch.add(ts + 1, labels={"key3": "value3"})
errors = await bucket.update_batch("py-example", batch)
assert not errors


if __name__ == "__main__":
import asyncio

asyncio.run(main())

Deleting Data​

Currently, you can delete data per bucket or per entry by using the Client SDKs, Reduct CLI or HTTP API:


from reduct import Client, Bucket


async def main():
# Create a client with the base URL and API token
async with Client("http://localhost:8383", api_token="my-token") as client:
# Get bucket to remove
bucket: Bucket = await client.get_bucket("bucket-to-remove")

# Delete only entry with name "example-entry"
await bucket.remove_entry("example-entry")

# Remove entire bucket
await bucket.remove()


if __name__ == "__main__":
import asyncio

asyncio.run(main())