MCPcopy
hub / github.com/benoitc/gunicorn / StashClient

Class StashClient

gunicorn/dirty/stash.py:90–331  ·  gunicorn/dirty/stash.py::StashClient

Client for stash operations. Communicates with the arbiter which stores all tables in memory.

Source from the content-addressed store, hash-verified

88
89
90class StashClient:
91 class="st">"""
92 Client for stash operations.
93
94 Communicates with the arbiter which stores all tables in memory.
95 class="st">"""
96
97 def __init__(self, socket_path, timeout=30.0):
98 class="st">"""
99 Initialize the stash client.
100
101 Args:
102 socket_path: Path to the dirty arbiter&class="cm">#x27;s Unix socket
103 timeout: Default timeout for operations in seconds
104 class="st">"""
105 self.socket_path = socket_path
106 self.timeout = timeout
107 self._sock = None
108 self._lock = threading.Lock()
109
110 def _get_request_id(self):
111 class="st">""class="st">"Generate a unique request ID."class="st">""
112 return str(uuid.uuid4())
113
114 def _connect(self):
115 class="st">""class="st">"Establish connection to arbiter."class="st">""
116 import socket
117 if self._sock is not None:
118 return
119
120 try:
121 self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
122 self._sock.settimeout(self.timeout)
123 self._sock.connect(self.socket_path)
124 except (socket.error, OSError) as e:
125 self._sock = None
126 raise StashError(fclass="st">"Failed to connect to arbiter: {e}") from e
127
128 def _close(self):
129 class="st">""class="st">"Close the connection."class="st">""
130 if self._sock is not None:
131 try:
132 self._sock.close()
133 except Exception:
134 pass
135 self._sock = None
136
137 def _execute(self, op, table, key=None, value=None, pattern=None):
138 class="st">"""
139 Execute a stash operation.
140
141 Args:
142 op: Operation code (STASH_OP_*)
143 table: Table name
144 key: Optional key
145 value: Optional value
146 pattern: Optional pattern for keys operation
147

Callers 1

_get_clientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected