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

support BGSAVE and SAVE properly

Changeset a26998c1f7a8

Parent 49f18d064f4d

by Profile picture of Benjamin PollackBenjamin Pollack

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

Change 1 of 5 Show Entire File miniredis.py Stacked
 
16
17
18
19
20
21
22
23
24
25
26
27
28
 
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
 
81
82
83
84
85
 
 
86
87
88
 
171
172
173
 
 
 
 
 
 
 
 
 
 
174
175
176
 
286
287
288
289
290
291
292
293
294
 
295
296
297
 
16
17
18
 
 
 
 
 
 
 
19
20
21
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
95
96
97
 
 
98
99
100
101
102
 
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
 
310
311
312
 
 
 
 
 
 
313
314
315
316
@@ -16,13 +16,6 @@
   from collections import deque   -class RedisError(object): - def __init__(self, message): - self.message = message - - def __repr__(self): - return '<RedisError(%s)>' % self.message -  class RedisConstant(object):   def __init__(self, type):   self.type = type @@ -30,6 +23,27 @@
  def __repr__(self):   return '<RedisConstant(%s)>' % self.type   +class RedisMessage(object): + def __init__(self, message): + self.message = message + + def __str__(self): + return '+%s' % self.message + + def __repr__(self): + return '<RedisMessage(%s)>' % self.message + +class RedisError(RedisMessage): + def __init__(self, message): + self.message = message + + def __str__(self): + return '-ERR %s' % self.message + + def __repr__(self): + return '<RedisError(%s)>' % self.message + +  EMPTY_SCALAR = RedisConstant('EmptyScalar')  EMPTY_LIST = RedisConstant('EmptyList')  BAD_VALUE = RedisError('Operation against a key holding the wrong kind of value') @@ -81,8 +95,8 @@
  client.wfile.write('*' + str(len(o)) + nl)   for val in o:   self.dump(client, str(val)) - elif isinstance(o, RedisError): - client.wfile.write('-ERR %s\r\n' % o.message) + elif isinstance(o, RedisMessage): + client.wfile.write('%s\r\n' % o)   else:   client.wfile.write('return type not yet implemented\r\n')   client.wfile.flush() @@ -171,6 +185,16 @@
    # HANDLERS   + def handle_bgsave(self, client): + if hasattr(os, 'fork'): + if not os.fork(): + self.save() + sys.exit(0) + else: + self.save() + self.log(client, 'BGSAVE') + return RedisMessage('Background saving started') +   def handle_del(self, client, key):   self.log(client, 'DEL %s' % key)   if key not in client.table: @@ -286,12 +310,7 @@
  return False     def handle_save(self, client): - if hasattr(os, 'fork'): - if not os.fork(): - self.save() - sys.exit(0) - else: - self.save() + self.save()   self.log(client, 'SAVE')   return True