A Key-Value DataStore that supports CRD operations by creating a local database on the local machine.
A file-based key-value data store that supports the basic CRD (create, read, and delete) operations. This data store is meant to be used as a local storage for one single process on one laptop. The data store must be exposed as a library to clients that can instantiate a class and work with the data store.
The data store supports the following functional requirements :
-
It can be initialized using an optional file path. If one is not provided, it will reliably create itself in a reasonable location on the laptop.
-
A new key-value pair can be added to the data store using the Create operation. The key is always a string - capped at 32chars. The value is always a JSON object - capped at 16KB.
-
If Create is invoked for an existing key, an appropriate error must be returned.
-
A Read operation on a key can be performed by providing the key, and receiving the value in response, as a JSON object.
-
A Delete operation can be performed by providing the key.
-
Every key supports setting a Time-To-Live property when it is created. This property is optional. If provided, it will be evaluated as an integer defining the number of seconds the key must be retained in the data store. Once the Time-To-Live for a key has expired, the key will no longer be available for Read or Delete operations.
-
Appropriate error responses must always be returned to a client if it uses the data store in unexpected ways or breaches any limits.
The data store will also support the following non-functional requirements :
-
The size of the file storing data must never exceed 1GB.
-
More than one client process cannot be allowed to use the same file as a data store at any given time.
-
A client process is allowed to access the data store using multiple threads, if it desires to. The data store must therefore be thread-safe.
-
The client will bear as little memory costs as possible to use this data store, while deriving maximum performance with respect to response times for accessing the data store.
To get a local copy up and running follow these simple example steps.
- Python
To check, if python is installed, type python
in command line. If this opens python3
interpreter then you are good to go.
else, python3
follow this link to download the latest version.
- Git
You can download the latest version of git
here.
- Clone the repo
git clone https://github.com/A-lone-Contributer/File-based-Key-Value-Store.git
from ds.__init__ import DataStore
import json
db = DataStore("C:\\Users\\acer\\Desktop\\data_store.json") # location is optional
Note: If location is provided then file desired json file must exist there
db.create('Student', json.dumps({'Name': 'John Doe'}))
# Optional Time-To-Live (TTL) argument
db.create('TempStudent', json.dumps({'Name': 'Steven'}), 2) # this {key:json obj} expires in 2 seconds
name = db.read('Student')
db.delete('Student')
To run the unittests, follow the below written steps
- Navigate to the test folder
cd tests
- Run the tests file
python3 tests.py
After running this file, all the 12 tests cases show run successfully indicating unittest coverage.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the Apache-2.0 License. See LICENSE
for more information.
Nishkarsh Tripathi : nishkarsh78@gmail.com
Project Link : File-based-Key-Value-Store