Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- added ability for subclasses of Redis to provide their own decode l…
…ogic if desired.

- setup.py needed to specify the package rather than py_module in order for build to work correctly.
  • Loading branch information
andymccurdy committed Feb 16, 2010
1 parent 3b05b78 commit 62fd846
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions redis/client.py
Expand Up @@ -254,6 +254,8 @@ def parse_response(self, command_name, **options):
response = self._parse_response(command_name)
if command_name in self.RESPONSE_CALLBACKS:
return self.RESPONSE_CALLBACKS[command_name](response, **options)
elif isinstance(response, str):
return self.decode(response)
return response

def encode(self, value):
Expand All @@ -265,6 +267,10 @@ def encode(self, value):
# not a string or unicode, attempt to convert to a string
return str(value)

def decode(self, value):
"Provides a hook for subclasses to add deserialization logic"
return value

def format_inline(self, *args, **options):
"Formats a request with the inline protocol"
cmd = '%s\r\n' % ' '.join([self.encode(a) for a in args])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -22,7 +22,7 @@
'maintainer_email' : 'sedrik@gmail.com',
'keywords' : ['Redis', 'key-value store'],
'license' : 'MIT',
'py_modules' : ['redis'],
'packages' : ['redis'],
'test_suite' : 'tests.all_tests',
'classifiers' : [
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 62fd846

Please sign in to comment.