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

switch from lists to deques for internal lists

Changeset 0e4f23777124

Parent 8ed3c53a7ef9

by Profile picture of Benjamin PollackBenjamin Pollack

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

Change 1 of 4 Show Entire File miniredis.py Stacked
 
14
15
16
 
 
17
18
19
 
189
190
191
192
 
193
194
195
 
217
218
219
220
221
 
 
222
223
 
224
225
226
 
230
231
232
233
 
234
235
236
 
 
 
237
238
239
240
241
 
242
243
244
245
246
247
 
248
249
250
 
14
15
16
17
18
19
20
21
 
191
192
193
 
194
195
196
197
 
219
220
221
 
 
222
223
224
 
225
226
227
228
 
232
233
234
 
235
236
 
 
237
238
239
240
241
242
243
 
244
245
246
247
248
249
 
250
251
252
253
@@ -14,6 +14,8 @@
 import socket  import sys   +from collections import deque +  class RedisError(object):   def __init__(self, message):   self.message = message @@ -189,7 +191,7 @@
    def handle_get(self, client, key):   data = client.table.get(key, None) - if isinstance(data, list): + if isinstance(data, deque):   return BAD_VALUE   if data != None:   data = str(data) @@ -217,10 +219,10 @@
    def handle_lpush(self, client, key, data):   if key not in client.table: - client.table[key] = [] - elif not isinstance(client.table[key], list): + client.table[key] = deque() + elif not isinstance(client.table[key], deque):   return BAD_VALUE - client.table[key].insert(0, data) + client.table[key].appendleft(data)   self.log(client, 'LPUSH %s %s' % (key, data))   return True   @@ -230,21 +232,22 @@
  high = None   if key not in client.table:   return EMPTY_LIST - if not isinstance(client.table[key], list): + if not isinstance(client.table[key], deque):   return BAD_VALUE - self.log(client, 'LRANGE %s %s %s -> %s' % (key, low, high, client.table[key][low:high])) - return client.table[key][low:high] + l = list(client.table[key])[low:high] + self.log(client, 'LRANGE %s %s %s -> %s' % (key, low, high, l)) + return l     def handle_rpop(self, client, key):   if key not in client.table:   return EMPTY_SCALAR - if not isinstance(client.table[key], list): + if not isinstance(client.table[key], deque):   return BAD_VALUE   if len(client.table[key]) > 0:   data = client.table[key].pop()   else:   data = EMPTY_SCALAR - self.log(client, 'LPOP %s -> %s' % (key, data)) + self.log(client, 'RPOP %s -> %s' % (key, data))   return data     def handle_quit(self, client):