Module: Valkey::Commands::JsonCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/json_commands.rb
Overview
This module contains commands related to RedisJSON / Valkey JSON.
Instance Method Summary collapse
-
#json_arrappend(key, path, *values) ⇒ Array<Integer>
Append values to JSON array at path.
-
#json_arrindex(key, path, value, start = nil, stop = nil) ⇒ Array<Integer>
Get index of value in JSON array.
-
#json_arrinsert(key, path, index, *values) ⇒ Array<Integer>
Insert values into JSON array at index.
-
#json_arrlen(key, path = nil) ⇒ Array<Integer, nil>
Get length of JSON array at path.
-
#json_arrpop(key, path = nil, index = nil) ⇒ Array<String, nil>
Pop element from JSON array.
-
#json_arrtrim(key, path, start, stop) ⇒ Array<Integer>
Trim JSON array to specified range.
-
#json_clear(key, path = nil) ⇒ Integer
Clear container values at path.
-
#json_debug(subcommand, key, path = nil) ⇒ Object
Get debug information about JSON value.
-
#json_del(key, path = nil) ⇒ Integer
Delete JSON value at path.
-
#json_forget(key, path = nil) ⇒ Integer
Alias for json_del (deprecated).
-
#json_get(key, *paths) ⇒ String?
Get JSON value at path.
-
#json_mget(*keys_and_path) ⇒ Array<String, nil>
Get multiple JSON values.
-
#json_numincrby(key, path, value) ⇒ String
Increment number at path.
-
#json_nummultby(key, path, value) ⇒ String
Multiply number at path.
-
#json_objkeys(key, path = nil) ⇒ Array<Array<String>>
Get keys of JSON object at path.
-
#json_objlen(key, path = nil) ⇒ Array<Integer, nil>
Get number of keys in JSON object at path.
-
#json_resp(key, path = nil) ⇒ Object
Get JSON value in RESP format.
-
#json_set(key, path, value) ⇒ String
Set JSON value at path.
-
#json_strappend(key, path, value) ⇒ Array<Integer>
Append string to JSON string at path.
-
#json_strlen(key, path = nil) ⇒ Array<Integer, nil>
Get length of JSON string at path.
-
#json_toggle(key, path) ⇒ Array<Integer>
Toggle boolean value at path.
-
#json_type(key, path = nil) ⇒ Array<String>
Get the type of JSON value at path.
Instance Method Details
#json_arrappend(key, path, *values) ⇒ Array<Integer>
Append values to JSON array at path.
189 190 191 |
# File 'lib/valkey/commands/json_commands.rb', line 189 def json_arrappend(key, path, *values) send_command(RequestType::JSON_ARR_APPEND, [key, path] + values) end |
#json_arrindex(key, path, value, start = nil, stop = nil) ⇒ Array<Integer>
Get index of value in JSON array.
207 208 209 210 211 212 |
# File 'lib/valkey/commands/json_commands.rb', line 207 def json_arrindex(key, path, value, start = nil, stop = nil) args = [key, path, value] args << start.to_s if start args << stop.to_s if stop send_command(RequestType::JSON_ARR_INDEX, args) end |
#json_arrinsert(key, path, index, *values) ⇒ Array<Integer>
Insert values into JSON array at index.
227 228 229 |
# File 'lib/valkey/commands/json_commands.rb', line 227 def json_arrinsert(key, path, index, *values) send_command(RequestType::JSON_ARR_INSERT, [key, path, index.to_s] + values) end |
#json_arrlen(key, path = nil) ⇒ Array<Integer, nil>
Get length of JSON array at path.
242 243 244 245 246 |
# File 'lib/valkey/commands/json_commands.rb', line 242 def json_arrlen(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_ARR_LEN, args) end |
#json_arrpop(key, path = nil, index = nil) ⇒ Array<String, nil>
Pop element from JSON array.
263 264 265 266 267 268 |
# File 'lib/valkey/commands/json_commands.rb', line 263 def json_arrpop(key, path = nil, index = nil) args = [key] args << path if path args << index.to_s if index send_command(RequestType::JSON_ARR_POP, args) end |
#json_arrtrim(key, path, start, stop) ⇒ Array<Integer>
Trim JSON array to specified range.
283 284 285 |
# File 'lib/valkey/commands/json_commands.rb', line 283 def json_arrtrim(key, path, start, stop) send_command(RequestType::JSON_ARR_TRIM, [key, path, start.to_s, stop.to_s]) end |
#json_clear(key, path = nil) ⇒ Integer
Clear container values at path.
332 333 334 335 336 |
# File 'lib/valkey/commands/json_commands.rb', line 332 def json_clear(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_CLEAR, args) end |
#json_debug(subcommand, key, path = nil) ⇒ Object
Get debug information about JSON value.
365 366 367 368 369 |
# File 'lib/valkey/commands/json_commands.rb', line 365 def json_debug(subcommand, key, path = nil) args = [subcommand, key] args << path if path send_command(RequestType::JSON_DEBUG, args) end |
#json_del(key, path = nil) ⇒ Integer
Delete JSON value at path.
62 63 64 65 66 |
# File 'lib/valkey/commands/json_commands.rb', line 62 def json_del(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_DEL, args) end |
#json_forget(key, path = nil) ⇒ Integer
Alias for json_del (deprecated).
75 76 77 78 79 |
# File 'lib/valkey/commands/json_commands.rb', line 75 def json_forget(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_FORGET, args) end |
#json_get(key, *paths) ⇒ String?
Get JSON value at path.
24 25 26 27 |
# File 'lib/valkey/commands/json_commands.rb', line 24 def json_get(key, *paths) args = [key] + paths send_command(RequestType::JSON_GET, args) end |
#json_mget(*keys_and_path) ⇒ Array<String, nil>
Get multiple JSON values.
91 92 93 |
# File 'lib/valkey/commands/json_commands.rb', line 91 def json_mget(*keys_and_path) send_command(RequestType::JSON_MGET, keys_and_path) end |
#json_numincrby(key, path, value) ⇒ String
Increment number at path.
124 125 126 |
# File 'lib/valkey/commands/json_commands.rb', line 124 def json_numincrby(key, path, value) send_command(RequestType::JSON_NUM_INCR_BY, [key, path, value.to_s]) end |
#json_nummultby(key, path, value) ⇒ String
Multiply number at path.
140 141 142 |
# File 'lib/valkey/commands/json_commands.rb', line 140 def json_nummultby(key, path, value) send_command(RequestType::JSON_NUM_MULT_BY, [key, path, value.to_s]) end |
#json_objkeys(key, path = nil) ⇒ Array<Array<String>>
Get keys of JSON object at path.
298 299 300 301 302 |
# File 'lib/valkey/commands/json_commands.rb', line 298 def json_objkeys(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_OBJ_KEYS, args) end |
#json_objlen(key, path = nil) ⇒ Array<Integer, nil>
Get number of keys in JSON object at path.
315 316 317 318 319 |
# File 'lib/valkey/commands/json_commands.rb', line 315 def json_objlen(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_OBJ_LEN, args) end |
#json_resp(key, path = nil) ⇒ Object
Get JSON value in RESP format.
382 383 384 385 386 |
# File 'lib/valkey/commands/json_commands.rb', line 382 def json_resp(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_RESP, args) end |
#json_set(key, path, value) ⇒ String
Set JSON value at path.
44 45 46 |
# File 'lib/valkey/commands/json_commands.rb', line 44 def json_set(key, path, value) send_command(RequestType::JSON_SET, [key, path, value]) end |
#json_strappend(key, path, value) ⇒ Array<Integer>
Append string to JSON string at path.
156 157 158 |
# File 'lib/valkey/commands/json_commands.rb', line 156 def json_strappend(key, path, value) send_command(RequestType::JSON_STR_APPEND, [key, path, value]) end |
#json_strlen(key, path = nil) ⇒ Array<Integer, nil>
Get length of JSON string at path.
171 172 173 174 175 |
# File 'lib/valkey/commands/json_commands.rb', line 171 def json_strlen(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_STR_LEN, args) end |
#json_toggle(key, path) ⇒ Array<Integer>
Toggle boolean value at path.
349 350 351 |
# File 'lib/valkey/commands/json_commands.rb', line 349 def json_toggle(key, path) send_command(RequestType::JSON_TOGGLE, [key, path]) end |
#json_type(key, path = nil) ⇒ Array<String>
Get the type of JSON value at path.
106 107 108 109 110 |
# File 'lib/valkey/commands/json_commands.rb', line 106 def json_type(key, path = nil) args = [key] args << path if path send_command(RequestType::JSON_TYPE, args) end |