DEV Community

Cover image for Managing buckets with Reduct Storage CLI Client
Alexey Timin for ReductStore

Posted on

Managing buckets with Reduct Storage CLI Client

A bucket is a top-level data container of Reduct Storage. You can consider it as a folder of a file system. If you delete it, you delete all files inside the bucket. Also, it has common settings for all entries, like the quota or maximal block size.

You can create, remove or browse a bucket by using:

  1. HTTP API with CURL
  2. Python, JavaScript, or C++ SDKs
  3. Web Console
  4. CLI Client

In this post, I'll show you how we can use the CLI client for typical operations with bucket.

Installing

The CLI client is cross-platform and written in pure Python. The easiest way to install it, is pip:

pip install reduct-cli
Enter fullscreen mode Exit fullscreen mode

After installation, check the version:

rcli --version
Enter fullscreen mode Exit fullscreen mode

This tutorial was written and tested for version 0.2.0 and Reduct Storage 1.0.1.

Aliasing

To avoid entering credentials and server URL for each command, the CLI client uses aliases. So, we should setup one before to start. Let's run a Reduct Storage instance locally and add an alias to it:

rcli alias add local
  URL: http://127.0.0.1:8383
  API Token []: # leav token empty if you don't use it
Enter fullscreen mode Exit fullscreen mode

Check:

rcli server status local
Status:     Ok
Version:    1.0.1
Uptime:     39 second(s)
Enter fullscreen mode Exit fullscreen mode

If you don't have any errors, you create a correct alias.

Bucket Management

Now, we can create a bucket:

rcli bucket create --quota-type FIFO --quota-size 30Mb local/my-data
Bucket 'my-data' created
Enter fullscreen mode Exit fullscreen mode

Here we created a bucket called my-data and FIFO quota of 30MB. We choose this type of the bucket quota to remove old data when the bucket size reaches 30MB.

You can check the whole settings:

rcli bucket show local/my-data --full

╭───────────────────── Info ─────────────────────╮╭───────── Settings ─────────╮
│ Entry count:         0                         ││ Quota Type:         FIFO   │
│ Size:                0 B                       ││ Quota Size:         30 MB  │
│ Oldest Record (UTC): ---                       ││ Max. Block Size:    64 MB  │
│ Latest Record (UTC): ---                       ││ Max. Block Records: 1024   │
│ History Interval:    ---                       ││                            │
│                                                ││                            │
│                                                ││                            │
│                                                ││                            │
│                                                ││                            │
│                                                ││                            │
╰────────────────────────────────────────────────╯╰────────────────────────────╯
                                    Entries                                     
┏━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃      ┃         ┃        ┃      ┃ Oldest Record   ┃ Latest Record   ┃         ┃
┃ Name ┃ Records ┃ Blocks ┃ Size ┃ (UTC)           ┃ (UTC)           ┃ History ┃
┡━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
└──────┴─────────┴────────┴──────┴─────────────────┴─────────────────┴─────────┘
Enter fullscreen mode Exit fullscreen mode

You may also notice that the bucket is empty. We can write some data there with CURL:

curl -X POST -d "Hey, I'm a blob string"  http://127.0.0.1:8383/api/v1/b/my-data/entry?ts=1667741359000000
Enter fullscreen mode Exit fullscreen mode

If we repeat the previous bucket show command, we should see that the bucket has some data now:

rcli bucket show local/my-data --full
Enter fullscreen mode Exit fullscreen mode

The CLI client also provides the bucket ls command to print a list of buckets:

rcli bucket ls local
my-data
Enter fullscreen mode Exit fullscreen mode

You also can add --full flag to show more detail:

rcli bucket ls local --full

┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃                  ┃             ┃      ┃ Oldest Record     ┃ Latest Record    ┃
┃             Name ┃ Entry Count ┃ Size ┃ (UTC)             ┃ (UTC)            ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│          my-data │ 1           │ 22 B │ 2022-11-06T13:29… │ 2022-11-06T13:2… │
├──────────────────┼─────────────┼──────┼───────────────────┼──────────────────┤
│      Total for 1 │ 1           │ 22 B │ 2022-11-06T13:29… │ 2022-11-06T13:2… │
│          buckets │             │      │                   │                  │
└──────────────────┴─────────────┴──────┴───────────────────┴──────────────────┘
Enter fullscreen mode Exit fullscreen mode

In the end, you may want to remove your bucket and all its data. You should use the bucket rm command for this:

rcli bucket rm local/my-data
All data in bucket 'my-data' will be REMOVED.
Do you want to continue? [y/N]: y
Bucket 'my-data' was removed
Enter fullscreen mode Exit fullscreen mode

I hope it was helpful. The Reduct Storage project is open-source software. You can find the source code of the storage engine and all its libraries and tools on our GitHub organization. Please create an issue or discussion there, if you need help.

Top comments (0)