Public » MiniRedis Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

no more supporting Redis 1.0's busted protocol

Changeset fbfc6b3f6a09

Parent e5b3d2f39ae0

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at fbfc6b3f6a09 Showing diff from parent e5b3d2f39ae0 Diff from another changeset...

Change 1 of 2 Show Entire File miniredis.py Stacked
 
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
 
 
 
 
 
 
 
251
252
253
 
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
 
272
273
274
 
182
183
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
186
187
188
189
190
191
192
193
194
 
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200
201
202
@@ -182,72 +182,13 @@
  self.log(client, 'SAVE')   return True   - def handle_bgrewriteaof(self, client): - self.save() - self.log(client, 'BGREWRITEAOF') - return True - - def unwrap_set(self, client, line): - key, length = line.split() - data = client.rfile.read(int(length)) - client.rfile.read(2) # throw out newline - return self.handle_set(client, key, data) - - def unwrap_get(self, client, line): - key = line.strip() - return self.handle_get(client, key) - - def unwrap_del(self, client, line): - key = line.strip() - return self.handle_del(client, key) - - def unwrap_lpush(self, client, line): - key, length = line.split() - data = client.rfile.read(int(length)) - client.rfile.read(2) # throw out newline - return self.handle_lpush(client, key, data) - - def unwrap_lrange(self, client, line): - key, low, high = line.split() - return self.handle_lrange(client, key, low, high) - - def unwrap_rpop(self, client, line): - key = line.strip() - return self.handle_rpop(client, key) - - def unwrap_keys(self, client, line): - pattern = line.strip() - return self.handle_keys(client, pattern) - - def unwrap_incr(self, client, line): - key = line.strip() - return self.handle_incr(client, key) - - def unwrap_incrby(self, client, line): - key, by = line.split() - return self.handle_incrby(client, key, by) - - def unwrap_flushdb(self, client, line): - return self.handle_flushdb(client) - - def unwrap_select(self, client, line): - db = line.strip() - return self.handle_select(client, db) - - def unwrap_quit(self, client, line): - return self.handle_quit(client) - - def unwrap_save(self, client, line): - return self.handle_save(client) - - def unwrap_shutdown(self, client, line): - return self.handle_shutdown(client) - - def handle_normal(self, client, line): - command, _, rest = line.partition(' ') - return getattr(self, 'unwrap_' + command.strip().lower())(client, rest) - - def handle_multibulk(self, client, line): + def handle(self, client): + line = client.rfile.readline() + if not line: + self.log(client, 'client disconnected') + del self.clients[client.socket] + client.socket.close() + return   items = int(line[1:].strip())   args = []   for x in xrange(0, items): @@ -255,20 +196,7 @@
  args.append(client.rfile.read(length))   client.rfile.read(2) # throw out newline   command = args[0].lower() - return getattr(self, 'handle_' + command)(client, *args[1:]) - - def handle(self, client): - line = client.rfile.readline() - if not line: - self.log(client, 'client disconnected') - del self.clients[client.socket] - client.socket.close() - return - if line[0] == '*': - o = self.handle_multibulk(client, line) - else: - o = self.handle_normal(client, line) - self.dump(client, o) + self.dump(getattr(self, 'handle_' + command)(client, *args[1:]))     def dump(self, client, o):   nl = '\r\n'