base context for wrappers updated
This commit is contained in:
@@ -77,12 +77,7 @@ class RedisActions:
|
||||
time=expiry_time,
|
||||
value=redis_row.value,
|
||||
)
|
||||
redis_row.expires_at = (
|
||||
arrow.now()
|
||||
.shift(seconds=expiry_time)
|
||||
.format(MainConfig.DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
redis_row.expires_at = str(arrow.now().shift(seconds=expiry_time).format(MainConfig.DATETIME_FORMAT))
|
||||
else:
|
||||
redis_cli.set(name=redis_row.redis_key, value=redis_row.value)
|
||||
|
||||
@@ -115,7 +110,6 @@ class RedisActions:
|
||||
list_of_rows = []
|
||||
regex = RedisRow.regex(list_keys=list_keys)
|
||||
json_get = redis_cli.scan_iter(match=regex)
|
||||
|
||||
for row in list(json_get):
|
||||
redis_row = RedisRow()
|
||||
redis_row.set_key(key=row)
|
||||
@@ -123,11 +117,16 @@ class RedisActions:
|
||||
redis_value = redis_cli.get(redis_row.redis_key)
|
||||
redis_row.feed(redis_value)
|
||||
list_of_rows.append(redis_row)
|
||||
|
||||
if list_of_rows:
|
||||
return RedisResponse(
|
||||
status=True,
|
||||
message="Value is get successfully.",
|
||||
data=list_of_rows,
|
||||
)
|
||||
return RedisResponse(
|
||||
status=True,
|
||||
message="Value is get successfully.",
|
||||
data=list_of_rows,
|
||||
status=False,
|
||||
message="Value is not get successfully.",
|
||||
data=list_of_rows
|
||||
)
|
||||
except Exception as e:
|
||||
return RedisResponse(
|
||||
@@ -135,3 +134,4 @@ class RedisActions:
|
||||
message="Value is not get successfully.",
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class RedisRow:
|
||||
# Filter and convert valid keys
|
||||
valid_keys = []
|
||||
for key in list_keys:
|
||||
if key is None:
|
||||
if key is None or str(key) == "None":
|
||||
continue
|
||||
if isinstance(key, bytes):
|
||||
key = key.decode()
|
||||
@@ -108,7 +108,8 @@ class RedisRow:
|
||||
# Add wildcard if first key was None
|
||||
if list_keys[0] is None:
|
||||
pattern = f"*{cls.delimiter}{pattern}"
|
||||
|
||||
if '*' not in pattern:
|
||||
pattern = f"{pattern}:*"
|
||||
return pattern
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -47,4 +47,7 @@ class RedisResponse:
|
||||
|
||||
@property
|
||||
def first(self) -> Union[RedisRow, None]:
|
||||
return self.data[0] if self.data else None
|
||||
if self.data:
|
||||
return self.data[0]
|
||||
self.status = False
|
||||
return
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, Literal
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, validator
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
|
||||
class AccessToken(BaseModel):
|
||||
|
||||
accessToken: Optional[str] = None
|
||||
userUUID: Optional[str] = None
|
||||
userUUID: Optional[str | UUID] = None
|
||||
|
||||
@validator("userUUID", pre=True)
|
||||
@field_validator("userUUID", mode="after")
|
||||
def validate_uuid(cls, v):
|
||||
"""Convert UUID to string during validation."""
|
||||
if isinstance(v, UUID):
|
||||
return str(v)
|
||||
return v
|
||||
if v is None:
|
||||
return None
|
||||
return str(v)
|
||||
|
||||
def to_list(self):
|
||||
"""Convert to list for Redis storage."""
|
||||
return [self.accessToken, self.userUUID]
|
||||
return [self.accessToken, str(self.userUUID) if self.userUUID else None]
|
||||
|
||||
@property
|
||||
def count(self):
|
||||
|
||||
Reference in New Issue
Block a user