DistributedLockCron


NameDistributedLockCron JSON
Version 3.0.0 PyPI version JSON
download
home_pageNone
SummaryPackage to used for handling lock mechanism when running appplication with multiple replicas
upload_time2025-01-07 12:04:55
maintainerNone
docs_urlNone
authorTanmay Varade
requires_pythonNone
licenseNone
keywords python distributed lock rds sql redis replicas kubernetes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# distributed lock module

This Python package provides a mechanism to acquire and release Redis and MYSQL locks with authentication. It is useful for ensuring that only one process can access a particular resource or execute a critical section of code at a time.

## Features
- Connects to Redis or MySQL with username and password for authentication.
- Acquires a lock, executes a function, and then releases the lock.
- Useful in distributed systems where resource locking is needed.

## Installation

To install the module, use `pip`:

```
pip install DistributedLockCron
```

## use with mysql lock
```

import DistributedLockCron

mysql_user = "root"
mysql_pass = "root"
mysql_host = "localhost"
mysql_database = "mysql"

connection = mysql.connector.connect(
    host=mysql_host,
    user=mysql_user,
    password=mysql_pass,
    database=mysql_database,
    pool_name="mypool",
    pool_size=3
)

cron_expression = "* */5 * * *"  # Runs every 5 minute
DistributedLockCron.start_cron_with_expression(connection, my_custom_function, cron_expression,"mysql")


def my_custom_function():
    # add whatever action you want in your custom function
    pass
```

## use with redis lock
```

import DistributedLockCron

redis_host = "localhost"
redis_port = 6379
redis_username = "default"
redis_password = "root"

# Connect to Redis with username and password
connection = redis.StrictRedis(
    host=redis_host,
    port=redis_port,
    username=redis_username,
    password=redis_password,
    decode_responses=True
)

cron_expression = "* */5 * * *"  # Runs every 5 minute
DistributedLockCron.start_cron_with_expression(connection, my_custom_function, cron_expression,"redis")


def my_custom_function():
    # add whatever action you want in your custom function
    pass

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "DistributedLockCron",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, distributed, lock, rds, sql, redis, replicas, kubernetes",
    "author": "Tanmay Varade",
    "author_email": "tanmayvarade235@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fe/54/f117c0ece50e5b36494f9c9a4101b76431d7aeda69ec8f7d5fea6d815dfd/distributedlockcron-3.0.0.tar.gz",
    "platform": null,
    "description": "\n# distributed lock module\n\nThis Python package provides a mechanism to acquire and release Redis and MYSQL locks with authentication. It is useful for ensuring that only one process can access a particular resource or execute a critical section of code at a time.\n\n## Features\n- Connects to Redis or MySQL with username and password for authentication.\n- Acquires a lock, executes a function, and then releases the lock.\n- Useful in distributed systems where resource locking is needed.\n\n## Installation\n\nTo install the module, use `pip`:\n\n```\npip install DistributedLockCron\n```\n\n## use with mysql lock\n```\n\nimport DistributedLockCron\n\nmysql_user = \"root\"\nmysql_pass = \"root\"\nmysql_host = \"localhost\"\nmysql_database = \"mysql\"\n\nconnection = mysql.connector.connect(\n    host=mysql_host,\n    user=mysql_user,\n    password=mysql_pass,\n    database=mysql_database,\n    pool_name=\"mypool\",\n    pool_size=3\n)\n\ncron_expression = \"* */5 * * *\"  # Runs every 5 minute\nDistributedLockCron.start_cron_with_expression(connection, my_custom_function, cron_expression,\"mysql\")\n\n\ndef my_custom_function():\n    # add whatever action you want in your custom function\n    pass\n```\n\n## use with redis lock\n```\n\nimport DistributedLockCron\n\nredis_host = \"localhost\"\nredis_port = 6379\nredis_username = \"default\"\nredis_password = \"root\"\n\n# Connect to Redis with username and password\nconnection = redis.StrictRedis(\n    host=redis_host,\n    port=redis_port,\n    username=redis_username,\n    password=redis_password,\n    decode_responses=True\n)\n\ncron_expression = \"* */5 * * *\"  # Runs every 5 minute\nDistributedLockCron.start_cron_with_expression(connection, my_custom_function, cron_expression,\"redis\")\n\n\ndef my_custom_function():\n    # add whatever action you want in your custom function\n    pass\n\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Package to used for handling lock mechanism when running appplication with multiple replicas",
    "version": "3.0.0",
    "project_urls": null,
    "split_keywords": [
        "python",
        " distributed",
        " lock",
        " rds",
        " sql",
        " redis",
        " replicas",
        " kubernetes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d863b0aa837c5100134ef4f16de5403e74b50d1c9e584f4fa2999b5acbd5f635",
                "md5": "2d16d22e849ba39c9a472d1b58abedbd",
                "sha256": "191b69a978a8b4de067ea829670f1ac3ca17cda74ba6407a85692ea4d759b730"
            },
            "downloads": -1,
            "filename": "DistributedLockCron-3.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2d16d22e849ba39c9a472d1b58abedbd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3752,
            "upload_time": "2025-01-07T12:04:51",
            "upload_time_iso_8601": "2025-01-07T12:04:51.766154Z",
            "url": "https://files.pythonhosted.org/packages/d8/63/b0aa837c5100134ef4f16de5403e74b50d1c9e584f4fa2999b5acbd5f635/DistributedLockCron-3.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe54f117c0ece50e5b36494f9c9a4101b76431d7aeda69ec8f7d5fea6d815dfd",
                "md5": "8a32d4155990d1b27fac53feb97ce65f",
                "sha256": "3e108e2de87f66e42a928999072b9fe95957abe5f391190bd200f3090a0111a3"
            },
            "downloads": -1,
            "filename": "distributedlockcron-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8a32d4155990d1b27fac53feb97ce65f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3557,
            "upload_time": "2025-01-07T12:04:55",
            "upload_time_iso_8601": "2025-01-07T12:04:55.693590Z",
            "url": "https://files.pythonhosted.org/packages/fe/54/f117c0ece50e5b36494f9c9a4101b76431d7aeda69ec8f7d5fea6d815dfd/distributedlockcron-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-07 12:04:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "distributedlockcron"
}
        
Elapsed time: 0.40155s