Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 2. 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.
2.1. Creating Caches with the Data Grid Command Line Interface (CLI) Copier lienLien copié sur presse-papiers!
Use the Data Grid CLI to add caches from templates or configuration files in XML or JSON format.
Prerequisites
Create a user and start at least one Data Grid server instance.
Procedure
- Create a CLI connection to Data Grid.
Add cache definitions with the
create cachecommand.Add a cache definition from an XML or JSON file with the
--fileoption.[//containers/default]> create cache --file=configuration.xml mycache
[//containers/default]> create cache --file=configuration.xml mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a cache definition from a template with the
--templateoption.[//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.
Verify the cache exists with the
lscommand.[//containers/default]> ls caches mycache
[//containers/default]> ls caches mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the cache configuration with the
describecommand.[//containers/default]> describe caches/mycache
[//containers/default]> describe caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.1.1. XML Configuration Copier lienLien copié sur presse-papiers!
Data Grid configuration in XML format must conform to the schema and include:
-
<infinispan>root element. -
<cache-container>definition.
Example XML Configuration
2.1.2. JSON Configuration Copier lienLien copié sur presse-papiers!
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
2.2. Adding Cache Entries Copier lienLien copié sur presse-papiers!
Create key:value pair entries in the data container.
Prerequisites
Create a Data Grid cache that can store your data.
Procedure
- Create a CLI connection to Data Grid.
Add entries into your cache as follows:
Use the
putcommand from the context of a cache:[//containers/default/caches/mycache]> put hello world
[//containers/default/caches/mycache]> put hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
--cache=with theputcommand:[//containers/default]> put --cache=mycache hello world
[//containers/default]> put --cache=mycache hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Use the
getcommand to verify entries.[//containers/default/caches/mycache]> get hello world
[//containers/default/caches/mycache]> get hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Clearing Caches and Deleting Entries Copier lienLien copié sur presse-papiers!
Remove data from caches with the Data Grid CLI.
Procedure
- Create a CLI connection to Data Grid.
Do one of the following:
Delete all entries with the
clearcachecommand.[//containers/default]> clearcache mycache
[//containers/default]> clearcache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove specific entries with the
removecommand.[//containers/default]> remove --cache=mycache hello
[//containers/default]> remove --cache=mycache helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Deleting Caches Copier lienLien copié sur presse-papiers!
Drop caches to remove them and delete all data they contain.
Procedure
- Create a CLI connection to Data Grid.
Remove caches with the
dropcommand.[//containers/default]> drop cache mycache
[//containers/default]> drop cache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow