C++ Hot Rod Client: Getting Started
What You Will Learn
How to connect a C++ Hot Rod client to an Infinispan Server and perform basic cache operations: put, get, and print values.
Prerequisites
-
C++11 compatible compiler
-
CMake 2.6+
-
Infinispan C++ Hot Rod client library (
libhotrod) -
An Infinispan Server running on
127.0.0.1:11222
Step 1: Configure the Client
Create a ConfigurationBuilder and add the server connection:
ConfigurationBuilder builder;
builder.addServer().host("127.0.0.1").port(11222);
Step 2: Connect and Perform Cache Operations
Initialize the RemoteCacheManager, get a cache, and store and retrieve a value:
RemoteCacheManager cacheManager(builder.build(), false);
RemoteCache<std::string, std::string> cache =
cacheManager.getCache<std::string, std::string>("default", false);
cacheManager.start();
cache.put("key", "value");
std::cout << "key = " << *cache.get("key") << std::endl;
cacheManager.stop();
Step 3: Build and Run
Build the project with CMake:
mkdir build && cd build
cmake ..
make
./simple
You should see output like:
key = value


