Giter Club home page Giter Club logo

easybucket's Introduction

easyBucket

An easy multi-thread supported bucket database

Installation

pip install git+https://github.com/guanhuankang/easyBucket.git

Quick Try

Below is the tutorial code.

from easybucket import easyBucket

## optional
easyBucket.bucket_path = "easyBucketDataBase"
easyBucket.max_fifo = 100 

def tutorial(x):
    bucket_name = "test"  ## Bucket name
    with easyBucket(bucket_name, btype="json") as bucket:
        bucket["say"] = "Hello World"
        bucket["name"] = "I am easyBucket"
        bucket["array"] = ["I", "support", "array"]
        bucket["hasAddr"] = bucket.has("addr")
        bucket["dictOfdict"] = {
            "key2": {
                "key1": "value"
            }
        }
        bucket["cnt"] = bucket.get("cnt", 0) + 1
        bucket.flush()  ## flush mannually ## Actually, easyBucket will flush automatically
        data = bucket.content()
    print(data)
    print(easyBucket.buckets, len(easyBucket.fifo))

if __name__=="__main__":
    from threading import Thread

    # tutorial(2)
    # exit(0)

    threads = [
        Thread(target=tutorial, args=(x,))
        for x in range(1000)
    ]

    for t in threads:
        t.start()
    for t in threads:
        t.join()

    easyBucket.clean()  ## flush all data to stroage before exiting easyBucket
    print(easyBucket.buckets)  ## cache in the easyBucket

where "easyBucket.bucket_path" is the root location of the bucket database, and "easyBucket.max_fifo" is the max-length of the FIFO queue, which will trigger the flush and unload event when the length of FIFO exceed the max-length value.

Run tutorial.py:

python tutorial.py

Note that "bucket_name" is the unique identifier to retrieve the bucket.

ToDo

[] Multi-bucket supporting

Huankang Guan, [email protected]

easybucket's People

Contributors

guanhuankang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.