Skip to main content

PyPI version License: MIT Downloads LinkedIn

redis_init_zero

A Python package to initialize a Redis key with a value of 0 if the key does not already exist.

Installation

To install redis_init_zero, use pip:

pip install redis_init_zero

Usage

Using redis_init_zero is straightforward. You need to provide the Redis connection string and the key you want to initialize.

from redis_init_zero import initialize_key_if_not_exists

# Replace with your actual Redis connection string
REDIS_CONNECTION_STRING = "redis://localhost:6379/0"
KEY_TO_INITIALIZE = "my_counter"

# Initialize the key if it doesn't exist
was_initialized = initialize_key_if_not_exists(REDIS_CONNECTION_STRING, KEY_TO_INITIALIZE)

if was_initialized:
    print(f"Key '{KEY_TO_INITIALIZE}' was initialized to 0.")
else:
    print(f"Key '{KEY_TO_INITIALIZE}' already exists.")

# Example demonstrating it only initializes once
was_initialized_again = initialize_key_if_not_exists(REDIS_CONNECTION_STRING, KEY_TO_INITIALIZE)
if not was_initialized_again:
    print(f"Key '{KEY_TO_INITIALIZE}' was not re-initialized.")

Functionality

  • initialize_key_if_not_exists(redis_connection_string: str, key: str) -> bool:
    • Connects to the Redis server using the provided connection string.
    • Checks if the specified key exists.
    • If the key does not exist, it sets the key's value to 0 and returns True.
    • If the key already exists, it does nothing and returns False.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

redis_init_zero is licensed under the MIT License.

Author

Eugene Evstafev hi@eugene.plus

Metadata

Release files for redis-init-zero 2025.9.13174

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redis-init-zero 2025.9.13174
File Size Uploaded
redis_init_zero-2025.9.13174.tar.gz 2.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redis-init-zero 2025.9.13174
File Interpreter ABI Platform
redis_init_zero-2025.9.13174-py3-none-any.whl Python 3 none any Details

Total release size: 5.4 kB

Release files / redis_init_zero-2025.9.13174.tar.gz

Download URL redis_init_zero-2025.9.13174.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b8d7c9ccea42240e6674720e93a25df1cb91fda2552306a21c79c0634f43652d
BLAKE2b-256 checksum
How to use checksums
4189b8adf3067797c72dfca1408686bb3634763d1cfef8453e2c9e24ec7d7a33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / redis_init_zero-2025.9.13174-py3-none-any.whl

Download URL redis_init_zero-2025.9.13174-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf2d38b38a56059d5d3da71edf4698d636e5a32b998fcd97905340dfc2a76093
BLAKE2b-256 checksum
How to use checksums
f66cd99fab2e01297eb083fc6093c20ce10f825eeeda99de44d918c5c7a097ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2025.9.13174 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page