Skip to content

Commit 6de9a10

Browse files
JSON.TOGGLE
1 parent 5e25a8f commit 6de9a10

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

rejson/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
5656
'JSON.SET': lambda r: r and nativestr(r) == 'OK',
5757
'JSON.NUMINCRBY': self._decode,
5858
'JSON.NUMMULTBY': self._decode,
59+
'JSON.TOGGLE': bool,
5960
'JSON.STRAPPEND': long,
6061
'JSON.STRLEN': long,
6162
'JSON.ARRAPPEND': long,
@@ -166,6 +167,13 @@ def jsonnummultby(self, name, path, number):
166167
"""
167168
return self.execute_command('JSON.NUMMULTBY', name, str_path(path), self._encode(number))
168169

170+
def jsontoggle(self, name, path=Path.rootPath()):
171+
"""
172+
Toggle boolean value under ``path`` at key ``name``,
173+
Returning the new value.
174+
"""
175+
return self.execute_command('JSON.TOGGLE', name, str_path(path))
176+
169177
def jsonstrappend(self, name, string, path=Path.rootPath()):
170178
"""
171179
Appends to the string JSON value under ``path`` at key ``name`` the

tests/test_rejson.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def testNumMultByShouldSucceed(self):
8282
self.assertEqual(5, rj.jsonnummultby('num', Path.rootPath(), 2.5))
8383
self.assertEqual(2.5, rj.jsonnummultby('num', Path.rootPath(), 0.5))
8484

85+
def testToggle(self):
86+
"Test JSONToggle"
87+
88+
rj.jsonset('bool', Path.rootPath(), False)
89+
self.assertTrue(rj.jsontoggle('bool', Path.rootPath()))
90+
8591
def testStrAppendShouldSucceed(self):
8692
"Test JSONStrAppend"
8793

0 commit comments

Comments
 (0)