Changeset a26998c1f7a8…
Parent 49f18d064f4d…
by Benjamin Pollack
Changes to one file · Browse files at a26998c1f7a8 Showing diff from parent 49f18d064f4d Diff from another changeset...
@@ -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
|
Loading...