HadiDB: A lightweight, horizontally scalable database in Python
HadiDB: Lightweight, high-level scalable Python database
HadiDB (hadidb) is a lightweight database written in Python that has a high level of scalability.
Install HadiDB
Install using pip:
<code class="bash">pip install hadidb</code>
User Management
Create a user: createuser()
method creates a new user. authentication()
method authenticates the user's identity.
<code class="python">from hadidb.operation import user user_obj = user("admin", "admin") user_obj.createuser() # 创建用户user_obj.authentication() # 验证用户</code>
Return the result example:
<code class="json">{'status': 200, 'message': 'database user created'}</code>
Database, collection, and schema creation
The following code snippet shows how to set up user credentials, database collection schema, and how to insert data.
<code class="python">from hadidb.operation import operation username = "admin" password = "admin" database = "mefiz.com" collection = "authuser" schema = { "username": "unique", "password": "hash", "cnic": "unique", "picture": "image", "bio": "text" } db = operation(username, password, database, collection) db.create_database(schema)</code>
Data operation
- Insert data:
db.insert(data)
method inserts data.
<code class="python">data = { "username": "hadidb", "password": "12345", "cnic": "123232442", "picture": "user/my/hadidb.jpg", "bio": "hadidb is the best ;)" } result = db.insert(data) print(result)</code>
Return the result example:
<code class="json">{ 'status': 200, 'message': 'data insert successfully', 'data': { 'username': 'hadidb', 'password': '12345', 'cnic': '123232442', 'picture': 'user/my/hadidb.jpg', 'bio': 'hadidb is the best ;)', 'id': 1 } }</code>
- Update data:
db.update(1, update_data)
method updates data.
<code class="python">update_data = { "username": "hadidb_update", "password": "123455", "cnic": "1232324423", "picture": "user/my/hadidb1.jpg", "bio": "hadidb is the best ;) update bio" } result = db.update(1, update_data) print(result)</code>
Get data by ID:
db.getbyid(1)
method Get data by ID.Get all data:
db.getall()
method gets all data.Press the key to get data:
db.getbykey()
anddb.getbykeys()
methods use the key to get data.Count: The number of data statistics of
db.count()
method.db.getbykeycount()
method counts the number of data matching the specified key-value pair.Delete data:
db.delete(1)
method deletes data.
Database and collection management
Get all databases:
configuration().get_database()
method gets all databases.Get all collections:
configuration(database).get_collection()
method gets all collections of the specified database.Get the pattern:
configuration(database, collection).get_schema()
method gets the pattern of the specified collection.Delete collection:
databasedeletionservice().deletecollection()
method deletes collection.Delete the database:
databasedeletionservice().deleteDatabase()
method deletes the database.
Project link
- GitHub: https://www.php.cn/link/4b0a618db23379c7c77f818cf569050d
- Website: https://www.php.cn/link/a2642f3f2bd5c4424bb169ac8367257f
- Developer: Moming Iqbal
This version reorganized and polished the original text to make it clearer and easier to read, and formatted the code sections to make it easier to understand. All image links are retained.
The above is the detailed content of HadiDB: A lightweight, horizontally scalable database in Python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Redis uses hash tables to store data and supports data structures such as strings, lists, hash tables, collections and ordered collections. Redis persists data through snapshots (RDB) and append write-only (AOF) mechanisms. Redis uses master-slave replication to improve data availability. Redis uses a single-threaded event loop to handle connections and commands to ensure data atomicity and consistency. Redis sets the expiration time for the key and uses the lazy delete mechanism to delete the expiration key.

How to clean all Redis data: Redis 2.8 and later: The FLUSHALL command deletes all key-value pairs. Redis 2.6 and earlier: Use the DEL command to delete keys one by one or use the Redis client to delete methods. Alternative: Restart the Redis service (use with caution), or use the Redis client (such as flushall() or flushdb()).

To view all keys in Redis, there are three ways: use the KEYS command to return all keys that match the specified pattern; use the SCAN command to iterate over the keys and return a set of keys; use the INFO command to get the total number of keys.

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

Redis memory fragmentation refers to the existence of small free areas in the allocated memory that cannot be reassigned. Coping strategies include: Restart Redis: completely clear the memory, but interrupt service. Optimize data structures: Use a structure that is more suitable for Redis to reduce the number of memory allocations and releases. Adjust configuration parameters: Use the policy to eliminate the least recently used key-value pairs. Use persistence mechanism: Back up data regularly and restart Redis to clean up fragments. Monitor memory usage: Discover problems in a timely manner and take measures.

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.
