updated Postgres Service

This commit is contained in:
2025-04-01 17:30:40 +03:00
parent 6b9e9050a2
commit 4c87c4df91
18 changed files with 745 additions and 368 deletions

View File

@@ -1,5 +1,5 @@
from typing import Dict, List, Optional
from database import RedisActions
from Controllers.Redis.database import RedisActions
def example_set_json() -> None:
"""Example of setting JSON data in Redis with and without expiry."""
@@ -7,48 +7,48 @@ def example_set_json() -> None:
data = {"name": "John", "age": 30, "city": "New York"}
keys = ["user", "profile", "123"]
result = RedisActions.set_json(list_keys=keys, value=data)
print("Set JSON without expiry:", result)
print("Set JSON without expiry:", result.as_dict())
# Example 2: Set JSON with expiry
expiry = {"hours": 1, "minutes": 30}
result = RedisActions.set_json(list_keys=keys, value=data, expires=expiry)
print("Set JSON with expiry:", result)
print("Set JSON with expiry:", result.as_dict())
def example_get_json() -> None:
"""Example of retrieving JSON data from Redis."""
# Example 1: Get all matching keys
keys = ["user", "profile", "*"]
result = RedisActions.get_json(list_keys=keys)
print("Get all matching JSON:", result)
print("Get all matching JSON:", result.as_dict())
# Example 2: Get with limit
result = RedisActions.get_json(list_keys=keys, limit=5)
print("Get JSON with limit:", result)
print("Get JSON with limit:", result.as_dict())
def example_get_json_iterator() -> None:
"""Example of using the JSON iterator for large datasets."""
keys = ["user", "profile", "*"]
for row in RedisActions.get_json_iterator(list_keys=keys):
print("Iterating over JSON row:", row)
print("Iterating over JSON row:", row.as_dict if isinstance(row.as_dict, dict) else row.as_dict())
def example_delete_key() -> None:
"""Example of deleting a specific key."""
key = "user:profile:123"
result = RedisActions.delete_key(key)
print("Delete specific key:", result)
def example_delete() -> None:
"""Example of deleting multiple keys matching a pattern."""
keys = ["user", "profile", "*"]
result = RedisActions.delete(list_keys=keys)
print("Delete multiple keys:", result)
# def example_delete_key() -> None:
# """Example of deleting a specific key."""
# key = "user:profile:123"
# result = RedisActions.delete_key(key)
# print("Delete specific key:", result)
#
# def example_delete() -> None:
# """Example of deleting multiple keys matching a pattern."""
# keys = ["user", "profile", "*"]
# result = RedisActions.delete(list_keys=keys)
# print("Delete multiple keys:", result)
def example_refresh_ttl() -> None:
"""Example of refreshing TTL for a key."""
key = "user:profile:123"
new_expiry = {"hours": 2, "minutes": 0}
result = RedisActions.refresh_ttl(key=key, expires=new_expiry)
print("Refresh TTL:", result)
print("Refresh TTL:", result.as_dict())
def example_key_exists() -> None:
"""Example of checking if a key exists."""
@@ -58,9 +58,10 @@ def example_key_exists() -> None:
def example_resolve_expires_at() -> None:
"""Example of resolving expiry time for a key."""
from base import RedisRow
from Controllers.Redis.base import RedisRow
redis_row = RedisRow()
redis_row.redis_key = "user:profile:123"
redis_row.set_key("user:profile:123")
print(redis_row.keys)
expires_at = RedisActions.resolve_expires_at(redis_row)
print("Resolve expires at:", expires_at)
@@ -77,11 +78,11 @@ def run_all_examples() -> None:
print("\n3. Using JSON iterator:")
example_get_json_iterator()
print("\n4. Deleting specific key:")
example_delete_key()
print("\n5. Deleting multiple keys:")
example_delete()
# print("\n4. Deleting specific key:")
# example_delete_key()
#
# print("\n5. Deleting multiple keys:")
# example_delete()
print("\n6. Refreshing TTL:")
example_refresh_ttl()