Skip to content

Commit

Permalink
fix: command stats and response
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Apr 6, 2021
1 parent 2454033 commit 06e4df6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pyle38/follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ async def server_extended(self) -> ServerStatsExtendedResponse:
)

async def stats(self, *keys: List[str]) -> StatsResponse:
return StatsResponse(**(await self.client.command(Command.STATS, *keys)))
response = await self.client.command(Command.STATS, *keys)

if response["stats"] == [None]:
response["stats"] = []

return StatsResponse(**response)

async def quit(self) -> str:

Expand Down
4 changes: 2 additions & 2 deletions pyle38/leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async def delete(self, key: str, id: str) -> JSONResponse:
async def drop(self, key: str) -> JSONResponse:
return JSONResponse(**(await self.client.command(Command.DROP, [key])))

async def flushdb(self) -> dict:
return await self.client.command("FLUSHDB")
async def flushdb(self) -> JSONResponse:
return JSONResponse(**(await self.client.command("FLUSHDB")))

async def expire(self, key: str, id: str, seconds: int) -> JSONResponse:
return JSONResponse(
Expand Down
6 changes: 4 additions & 2 deletions pyle38/responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Any
from typing import Dict
from typing import Generic
from typing import List
Expand Down Expand Up @@ -32,6 +31,9 @@ class JSONResponse(BaseModel):
elapsed: str
err: Optional[str] = None

class Config:
exclude_unset = True


class Object(GenericModel, Generic[T]):
object: T
Expand Down Expand Up @@ -136,7 +138,7 @@ class Stats(BaseModel):


class StatsResponse(JSONResponse):
stats: List[Union[Stats, Any]]
stats: Optional[List[Stats]] = []


class ServerStatsLeader(BaseModel):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_command_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
async def test_command_stats(tile38_with_follower):
tile38 = tile38_with_follower

response = await tile38.stats(["fleet"])
assert response.ok
assert response.stats == []

await tile38.set("fleet", "truck1").point(1, 1).exec()
await tile38.set("zones", "parking1").bounds(1, 1, 1, 1).exec()

Expand Down

0 comments on commit 06e4df6

Please sign in to comment.