Resetting utils subtree.

This commit is contained in:
2025-06-12 10:53:48 +05:30
parent 94a254474c
commit 65cceb1a5a
169 changed files with 58 additions and 136755 deletions
+132
View File
@@ -0,0 +1,132 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 19th Sept., 2024
OBJECTIVE:
To provide a quick way to test out Redis.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# System-level:
import os
# Utils:
from utils_v2.string import json
from utils_v2.date_time import date_time
from utils_v2.cache.async_redis_cache_v3 import AsyncRedisCache
# For async activities:
import asyncio
# Common:
from shared import constants
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
async def main():
print("Connecting...")
my_cache = AsyncRedisCache(
sentinel_json = json.from_string(input("Sentinel JSON String: ")),
ping_counter = 100,
debug = False
)
await my_cache.connect()
print("Connected!", end = "\n\n")
value = await my_cache.get(key = "name")
print("GET:", value)
print("TYP:", type(value), end = "\n\n")
success = await my_cache.set(
key = "name",
value = {"first": "John", "last": "Doe"},
expiry = 10
)
print("SET:", success, end = "\n\n")
value = await my_cache.get(key = "name")
print("GET:", value)
print("TYP:", type(value), end = "\n\n")
success = await my_cache.delete(key = "name")
print("DEL:", success, end = "\n\n")
value = await my_cache.get(key = "cnt")
print("GET:", value)
print("TYP:", type(value), end = "\n\n")
await my_cache.delete(key = "cnt")
for _ in range(50):
await asyncio.sleep(1.0)
counter = await my_cache.count(key = "cnt", value = 1, expiry = 10)
print("COUNTER:", counter)
asyncio.run(main())
+2 -2
View File
@@ -41,7 +41,7 @@ import os
# Utils:
from utils_v2.string import json
from utils_v2.date_time import date_time
from utils_v2.cache.async_redis_cache import AsyncRedisCache
from utils_v2.cache.async_redis_cache_v3 import AsyncRedisCache
# For async activities:
import asyncio
@@ -93,7 +93,7 @@ if __name__ == "__main__":
print("Connecting...")
my_cache = AsyncRedisCache(
connection_string = r"redis://:dc4da94197c843ab6a730113c2b801d9@192.168.2.251/0",
connection_string = input("Connection String: "),
ping_counter = 100,
debug = False
)