Skip to content

Commit 73ab81a

Browse files
author
Max Kamashev
committed
begin work
1 parent 763fce8 commit 73ab81a

File tree

1 file changed

+250
-0
lines changed

1 file changed

+250
-0
lines changed

redisphp.php

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
<?php
2+
3+
/*
4+
* To change this template, choose Tools | Templates
5+
* and open the template in the editor.
6+
*/
7+
class Redis
8+
{
9+
/**
10+
* Creates a Redis client
11+
*
12+
* @example $redis = new Redis();
13+
*/
14+
public function __construct() {}
15+
16+
/**
17+
* Connects to a Redis instance.
18+
*
19+
* @param string $host can be a host, or the path to a unix domain socket
20+
* @param int $port optional
21+
* @param float $timeout value in seconds (optional, default is 0 meaning unlimited)
22+
* @return bool TRUE on success, FALSE on error.
23+
* @example $redis->connect('127.0.0.1', 6379);
24+
* @example $redis->connect('127.0.0.1'); // port 6379 by default
25+
* @example $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
26+
* @example $redis->connect('/tmp/redis.sock'); // unix domain socket.
27+
*/
28+
public function connect($host, $port = 6379, $timeout = 0) {}
29+
30+
/**
31+
* @see connect()
32+
*/
33+
public function open($host, $port = 6379, $timeout = 0) {}
34+
35+
/**
36+
* Connects to a Redis instance or reuse a connection already established with pconnect/popen.
37+
*
38+
* The connection will not be closed on close or end of request until the php process ends. So be patient on to many open FD's (specially on redis server side) when using persistent connections on many servers connecting to one redis server.
39+
*
40+
* Also more than one persistent connection can be made identified by either host + port + timeout or unix socket + timeout.
41+
*
42+
* This feature is not available in threaded versions. pconnect and popen then working like their non persistent equivalents.
43+
*
44+
* @param string $host can be a host, or the path to a unix domain socket
45+
* @param int $port optional
46+
* @param float $timeout value in seconds (optional, default is 0 meaning unlimited)
47+
* @return bool TRUE on success, FALSE on error.
48+
* @example $redis->connect('127.0.0.1', 6379);
49+
* @example $redis->connect('127.0.0.1'); // port 6379 by default
50+
* @example $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
51+
* @example $redis->connect('/tmp/redis.sock'); // unix domain socket.
52+
*/
53+
public function pconnect($host, $port = 6379, $timeout = 0) {}
54+
55+
/**
56+
* @see pconnect()
57+
*/
58+
public function popen($host, $port = 6379, $timeout = 0) {}
59+
60+
/**
61+
* Disconnects from the Redis instance, except when pconnect is used.
62+
*/
63+
public function close() {}
64+
65+
/**
66+
* Set client option.
67+
*
68+
* @param type $name parameter name
69+
* @param type $value parameter value
70+
* @return BOOL: TRUE on success, FALSE on error.
71+
* @example $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data
72+
* @example $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize
73+
* @example $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize
74+
* @example $redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys
75+
*/
76+
public function setOption($name, $value) {}
77+
78+
/**
79+
* Get client option
80+
*
81+
* @param type $name parameter name
82+
* @return Parameter value.
83+
* @example $redis->getOption(Redis::OPT_SERIALIZER); // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, or Redis::SERIALIZER_IGBINARY.
84+
*/
85+
public function getOption($name) {}
86+
87+
/**
88+
* Check the current connection status
89+
*
90+
* @return string STRING: +PONG on success. Throws a RedisException object on connectivity error, as described above.
91+
*/
92+
public function ping() {}
93+
94+
95+
/**
96+
* Get the value related to the specified key
97+
*
98+
* @param type $key
99+
* @return String or Bool: If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned.
100+
* @example $redis->get('key');
101+
*/
102+
public function get($key) {}
103+
104+
105+
/**
106+
* Set the string value in argument as value of the key.
107+
*
108+
* @param string $key
109+
* @param string $value
110+
* @param float $timeout Calling SETEX is preferred if you want a timeout.
111+
* @return Bool TRUE if the command is successful.
112+
* @example $redis->set('key', 'value');
113+
*/
114+
public function set($key, $value, $timeout = 0) {}
115+
116+
/**
117+
* Set the string value in argument as value of the key, with a time to live.
118+
*
119+
* @param string $key
120+
* @param int $ttl
121+
* @param type $value
122+
* @return Bool TRUE if the command is successful.
123+
* @example $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
124+
*/
125+
public function setex($key, $ttl, $value) {}
126+
127+
/**
128+
* Set the string value in argument as value of the key if the key doesn't already exist in the database.
129+
*
130+
* @param type $key
131+
* @param type $value
132+
* @return Bool TRUE in case of success, FALSE in case of failure.
133+
* @example $redis->setnx('key', 'value'); // return TRUE
134+
* @example $redis->setnx('key', 'value'); // return FALSE
135+
*/
136+
public function setnx($key, $value) {}
137+
138+
/**
139+
* Remove specified keys.
140+
*
141+
* @param int | array $key1 An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
142+
* @param type $key2 ...
143+
* @param type $key3 ...
144+
* @return Long Number of keys deleted.
145+
* @example
146+
* $redis->set('key1', 'val1');
147+
* $redis->set('key2', 'val2');
148+
* $redis->set('key3', 'val3');
149+
* $redis->set('key4', 'val4');
150+
* $redis->delete('key1', 'key2'); // return 2
151+
* $redis->delete(array('key3', 'key4')); // return 2
152+
*/
153+
public function del($key1, $key2 = NULL, $key3 = NULL) {}
154+
155+
/**
156+
* @see del()
157+
*/
158+
public function delete($key1, $key2 = NULL, $key3 = NULL) {}
159+
160+
/**
161+
* Enter and exit transactional mode.
162+
*
163+
* @param Redis::MULTI | Redis::PIPELINE Defaults to Redis::MULTI. A Redis::MULTI block of commands runs as a single transaction; a Redis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity. discard cancels a transaction.
164+
* @return multi() returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until exec() is called.
165+
* @example
166+
* $ret = $redis->multi()
167+
* ->set('key1', 'val1')
168+
* ->get('key1')
169+
* ->set('key2', 'val2')
170+
* ->get('key2')
171+
* ->exec();
172+
*
173+
* //$ret == array (
174+
* // 0 => TRUE,
175+
* // 1 => 'val1',
176+
* // 2 => TRUE,
177+
* // 3 => 'val2');
178+
*/
179+
public function multi() {}
180+
181+
/**
182+
* @see multi()
183+
*/
184+
public function exec() {}
185+
186+
/**
187+
* @see multi()
188+
*/
189+
public function discard() {}
190+
191+
/**
192+
* Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client.
193+
* @param string | array $key: a list of keys
194+
* @return void
195+
* @example
196+
* $redis->watch('x');
197+
* // long code here during the execution of which other clients could well modify `x`
198+
* $ret = $redis->multi()
199+
* ->incr('x')
200+
* ->exec();
201+
* // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
202+
*/
203+
public function watch($key) {}
204+
205+
/**
206+
* @see watch()
207+
*/
208+
public function unwatch() {}
209+
210+
/**
211+
* Subscribe to channels. Warning: this function will probably change in the future.
212+
*
213+
* @param array $channels an array of channels to subscribe to
214+
* @param string | array $callback either a string or an array($instance, 'method_name'). The callback function receives 3 parameters: the redis instance, the channel name, and the message.
215+
* @example
216+
* function f($redis, $chan, $msg) {
217+
* switch($chan) {
218+
* case 'chan-1':
219+
* ...
220+
* break;
221+
*
222+
* case 'chan-2':
223+
* ...
224+
* break;
225+
*
226+
* case 'chan-2':
227+
* ...
228+
* break;
229+
* }
230+
* }
231+
*
232+
* $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
233+
*/
234+
public function subscribe($channels, $callback) {}
235+
236+
/**
237+
* Publish messages to channels. Warning: this function will probably change in the future.
238+
*
239+
* @param string $channel a channel to publish to
240+
* @param string $message string
241+
* @example $redis->publish('chan-1', 'hello, world!'); // send message.
242+
*/
243+
public function publish($channel, $message) {}
244+
245+
246+
247+
248+
249+
250+
}

0 commit comments

Comments
 (0)