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 Copy linkLink copied to clipboard!
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.
bin/cli.sh
bin/cli.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the
connectcommand and enter your username and password when prompted. 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 Copy linkLink copied to clipboard!
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, Data Grid throws an exception. 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 file names.
Distributed caches
XML
JSON
YAML
Replicated caches
XML
JSON
YAML
Multiple caches
XML
JSON
YAML
2.2. Modifying Data Grid cache configuration Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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.
2.7. Set a Stable Topology Copy linkLink copied to clipboard!
By default, after a cluster shutdown, Data Grid waits for all nodes to join the cluster and restore the topology. However, we offer a CLI command to mark the current topology stable for a specific cache.
Procedure
- Create a CLI connection to Data Grid.
Do one of the following:
Set the current topology as stable for the given cache.
topology set-stable cacheName
topology set-stable cacheNameCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the current topology is missing more nodes than the number of owners, the force flag is necessary to confirm the operation.
topology set-stable cacheName -f
topology set-stable cacheName -fCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information about the topology set-stable command, run topology set-stable -h.
Manually installing a topology can lead to data loss, only perform this operation if the initial topology cannot be recreated.