Git Product home page Git Product logo

kvstore's Introduction

File-based Key-Value Store(JAVA)

Prerequisites

  1. Java JDK.
  2. You need to download the json-jar file from https://code.google.com/archive/p/org-json-java/downloads.

How to use?

Step 1:

If you do not want to clone,go to step 2.Clone this repository to any desired location on your system:

https://github.com/RajayR2000/KVStore.git

or download as a zip file and extract.

Step 2 (YOU CLONED, see below if you did not clone):

Add the downloaded json_jar file from prerequisites to the build path.

Follow following steps to add a jar file to build path for Eclipse :

  1. Right-click the project folder and click Properties.
  2. Click Java Build Path in the left pane.
  3. Click the Libraries tab.
  4. Click "Add External JARs", select the JAR file that you downloaded, then click OK.

Now you can simply run the EndUser class in the default package to use your KVStore.Skip all the steps below and go to methods.

Step 2 (YOU DID NOT CLONE,using kvstore_JAR):

  • So you do not want to clone my repo,it is fine :(
    • Create a java project.
    • Download the kvstore_JAR file from my repo by clicking on it and pressing the download button on the right.
    • Add kvstore_JAR file as well as the jsonjar(See Prerequisites) file to your project's build path by following the below instructions.

Follow following steps to add a jar file to build path for Eclipse :

  1. Right-click the project folder and click Properties.
  2. Click Java Build Path in the left pane.
  3. Click the Libraries tab.
  4. Click "Add External JARs", select the JAR file that you downloaded, then click OK.

Step 3

Create a KVStore object.

KVStore obj = new KVStore();

Step 4:

Initialise JSON object with the json value you want. This initialisation might throw JSONException,so you might have to deal with that. After creating the JSON object,you can now call the methods that you want(Create,Read,Delete)

try {
JSONObject j1 = new JSONObject("{\"name\":\"John\", \"age\":30, \"car\":null }");

obj.create("John" , j1 , 10) // or obj.create("John" , j1);
}

Methods

Create

The create function in the KVStore takes either 2 or 3 arguments.

create(String key , JSONObject value)

create(String key , JSONObject value , long TimeToLive)

If you create include the TimeToLive value while creation,then the created entry will be deleted after TTL seconds.

Read

The read function in the KVStore takes either 1 argument.

read(String key)

This will return the JSON value stored to the corresponding key.

Delete

The delete function in the KVStore takes either 1 argument.

delete(String key)

This will delete the key-value pair from the storage.


Time-To-Live

The TTL property can be satisfied with the help of the schedule() function of the Timer class.

It takes two arguments.

schedule(task to be performed , time after which the task is to be performed in milliseconds) The task to be performed can be mentioned by over-riding run() of the TimerTask.

For example: schedule(task , 1000)

Here the mentioned task is performed after 1 second.

Code

public class ClassName extends TimerTask
{
    @Override
    public void run() {
        //TASK
    }

}

Screenshots

Output after you run the EndUser.java file

Screenshot (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.