RedisJSON 命令¶
这些是与 RedisJSON 模块 交互的命令。下面是一个简短的示例,以及命令本身的文档。
创建一个 json 对象
import redis
r = redis.Redis()
r.json().set("mykey", ".", {"hello": "world", "i am": ["a", "json", "object!"]})
有关如何结合搜索和 json 的示例可在 此处 找到。
- class redis.commands.json.commands.JSONCommands[源代码]¶
json commands.
- arrappend(name, path='.', *args)[源代码]¶
Append the objects
argsto the array under thepath` in key ``name.For more information see JSON.ARRAPPEND..
- 参数:
name (str)
path (str | None)
args (List[str | int | float | bool | None | Dict[str, Any] | List[Any]])
- 返回类型:
List[int | None]
- arrindex(name, path, scalar, start=None, stop=None)[源代码]¶
Return the index of
scalarin the JSON array underpathat keyname.The search can be limited using the optional inclusive
startand exclusivestopindices.For more information see JSON.ARRINDEX.
- 参数:
name (str)
path (str)
scalar (int)
start (int | None)
stop (int | None)
- 返回类型:
List[int | None]
- arrinsert(name, path, index, *args)[源代码]¶
Insert the objects
argsto the array at indexindexunder thepath` in key ``name.For more information see JSON.ARRINSERT.
- 参数:
name (str)
path (str)
index (int)
args (List[str | int | float | bool | None | Dict[str, Any] | List[Any]])
- 返回类型:
List[int | None]
- arrlen(name, path='.')[源代码]¶
Return the length of the array JSON value under
pathat key``name``.For more information see JSON.ARRLEN.
- 参数:
name (str)
path (str | None)
- 返回类型:
List[int | None]
- arrpop(name, path='.', index=-1)[源代码]¶
Pop the element at
indexin the array JSON value underpathat keyname.For more information see JSON.ARRPOP.
- 参数:
name (str)
path (str | None)
index (int | None)
- 返回类型:
List[str | None]
- arrtrim(name, path, start, stop)[源代码]¶
Trim the array JSON value under
pathat keynameto the inclusive range given bystartandstop.For more information see JSON.ARRTRIM.
- 参数:
name (str)
path (str)
start (int)
stop (int)
- 返回类型:
List[int | None]
- clear(name, path='.')[源代码]¶
Empty arrays and objects (to have zero slots/keys without deleting the array/object).
Return the count of cleared paths (ignoring non-array and non-objects paths).
For more information see JSON.CLEAR.
- 参数:
name (str)
path (str | None)
- 返回类型:
int
- debug(subcommand, key=None, path='.')[源代码]¶
Return the memory usage in bytes of a value under
pathfrom keyname.For more information see JSON.DEBUG.
- 参数:
subcommand (str)
key (str | None)
path (str | None)
- 返回类型:
int | List[str]
- delete(key, path='.')[源代码]¶
Delete the JSON value stored at key
keyunderpath.For more information see JSON.DEL.
- 参数:
key (str)
path (str | None)
- 返回类型:
int
- forget(key, path='.')¶
Delete the JSON value stored at key
keyunderpath.For more information see JSON.DEL.
- 参数:
key (str)
path (str | None)
- 返回类型:
int
- get(name, *args, no_escape=False)[源代码]¶
Get the object stored as a JSON value at key
name.argsis zero or more paths, and defaults to root path`no_escapeis a boolean flag to add no_escape option to get non-ascii charactersFor more information see JSON.GET.
- 参数:
name (str)
no_escape (bool | None)
- 返回类型:
List[str | int | float | bool | None | Dict[str, Any] | List[Any]] | None
- merge(name, path, obj, decode_keys=False)[源代码]¶
Merges a given JSON value into matching paths. Consequently, JSON values at matching paths are updated, deleted, or expanded with new children
decode_keysIf set to True, the keys ofobjwill be decoded with utf-8.For more information see JSON.MERGE.
- 参数:
name (str)
path (str)
obj (str | int | float | bool | None | Dict[str, Any] | List[Any])
decode_keys (bool | None)
- 返回类型:
str | None
- mget(keys, path)[源代码]¶
Get the objects stored as a JSON values under
path.keysis a list of one or more keys.For more information see JSON.MGET.
- 参数:
keys (List[str])
path (str)
- 返回类型:
List[str | int | float | bool | None | Dict[str, Any] | List[Any]]
- mset(triplets)[源代码]¶
Set the JSON value at key
nameunder thepathtoobjfor one or more keys.tripletsis a list of one or more triplets of key, path, value.For the purpose of using this within a pipeline, this command is also aliased to JSON.MSET.
For more information see JSON.MSET.
- 参数:
triplets (List[Tuple[str, str, str | int | float | bool | None | Dict[str, Any] | List[Any]]])
- 返回类型:
str | None
- numincrby(name, path, number)[源代码]¶
Increment the numeric (integer or floating point) JSON value under
pathat keynameby the providednumber.For more information see JSON.NUMINCRBY.
- 参数:
name (str)
path (str)
number (int)
- 返回类型:
str
- nummultby(name, path, number)[源代码]¶
Multiply the numeric (integer or floating point) JSON value under
pathat keynamewith the providednumber.For more information see JSON.NUMMULTBY.
- 参数:
name (str)
path (str)
number (int)
- 返回类型:
str
- objkeys(name, path='.')[源代码]¶
Return the key names in the dictionary JSON value under
pathat keyname.For more information see JSON.OBJKEYS.
- 参数:
name (str)
path (str | None)
- 返回类型:
List[List[str] | None]
- objlen(name, path='.')[源代码]¶
Return the length of the dictionary JSON value under
pathat keyname.For more information see JSON.OBJLEN.
- 参数:
name (str)
path (str | None)
- 返回类型:
List[int | None]
- resp(name, path='.')[源代码]¶
Return the JSON value under
pathat keyname.For more information see JSON.RESP.
- 参数:
name (str)
path (str | None)
- 返回类型:
List
- set(name, path, obj, nx=False, xx=False, decode_keys=False)[源代码]¶
Set the JSON value at key
nameunder thepathtoobj.nxif set to True, setvalueonly if it does not exist.xxif set to True, setvalueonly if it exists.decode_keysIf set to True, the keys ofobjwill be decoded with utf-8.For the purpose of using this within a pipeline, this command is also aliased to JSON.SET.
For more information see JSON.SET.
- 参数:
name (str)
path (str)
obj (str | int | float | bool | None | Dict[str, Any] | List[Any])
nx (bool | None)
xx (bool | None)
decode_keys (bool | None)
- 返回类型:
str | None
- set_file(name, path, file_name, nx=False, xx=False, decode_keys=False)[源代码]¶
Set the JSON value at key
nameunder thepathto the content of the json filefile_name.nxif set to True, setvalueonly if it does not exist.xxif set to True, setvalueonly if it exists.decode_keysIf set to True, the keys ofobjwill be decoded with utf-8.- 参数:
name (str)
path (str)
file_name (str)
nx (bool | None)
xx (bool | None)
decode_keys (bool | None)
- 返回类型:
str | None
- set_path(json_path, root_folder, nx=False, xx=False, decode_keys=False)[源代码]¶
Iterate over
root_folderand set each JSON file to a value underjson_pathwith the file name as the key.nxif set to True, setvalueonly if it does not exist.xxif set to True, setvalueonly if it exists.decode_keysIf set to True, the keys ofobjwill be decoded with utf-8.- 参数:
json_path (str)
root_folder (str)
nx (bool | None)
xx (bool | None)
decode_keys (bool | None)
- 返回类型:
Dict[str, bool]
- strappend(name, value, path='.')[源代码]¶
Append to the string JSON value. If two options are specified after the key name, the path is determined to be the first. If a single option is passed, then the root_path (i.e Path.root_path()) is used.
For more information see JSON.STRAPPEND.
- 参数:
name (str)
value (str)
path (str | None)
- 返回类型:
int | List[int | None]
- strlen(name, path=None)[源代码]¶
Return the length of the string JSON value under
pathat keyname.For more information see JSON.STRLEN.
- 参数:
name (str)
path (str | None)
- 返回类型:
List[int | None]
- toggle(name, path='.')[源代码]¶
Toggle boolean value under
pathat keyname. returning the new value.For more information see JSON.TOGGLE.
- 参数:
name (str)
path (str | None)
- 返回类型:
bool | List[int | None]