home ~ previous

REDIS

Example 1

The first example will be a simple one.

We will be writing to redis from a 1 field form and reading back from it.

This will allow you to make sure you are connecting to Redis4you and your Redis instance and reading from it.

All you need to do is make sure you have signed up for Redis4you and that you have placed the Predis folder in the directory that you are going to save your file.

Easy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require "predis/autoload.php";
PredisAutoloader::register();
try {
$redis = new PredisClient('tcp://50.30.35.9:2168/?password=c5xxxxxxxxxxxxxxxxxxxxxxxxcd&database=0');
$host = '50.30.35.9';
$port = 2168;
$password = 'c5xxxxxxxxxxxxxxxxxxxxxxxxcd';
$db = 1;
    echo "Successfully connected to Redis<br />";
} catch (Exception $e) {
    echo "Couldn't connected to Redis";
    echo $e->getMessage();
}
if (isset($_POST['firstname'])) {
$firstname = $_POST['firstname'];
$redis->set('firstname',$firstname);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
     <title>Redis Tutorial</title>
</head>
<body>
	<strong>Redis First Form</strong>
	<br />
	<form action="form_1_foreign.php" method="post">
	<input type="text" size="35" name="firstname" />
	<input type="submit" value="Set Firstname" />
</form>
<?php
	$redis_name = $redis->get('firstname');
	echo("this is reading from the Redis Database: " . $redis_name);
?>
</body>
</html>

home ~ previous

Rohan Leach .... thoughtful