-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.php
More file actions
executable file
·83 lines (68 loc) · 1.91 KB
/
redis.php
File metadata and controls
executable file
·83 lines (68 loc) · 1.91 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require 'vendor/autoload.php';
// prepend a base path if Predis is not present in the "include_path".
// require 'Predis/Autoloader.php';
Predis\Autoloader::register();
// Open Redis, catch exceptions
// but first wait a while before trying
sleep (30);
// since the dns does not always work, fix the ip address for localhost
try {
$redis = new Predis\Client(array(
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
'database' => 1,
// no timeouts on socket
'read_write_timeout' => 0,
));
}
catch (Exception $e) {
$message = date('Y-m-d H:i') . " Cannot connect to Redis " . $e->getMessage() . "\n";
error_log($message, 3, $LOGFILE);
// Just return to prevent the daemon from crashing
// exit(1);
return;
}
// Socketstream uses specific kinds of messages
// "publish" "ss:event" "{\"t\":\"all\",\"e\":\"newMessage\",\"p\":[\"\\u0013\\u0000Error in command.\"]}"
//
// {
// "t" : "all",
// "e" : "newMessage",
// "p" : [ "param1", "param2" ]
//}
class PubMessage {
public $t = "all"; // type
public $e = "portux"; // event, could also be portux
public $p = array(
'type' => '',
'location' => '',
'quantity' => '',
'value' => 0.0);
public function setType ($t) {
$this->t = $t;
}
public function getType () {
return $this->p['type'];
}
public function getLocation () {
return $this->p['location'];
}
public function getQuantity () {
return $this->p['quantity'];
}
public function getValue () {
return $this->p['value'];
}
public function setEvent ($e) {
$this->e = $e;
}
public function setParams ($t, $l, $q, $v) {
$this->p['type'] = $t;
$this->p['location'] = $l;
$this->p['quantity'] = $q;
$this->p['value'] = $v;
}
}
?>