You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/12/05 12:38:44 UTC

[40/52] ignite git commit: Ignite-4243: Added a Python/PHP examples for Redis. - Fixes #1258.

Ignite-4243: Added a Python/PHP examples for Redis. - Fixes #1258.

Signed-off-by: shroman <rs...@yahoo.com>

(cherry picked from commit 9ec0a6f)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1073b2c1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1073b2c1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1073b2c1

Branch: refs/heads/master
Commit: 1073b2c14d68e252fb2970d489eab47f9a31d201
Parents: 99eb4e0
Author: shroman <rs...@yahoo.com>
Authored: Sat Nov 26 09:23:06 2016 +0700
Committer: Andrey Novikov <an...@gridgain.com>
Committed: Mon Nov 28 17:56:39 2016 +0700

----------------------------------------------------------------------
 examples/redis/redis-example.php | 82 +++++++++++++++++++++++++++++++++++
 examples/redis/redis-example.py  | 62 ++++++++++++++++++++++++++
 2 files changed, 144 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1073b2c1/examples/redis/redis-example.php
----------------------------------------------------------------------
diff --git a/examples/redis/redis-example.php b/examples/redis/redis-example.php
new file mode 100644
index 0000000..0054f16
--- /dev/null
+++ b/examples/redis/redis-example.php
@@ -0,0 +1,82 @@
+#!/bin/php
+
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * To execute this script, you need to have Predis extension installed and Ignite running.
+ * See https://github.com/nrk/predis for Predis details.
+ *
+ * See https://apacheignite.readme.io/ for more details on Redis integration.
+ */
+
+// Load the library.
+require 'predis/autoload.php';
+Predis\Autoloader::register();
+
+// Connect.
+try {
+    $redis = new Predis\Client(array(
+        "host" => "localhost",
+        "port" => 11211));
+
+    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");
+
+    // Change entry's value.
+    if ($redis->set('k1', 'new_value'))
+        echo ">>> Successfully put entry in cache. \n";
+
+    // Check entry value.
+    echo(">>> Value for 'k1': " . $redis->get('k1') . "\n");
+
+    // Put entry to cache.
+    if ($redis->set('k2', '2'))
+        echo ">>> Successfully put entry in cache. \n";
+
+    // Check entry value.
+    echo(">>> Value for 'k2': " . $redis->get('k2') . "\n");
+
+    // Get two entries.
+    $val = $redis->mget('k1', 'k2');
+    echo(">>> Value for 'k1' and 'k2': " . var_dump($val) . "\n");
+
+    // Delete on entry.
+    if ($redis->del('k1'))
+        echo ">>> Successfully deleted 'k1'. \n";
+
+    // Db size.
+    echo ">>> Db size: " . $redis->dbsize() . "\n";
+
+    // Increment.
+    echo ">>> Incremented: " . $redis->incr("inc_k") . "\n";
+
+    // Increment by 5.
+    echo ">>> Incremented: " . $redis->incrby("inc_k", 5) . "\n";
+}
+catch (Exception $e) {
+    echo ">>> Couldn't connected to Redis.";
+    echo $e->getMessage();
+}
+?>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1073b2c1/examples/redis/redis-example.py
----------------------------------------------------------------------
diff --git a/examples/redis/redis-example.py b/examples/redis/redis-example.py
new file mode 100644
index 0000000..15b847b
--- /dev/null
+++ b/examples/redis/redis-example.py
@@ -0,0 +1,62 @@
+'''
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+'''
+
+import redis
+'''
+To execute this, you will have redis-py installed and Ignite running.
+See https://github.com/andymccurdy/redis-py for the details on redis-py.
+
+See https://apacheignite.readme.io/ for more details on Redis integration.
+'''
+
+r = redis.StrictRedis(host='localhost', port=11211, db=0)
+
+# set entry.
+r.set('k1', 1)
+
+# check.
+print 'Value for "k1": %s' % r.get('k1')
+
+# change entry's value.
+r.set('k1', 'new_val')
+
+# check.
+print 'Value for "k1": %s' % r.get('k1')
+
+# set another entry.
+r.set('k2', 2)
+
+# check.
+print 'Value for "k2": %s' % r.get('k2')
+
+# get both values.
+print 'Values for "k1" and "k2": %s' % r.mget('k1', 'k2')
+
+# delete one entry.
+r.delete('k1')
+
+# check one entry left.
+print 'Values for "k1" and "k2": %s' % r.mget('k1', 'k2')
+
+# check db size
+print 'Db size: %d' % r.dbsize()
+
+# increment.
+print 'Value for incremented "inc_k" : %s' % r.incr('inc_k')
+
+# increment again.
+print 'Value for incremented "inc_k" : %s' % r.incr('inc_k')