Skip to content

Commit 3c7fbaa

Browse files
JSON.TOGGLE
1 parent 5e25a8f commit 3c7fbaa

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ 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+
rj.jsonset('bool', Path.rootPath(), False)
87+
self.assertTrue(rj.jsontoggle('bool', Path.rootPath()))
88+
8589
def testStrAppendShouldSucceed(self):
8690
"Test JSONStrAppend"
8791

0 commit comments

Comments
 (0)