Skip to main content

CLI 工具利用 Redis 锁定模式管理云中的分布式应用程序

项目描述

为什么选择 LockR?

  • 管理云中的任何应用程序:
    • 它旨在成为一个非常通用的 CLI 工具,为应用程序提供分布式锁定机制,以防止同时运行的应用程序的重复实例

    • 如果您想防止多个应用程序实例同时运行,则可用于各种应用程序(Flask 应用程序、Spring Boot 应用程序、Celery 工作人员等)。

  • 极其容错:
    • LockR旨在对网络错误、应用程序问题等具有弹性。所以你只需要担心你自己的应用程序。

  • 使用简单:
    • LockR非常易于使用和维护

  • 没有第三方依赖:
    • LockR完全使用内置的 python 库构建,不依赖任何第三方库。

入门

使用pip安装

pip install lockr

然后,您需要一个配置文件来告诉lockr要做什么。它通常称为lockr.ini,但可以是任何名称,也可以是任何名称,只要它可读且格式正确。

要查找使用说明,请运行:

lockr --help
lockr run --help

一般配置如下所示:

# LockR default configuration file
[lockr]
# LockR timeout in milliseconds. Higher values mean it will take longer before a
# downed node is recognized, lower values mean more Redis traffic.
timeout = 1000
# defaults to 1000

# Name of the lock. If empty, generated from the command. Defaults to 'lockr'
lockname = test-lockr

# Command to execute. This is the process you want to start up. MUST BE SPECIFIED
# Examples are: Flask app, celery worker , anything which you don't want to run on more than one node at a time
command = "echo 'test lockr'"


# Whether or not to run command in shell. Defaults to 'no'
use_shell = no

# Specify any custom lock prefix for the lock value stored in key 'lockname'
# Defaults to 'LockR'. Accepts environment variables as well
lock_prefix = test-prefix

[redis]
# defaults to localhost. Specify environment variable or pass directly as well. Conflicts with 'cluster_nodes' (only one can be specified).
host = ${REDIS_HOST}

# Specify all the cluster nodes each in new line. Conflicts with 'host' (only one can be specified).
# Currently only works with environment variables
# The nodes must have cluster mode enabled
cluster_nodes = ${REDIS_HOST}:${REDIS_HOST}

# port is optional and defaults to 6379. Specify environment variable or pass directly as well
port = ${REDIS_HOST}

# In single Redis server mode only, you can SELECT the database. Defaults to 0. Ignored for cluster_nodes
database = 1

所有默认参数都是可选的,如果没有指定,则采用默认值。建议不要更新它们,除非您想微调您的lockr实例。

然后运行:

lockr run --dry-run

如果您的配置文件有效,您应该会看到输出:

Valid configuration found. Dry run verification successful

确认文件有效后,运行:

lockr run

发展

LockRGitHub上可用

获得源代码后,您可以使用以下命令运行测试

pip install -r requirements.dev.txt
pytest tests/

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

lockr-0.0.8.tar.gz (4.3 kB 查看哈希

已上传 source

内置分布

lockr-0.0.8-py3-none-any.whl (9.3 kB 查看哈希

已上传 py3