Skip to content

Commit b72bfe0

Browse files
JSON.DEBUG
1 parent e88b59e commit b72bfe0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

rejson/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
6767
'JSON.ARRPOP': self._decode,
6868
'JSON.ARRTRIM': long,
6969
'JSON.OBJLEN': long,
70+
'JSON.DEBUG': long,
7071
}
7172
for k, v in six.iteritems(MODULE_CALLBACKS):
7273
self.set_response_callback(k, v)
@@ -260,6 +261,12 @@ def jsonobjlen(self, name, path=Path.rootPath()):
260261
"""
261262
return self.execute_command('JSON.OBJLEN', name, str_path(path))
262263

264+
def jsondebugmemory(self, name, path=Path.rootPath()):
265+
"""
266+
Returns the memory usage in bytes of a value under ``path`` from key ``name``.
267+
"""
268+
return self.execute_command("JSON.DEBUG", "MEMORY", name, str_path(path))
269+
263270
def pipeline(self, transaction=True, shard_hint=None):
264271
"""
265272
Return a new pipeline object that can queue multiple commands for

tests/test_rejson.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ def testObjLenShouldSucceed(self):
174174
rj.jsonset('obj', Path.rootPath(), obj)
175175
self.assertEqual(len(obj), rj.jsonobjlen('obj', Path.rootPath()))
176176

177+
def testDebugMemoryShouldSucceed(self):
178+
"Test JSONDebug"
179+
180+
rj.jsonset('str', Path.rootPath(), 'foo')
181+
self.assertEqual(24, rj.jsondebugmemory('str', Path.rootPath()))
182+
177183
def testPipelineShouldSucceed(self):
178184
"Test pipeline"
179185

0 commit comments

Comments
 (0)