Skip to content
Browse files

Added support for OBJECT command.

  • Loading branch information...
1 parent 72facec commit 4d89fb2b0298d43fb74885dbfa993d2656cf040c @rlotun rlotun committed Sep 21, 2011
Showing with 41 additions and 3 deletions.
  1. +26 −3 txredis/protocol.py
  2. +15 −0 txredis/test/test_redis.py
View
29 txredis/protocol.py
@@ -97,6 +97,8 @@ class InvalidResponse(RedisError):
class InvalidData(RedisError):
pass
+class InvalidCommand(RedisError):
+ pass
class RedisBase(protocol.Protocol, policies.TimeoutMixin, object):
"""The main Redis client."""
@@ -553,9 +555,30 @@ def get_type(self, key):
Determine the type stored at key
"""
self._send('TYPE', key)
- res = self.getResponse()
- # return None if res == 'none' else res
- return res
+ return self.getResponse()
+
+ def get_object(self, key, refcount=False, encoding=False, idletime=False):
+ """
+ Inspect the internals of Redis objects.
+ @param key : The Redis key you want to inspect
+ @param refcount : Returns the number of refereces of the value
+ associated with the specified key.
+ @param encoding : Returns the kind of internal representation for value.
+ @param idletime Returns the number of seconds since the object stored
+ at the specified key is idle. (Currently the actual
+ resolution is 10 seconds.)
+ """
+ subcommand = ''
+ if idletime:
+ subcommand = 'IDLETIME'
+ elif encoding:
+ subcommand = 'ENCODING'
+ elif refcount:
+ subcommand = 'REFCOUNT'
+ if not subcommand:
+ raise InvalidCommand('Need a subcommand')
+ self._send('OBJECT', subcommand, key)
+ return self.getResponse()
# Commands operating on the key space
def keys(self, pattern):
View
15 txredis/test/test_redis.py
@@ -128,6 +128,21 @@ def test_delete(self):
t(a, ex)
@defer.inlineCallbacks
+ def test_get_object(self):
+ r = self.redis
+ t = self.assertEqual
+ a = yield r.set('obj', 1)
+ ex = 'OK'
+ t(a, ex)
+
+ a = yield r.get_object('obj', idletime=True)
+ self.assertEqual(type(a), int)
+
+ a = yield r.get_object('obj', encoding=True)
+ ex = 'int'
+ t(a, ex)
+
+ @defer.inlineCallbacks
def test_get_type(self):
r = self.redis
t = self.assertEqual

0 comments on commit 4d89fb2

Please sign in to comment.
Something went wrong with that request. Please try again.