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
keyexists. - If the key does not exist, it sets the key's value to
0and returnsTrue. - 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)
| File | Size | Uploaded | |
|---|---|---|---|
| redis_init_zero-2025.9.13174.tar.gz | 2.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|