Skip to content

Commit

Permalink
Add __getitem__ functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
zachwill committed Jun 19, 2012
1 parent 621c210 commit 817de75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions simplest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from core import Redis
25 changes: 25 additions & 0 deletions simplest/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Simple core functionality.
"""

from redis import StrictRedis


class Redis(StrictRedis):
"""A Redis class with sugary goodness."""

def __getitem__(self, name):
"""Easy access to items in the database."""
data_type = self.type(name)
if data_type == 'string':
return self.get(name)
elif data_type == 'hash':
return self.hgetall(name)
elif data_type == 'list':
return self.lrange(name, 0, -1)
elif data_type == 'set':
return self.smembers(name)
elif data_type == 'zset':
return self.zrange(name, 0, -1)
else:
return None

0 comments on commit 817de75

Please sign in to comment.