此内容没有您所选择的语言版本。
Chapter 3. Performing Cache Operations with the Data Grid CLI
The command line interface (CLI) lets you remotely connect to Data Grid servers to access data and perform administrative functions.
Prerequisites
- Start the Data Grid CLI.
- Connect to a running Data Grid cluster.
3.1. Creating Caches from Templates 复制链接链接已复制到粘贴板!
Use Data Grid cache templates to add caches with recommended default settings.
Procedure
Create a distributed, synchronous cache from a template and name it "mycache".
[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycache
[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipPress the tab key after the
--template=argument to list available cache templates.Retrieve the cache configuration.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2. Creating Caches from XML or JSON Files 复制链接链接已复制到粘贴板!
Add caches with custom Data Grid configuration in XML or JSON format.
Procedure
-
Add the path to your configuration file with the
--file=option as follows:
[//containers/default]> create cache --file=prod_dist_cache.xml dist_cache_01
[//containers/default]> create cache --file=prod_dist_cache.xml dist_cache_01
3.2.1. XML Configuration 复制链接链接已复制到粘贴板!
Data Grid configuration in XML format must conform to the schema and include:
-
<infinispan>root element. -
<cache-container>definition.
Example XML Configuration
3.2.2. JSON Configuration 复制链接链接已复制到粘贴板!
Data Grid configuration in JSON format:
- Requires the cache definition only.
Must follow the structure of an XML configuration.
- XML elements become JSON objects.
- XML attributes become JSON fields.
Example JSON Configuration
3.3. Adding Cache Entries 复制链接链接已复制到粘贴板!
Add data to caches with the Data Grid CLI.
Prerequisites
Create a cache named "mycache" and
cdinto it.[//containers/default]> cd caches/mycache
[//containers/default]> cd caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Put an entry into "mycache".
[//containers/default/caches/mycache]> put hello world
[//containers/default/caches/mycache]> put hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipIf not in the context of a cache, use the
--cache=parameter. For example:[//containers/default]> put --cache=mycache hello world
[//containers/default]> put --cache=mycache hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow Get the entry to verify it.
[//containers/default/caches/mycache]> get hello world
[//containers/default/caches/mycache]> get hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.4. Clearing Caches and Deleting Entries 复制链接链接已复制到粘贴板!
Remove data from caches with the Data Grid CLI.
Procedure
Clear caches. This command deletes all entries from a cache.
[//containers/default]> clearcache mycache
[//containers/default]> clearcache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove specific entries from a cache.
[//containers/default]> remove --cache=mycache hello
[//containers/default]> remove --cache=mycache helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.5. Deleting Caches 复制链接链接已复制到粘贴板!
Drop caches to remove them and delete all data they contain.
Procedure
Remove caches with the drop command.
[//containers/default]> drop cache mycache
[//containers/default]> drop cache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow