@@ -119,38 +119,16 @@ class Format(str, Enum):
119
119
120
120
class Client :
121
121
__redis = None
122
- __format : str = Format .RESP .value
123
122
124
123
def __init__ (self , url : str ) -> None :
125
124
self .url = url
126
125
self .__redis = None
127
- self .__format = Format .RESP .value
128
-
129
- async def force_json (self ) -> None :
130
- """Force the OUTPUT to JSON
131
-
132
- When a new connection is established
133
- the on_connect callback makes sure to reset the
134
- OUTPUT to RESP.
135
- This method makes sure to enforce the OUTPUT to
136
- JSON on any consecutive command using the connection.
137
- """
138
- if self .__format == Format .JSON .value :
139
- return
140
-
141
- await self .__execute_and_read_response (
142
- Command .OUTPUT .value , [Format .JSON .value ]
143
- )
144
- self .__format = Format .JSON .value
145
126
146
127
async def __on_connect (self , connection : redis .Connection ):
147
- """On connect callback to set OUTPUT to RESP
148
-
149
- That way we can keep track of the OUTPUT set
150
- for the connection.
151
- """
128
+ """On connect callback to set OUTPUT to JSON"""
152
129
await connection .on_connect ()
153
- self .__format = Format .RESP .value
130
+ await connection .send_command (Command .OUTPUT , Format .JSON )
131
+ await connection .read_response ()
154
132
155
133
async def __delete_response_callbacks (self ):
156
134
"""Delete response callbacks in redis-py
@@ -194,7 +172,6 @@ async def __execute_and_read_response(
194
172
return await r .execute_command (command , * command_args )
195
173
196
174
async def command (self , command : str , command_args : CommandArgs = []) -> Dict :
197
- await self .force_json ()
198
175
response = await self .__execute_and_read_response (command , command_args )
199
176
200
177
return parse_response (response )
@@ -210,6 +187,5 @@ async def quit(self) -> str:
210
187
await c .connection_pool .disconnect ()
211
188
212
189
self .__redis = None
213
- self .__format = Format .RESP .value
214
190
215
191
return "OK"
0 commit comments