Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 2. Performing Cache Operations with the Data Grid CLI
Use the command line interface (CLI) to perform operations on remote caches such as creating caches, manipulating data, and rebalancing.
2.1. Creating remote caches with the Data Grid CLI Copier lienLien copié sur presse-papiers!
Use the Data Grid Command Line Interface (CLI) to add remote caches on Data Grid Server.
Prerequisites
-
Create a Data Grid user with
adminpermissions. - Start at least one Data Grid Server instance.
- Have a Data Grid cache configuration.
Procedure
Start the CLI and enter your credentials when prompted.
bin/cli.sh
bin/cli.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
create cachecommand to create remote caches.For example, create a cache named "mycache" from a file named
mycache.xmlas follows:create cache --file=mycache.xml mycache
create cache --file=mycache.xml mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all remote caches with the
lscommand.ls caches mycache
ls caches mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow View cache configuration with the
describecommand.describe caches/mycache
describe caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.1.1. Cache configuration Copier lienLien copié sur presse-papiers!
You can create declarative cache configuration in XML, JSON, and YAML format.
All declarative caches must conform to the Data Grid schema. Configuration in JSON format must follow the structure of an XML configuration, elements correspond to objects and attributes correspond to fields.
Data Grid restricts characters to a maximum of 255 for a cache name or a cache template name. If you exceed this character limit, the Data Grid server might abruptly stop without issuing an exception message. Write succinct cache names and cache template names.
A file system might set a limitation for the length of a file name, so ensure that a cache’s name does not exceed this limitation. If a cache name exceeds a file system’s naming limitation, general operations or initialing operations towards that cache might fail. Write succinct cache names and cache template names.
Distributed caches
XML
JSON
YAML
Replicated caches
XML
JSON
YAML
Multiple caches
XML
YAML
JSON
2.2. Modifying Data Grid cache configuration Copier lienLien copié sur presse-papiers!
Make changes to your remote cache configuration with the Data Grid CLI. You can modify attributes in your cache configuration either one at a time or provide a cache configuration in XML, JSON or YAML format to modify several attributes at once.
Prerequisites
- Create at least one remote cache on your Data Grid cluster.
Procedure
- Create a CLI connection to Data Grid.
Modify the cache configuration with the
altercommand in one of the following ways:-
Use the
--fileoption to specify a configuration file with one or more attribute modifications. Use the
--attributeand--valueoption to modify a specific configuration attribute.TipFor more information and examples, run the
help altercommand.
-
Use the
Verify your changes with the
describecommand, for example:describe caches/mycache
describe caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. 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
--cache=with theputcommand:put --cache=mycache hello world
put --cache=mycache hello worldCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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
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.4. 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.clearcache mycache
clearcache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove specific entries with the
removecommand.remove --cache=mycache hello
remove --cache=mycache helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5. 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.drop cache mycache
drop cache mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6. Configuring Automatic Cache Rebalancing Copier lienLien copié sur presse-papiers!
By default, Data Grid automatically rebalances caches as nodes join and leave the cluster. You can configure automatic cache rebalancing by disabling or enabling it at the Cache Manager level or on a per-cache basis.
Procedure
- Create a CLI connection to Data Grid.
Disable automatic rebalancing for all caches with the
rebalance disablecommand.rebalance disable
rebalance disableCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable automatic rebalancing for a specific cache with the
rebalance enablecommand.The following example enables rebalancing for the cache named "mycache" only.
rebalance enable caches/mycache
rebalance enable caches/mycacheCopy to Clipboard Copied! Toggle word wrap Toggle overflow Re-enable automatic rebalancing for all caches.
rebalance enable
rebalance enableCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information about the rebalance command, run help rebalance.