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

clean up how errors are returned

Changeset 80ff910c8ff5

Parent 4e30762c5ca3

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at 80ff910c8ff5 Showing diff from parent 4e30762c5ca3 Diff from another changeset...

Change 1 of 6 Show Entire File miniredis.py Stacked
 
16
17
18
19
20
21
22
23
24
25
 
28
29
30
31
 
 
32
33
34
 
83
84
85
86
 
87
88
89
 
102
103
104
105
 
106
107
108
 
111
112
113
114
 
115
116
117
 
244
245
246
247
 
248
249
250
 
16
17
18
 
 
 
 
19
20
21
 
24
25
26
 
27
28
29
30
31
 
80
81
82
 
83
84
85
86
 
99
100
101
 
102
103
104
105
 
108
109
110
 
111
112
113
114
 
241
242
243
 
244
245
246
247
@@ -16,10 +16,6 @@
  def __repr__(self):   return '<RedisError(%s)>' % self.message   -class RedisBadValueError(RedisError): - def __init__(self): - super(RedisBadValueError, self).__init__('Operation against a key holding the wrong kind of value') -  class RedisConstant(object):   def __init__(self, type):   self.type = type @@ -28,7 +24,8 @@
  return '<RedisConstant(%s)>' % self.type    EMPTY_SCALAR = RedisConstant('EmptyScalar') -EMPTY_ARRAY = RedisConstant('EmptyArray') +EMPTY_LIST = RedisConstant('EmptyList') +BAD_VALUE = RedisError('Operation against a key holding the wrong kind of value')      class RedisClient(object): @@ -83,7 +80,7 @@
  def handle_get(self, client, key):   data = client.table.get(key, None)   if isinstance(data, list): - return RedisBadValueError() + return BAD_VALUE   if data != None:   data = str(data)   else: @@ -102,7 +99,7 @@
  if key not in client.table:   client.table[key] = []   elif not isinstance(client.table[key], list): - return RedisBadValueError() + return BAD_VALUE   client.table[key].insert(0, data)   self.log(client, 'LPUSH %s %s' % (key, data))   return True @@ -111,7 +108,7 @@
  if key not in client.table:   return EMPTY_SCALAR   if not isinstance(client.table[key], list): - return RedisBadValueError() + return BAD_VALUE   if len(client.table[key]) > 0:   data = client.table[key].pop()   else: @@ -244,7 +241,7 @@
  # Show nothing for a false return; that means be quiet   elif o == EMPTY_SCALAR:   client.wfile.write('$-1\r\n') - elif o == EMPTY_ARRAY: + elif o == EMPTY_LIST:   client.wfile.write('*-1\r\n')   elif isinstance(o, int):   client.wfile.write(':' + str(o) + nl)