Redis
Connect to Ignite using Redis compatible client.
This is a legacy Apache Ignite documentation
The new documentation is hosted here: https://ignite.apache.org/docs/latest/
Ignite is partially Redis compliant and enables users to store and retrieve distributed data from Apache Ignite caches using any Redis compatible client.
The following commands are supported by Ignite client:
Connection
String
- GET
- MGET (limitation: null values are not included in the query results for non-existing keys)
- SET
- MSET
- INCR
- DECR
- INCRBY
- DECRBY
- APPEND
- STRLEN
- GETSET
- SETRANGE
- GETRANGE
Keys
Server
Cluster nodes accept Redis requests listening on a particular socket. By default, each Ignite node is listening for incoming requests on [host]:11211
. You can override the host and port using ConnectorConfiguration
.
<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>
Configure default cache
You have to configure default
redis-ignite-internal-cache-0
cache that will be used as your default Redis database and also as a template for other databases you switch to with SELECT command.
You can connect to Ignite using your favorite Redis client. See basic examples for some languages below
Java
To connect to Ignite using a Java client for Redis, you need to have an Ignite cluster/node configured, if necessary, as shown above, and running.
To connect to Ignite running on port 6379
with, for instance, Jedis
JedisPoolConfig jedisPoolCfg = new JedisPoolConfig();
// your pool configurations.
JedisPool pool = new JedisPool(jedisPoolCfg, "localhost", 6379, 10000);
try (Jedis jedis = pool.getResource()) {
jedis.set("key1", "1");
System.out.println("Value for 'key1': " + jedis.get("key1"));
}
pool.destroy();
Python
To connect to Ignite using a Python client for Redis, you need to have an Ignite cluster/node configured, if necessary, as shown above and running.
To connect to Ignite running on port 6379
with, for instance, redis-py
>>> import redis
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
>>> r.set('k1', 1)
True
>>> r.get('k1')
'1'
PHP
To connect to Ignite using a PHP client for Redis, you need to have an Ignite cluster/node configured, if necessary, as shown above and running.
To connect to Ignite running on port 6379
with, for instance, predis
// Load the library.
require 'predis/autoload.php';
Predis\Autoloader::register();
// Connect.
try {
$redis = new Predis\Client();
echo ">>> Successfully connected to Redis. \n";
// Put entry to cache.
if ($redis->set('k1', '1'))
echo ">>> Successfully put entry in cache. \n";
// Check entry value.
echo(">>> Value for 'k1': " . $redis->get('k1') . "\n");
}
catch (Exception $e) {
echo "Couldn't connected to Redis";
echo $e->getMessage();
}
Updated 2 months ago