Starting from 1.8.0, Apache Ignite introduced Redis protocol support and implemented a set of commands. Now, one can store and retrieve data in the grid using any Redis client.
In this article, we will see how to make connections to an Ignite cluster and do some Redis string operations.
Currently, the scope of the supported commands is limited mostly to Redis string operations, but more commands are planned to be introduced in future.
Apache Ignite has very rich functionalities for handling data in the grid using Java, C++, and C#, so let's choose a Python client and perform some string operations.
First of all, we need to have an Ignite cluster (or a single instance, if you have just started with the grid) running. By default, each Ignite node is listening for incoming requests on [host]:11211, but you can easily switch to Redis default port by overriding Ignite's ConnectorConfiguration as follows:
<bean class="org.apache.ignite.configuration.IgniteConfiguration"> ... <property name="connectorConfiguration"> <bean class="org.apache.ignite.configuration.ConnectorConfiguration"> <property name="host" value="localhost"/> <property name="port" value="6379"/> </bean> </property> </bean>
To connect to the cluster, let's pick redis-py and have it properly installed as described here. After getting into Python interpreter, we are ready to connect:
>>> import redis >>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
As it was already mentioned above, the current Redis support scope is strings, as they are the most versatile and frequently used data type in Redis and have many commands. As a very simple demonstration, let's use INCR and INCRBY command to perform very simple counting — this can be page views, votes, likes, etc.
>>> r.incr('p1') 1 >>> r.incr('p1') 2 >>> r.incrby('p2', 5) 5
For the full list of supported commands, see this link.
That's all for now. Apache Ignite community welcomes your suggestions and contributions to improving Redis protocol support!