add memory_client.py
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Memory Client implementation.
|
||||
|
||||
This module provides a simple client that interacts with the MemoryServer via a local function call interface. In real deployments, this could be replaced with network communication (e.g., gRPC or HTTP).
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
from memory_server import MemoryServer
|
||||
|
||||
class MemoryClient:
|
||||
"""A thin wrapper around MemoryServer.
|
||||
|
||||
The client holds a reference to a :class:`MemoryServer` instance and forwards operations.
|
||||
"""
|
||||
|
||||
def __init__(self, server: MemoryServer) -> None:
|
||||
self._server = server
|
||||
|
||||
def set(self, key: str, value: Any) -> None:
|
||||
self._server.set(key, value)
|
||||
|
||||
def get(self, key: str) -> Any:
|
||||
return self._server.get(key)
|
||||
|
||||
def delete(self, key: str) -> None:
|
||||
self._server.delete(key)
|
||||
|
||||
# Simple demo when run as a script
|
||||
if __name__ == "__main__":
|
||||
srv = MemoryServer()
|
||||
cli = MemoryClient(srv)
|
||||
cli.set("bar", [1, 2, 3])
|
||||
print(cli.get("bar"))
|
||||
Reference in New Issue
Block a user