a function that recieve the key and redis connection string and then: 1. check if key doesnt exist then to create this key with value 0 2. …
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redis_init_zero-2025.9.13174.tar.gz.
File metadata
- Download URL: redis_init_zero-2025.9.13174.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8d7c9ccea42240e6674720e93a25df1cb91fda2552306a21c79c0634f43652d
|
|
| MD5 |
a0ba16fc13b57012e1abbc763c436b3f
|
|
| BLAKE2b-256 |
4189b8adf3067797c72dfca1408686bb3634763d1cfef8453e2c9e24ec7d7a33
|
File details
Details for the file redis_init_zero-2025.9.13174-py3-none-any.whl.
File metadata
- Download URL: redis_init_zero-2025.9.13174-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf2d38b38a56059d5d3da71edf4698d636e5a32b998fcd97905340dfc2a76093
|
|
| MD5 |
faec6769df5513a7e60eb9a4df5aa6fb
|
|
| BLAKE2b-256 |
f66cd99fab2e01297eb083fc6093c20ce10f825eeeda99de44d918c5c7a097ee
|