diff options
author | Itamar Haber <itamar@redislabs.com> | 2018-11-09 16:09:30 +0200 |
---|---|---|
committer | Itamar Haber <itamar@redislabs.com> | 2018-11-09 16:09:30 +0200 |
commit | b7d718054cbec4e4609312c96d25d08049685dfd (patch) | |
tree | ac3260ed256ddb6cd0fe7176e04eafe4d6c748bc /redis/client.py | |
parent | e9d48c9b93b489519608b8a2c4a988d431022617 (diff) | |
download | redis-py-b7d718054cbec4e4609312c96d25d08049685dfd.tar.gz |
Adds the memory_usage and memory_purge commands
Signed-off-by: Itamar Haber <itamar@redislabs.com>
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index d82078e..c6a8e4b 100755 --- a/redis/client.py +++ b/redis/client.py @@ -495,6 +495,8 @@ class StrictRedis(object): 'HSCAN': parse_hscan, 'INFO': parse_info, 'LASTSAVE': timestamp_to_datetime, + 'MEMORY PURGE': bool_ok, + 'MEMORY USAGE': int_or_none, 'OBJECT': parse_object, 'PING': lambda r: nativestr(r) == 'PONG', 'PUBSUB NUMSUB': parse_pubsub_numsub, @@ -895,6 +897,24 @@ class StrictRedis(object): "Return the encoding, idletime, or refcount about the key" return self.execute_command('OBJECT', infotype, key, infotype=infotype) + def memory_usage(self, key, samples=None): + """ + Return the total memory usage for key, its value and associated + administrative overheads. + + For nested data structures, ``samples`` is the number of elements to + sample. If left unspecified, the server's default is 5. Use 0 to sample + all elements. + """ + args = [] + if isinstance(samples, int): + args.extend([Token.get_token('SAMPLES'), samples]) + return self.execute_command('MEMORY USAGE', key, *args) + + def memory_purge(self): + "Attempts to purge dirty pages for reclamation by allocator" + return self.execute_command('MEMORY PURGE') + def ping(self): "Ping the Redis server" return self.execute_command('PING') |