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

add llen, lpop, rpush commands

Changeset 49f18d064f4d

Parent 0e4f23777124

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at 49f18d064f4d Showing diff from parent 0e4f23777124 Diff from another changeset...

Change 1 of 2 Show Entire File miniredis.py Stacked
 
217
218
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
221
222
 
250
251
252
 
 
 
 
 
 
 
 
 
253
254
255
 
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
 
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
@@ -217,6 +217,25 @@
  self.log(client, 'KEYS %s' % pattern)   return ' '.join(k for k in client.table.keys() if r.search(k))   + def handle_llen(self, client, key): + if key not in client.table: + return 0 + if not isinstance(client.table[key], deque): + return BAD_VALUE + return len(client.table[key]) + + def handle_lpop(self, client, key): + if key not in client.table: + return EMPTY_SCALAR + if not isinstance(client.table[key], deque): + return BAD_VALUE + if len(client.table[key]) > 0: + data = client.table[key].popleft() + else: + data = EMPTY_SCALAR + self.log(client, 'LPOP %s -> %s' % (key, data)) + return data +   def handle_lpush(self, client, key, data):   if key not in client.table:   client.table[key] = deque() @@ -250,6 +269,15 @@
  self.log(client, 'RPOP %s -> %s' % (key, data))   return data   + def handle_rpush(self, client, key, data): + if key not in client.table: + client.table[key] = deque() + elif not isinstance(client.table[key], deque): + return BAD_VALUE + client.table[key].append(data) + self.log(client, 'RPUSH %s %s' % (key, data)) + return True +   def handle_quit(self, client):   client.socket.shutdown(socket.SHUT_RDWR)   client.socket.close()