Add namespace.
This commit is contained in:
43
Redis/RedisDebug.php
Normal file
43
Redis/RedisDebug.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php namespace Majestic\Redis;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Redis
|
||||
* @since 2011-07-29
|
||||
*/
|
||||
|
||||
class RedisDebug
|
||||
{
|
||||
private $redis;
|
||||
|
||||
public function __construct($redis)
|
||||
{
|
||||
if (!is_a($redis, 'Redis')) {
|
||||
throw new GeneralException();
|
||||
}
|
||||
$this->redis = $redis;
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$command = $this->r_implode(', ', $arguments);
|
||||
$profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command);
|
||||
$data = call_user_func_array(array($this->redis, $name), $arguments);
|
||||
$profiler->end();
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function r_implode($glue, $pieces)
|
||||
{
|
||||
$retVal = array();
|
||||
foreach ($pieces as $r_pieces) {
|
||||
if (is_array($r_pieces)) {
|
||||
$retVal[] = '(' . $this->r_implode($glue, $r_pieces) . ')';
|
||||
} else {
|
||||
$retVal[] = $r_pieces;
|
||||
}
|
||||
}
|
||||
return implode($glue, $retVal);
|
||||
}
|
||||
}
|
66
Redis/RedisManager.php
Normal file
66
Redis/RedisManager.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php namespace Majestic\Redis;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Redis
|
||||
* @since 2010-07-17
|
||||
*/
|
||||
|
||||
class RedisManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Redis connections
|
||||
*
|
||||
* @var Redis[]
|
||||
*/
|
||||
static protected $connections = array();
|
||||
|
||||
/**
|
||||
* Connect to redis
|
||||
*
|
||||
* @param string $name connection name. If not set 'default' will be used.
|
||||
* @param array $config Configuration array.
|
||||
*
|
||||
* @throws \Majestic\Exception\GeneralException
|
||||
* @return Redis
|
||||
*/
|
||||
static public function connect($name = 'default', $config = null)
|
||||
{
|
||||
if (!isset(self::$connections[$name])) {
|
||||
if (!$config) {
|
||||
if (!is_object(\Majestic\Config::get('Redis'))) {
|
||||
throw new \Majestic\Exception\GeneralException('Redis config no existence');
|
||||
}
|
||||
$config = \Majestic\Config::get('Redis')->$name;
|
||||
}
|
||||
|
||||
if (!is_array($config)) {
|
||||
throw new \Majestic\Exception\GeneralException('Connection parameters must be an array');
|
||||
}
|
||||
|
||||
$host = isset($config['host']) ? $config['host'] : 'localhost';
|
||||
$port = isset($config['port']) ? $config['port'] : 6379;
|
||||
$database = isset($config['database']) ? $config['database'] : 0;
|
||||
|
||||
/**
|
||||
* @var Redis
|
||||
*/
|
||||
$connection = new \Redis();
|
||||
if (\Majestic\Config::get('PROFILER_DETAILS')) {
|
||||
$connection = new RedisDebug($connection);
|
||||
}
|
||||
if (!$connection->connect($host, $port)) {
|
||||
throw new \Majestic\Exception\GeneralException('Failed to connect to Redis server at ' . $host . ':' . $port);
|
||||
}
|
||||
if ($database) {
|
||||
if (!$connection->select($database)) {
|
||||
throw new \Majestic\Exception\GeneralException('Failed to select Redis database with index ' . $database);
|
||||
}
|
||||
}
|
||||
self::$connections[$name] = $connection;
|
||||
}
|
||||
return self::$connections[$name];
|
||||
}
|
||||
}
|
69
Redis/redis.php
Normal file
69
Redis/redis.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php namespace Majestic\Redis;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Redis
|
||||
* @since 2011-05-17
|
||||
*/
|
||||
|
||||
/**
|
||||
* Redis stub for https://github.com/nicolasff/phpredis
|
||||
* @author aterekhov
|
||||
* @see https://github.com/nicolasff/phpredis
|
||||
*
|
||||
* @method bool connect() connect(string $host, int $port = 6379, float $timeout = 0) Connect to redis
|
||||
* @method bool pconnect() pconnect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id) Connect to redis with reusing connection
|
||||
* @method bool select() select(int $dbindex) Switches to a given database
|
||||
* @method void close() Close connection to redis
|
||||
* @method bool setOption() setOption(mixed $name, mixed $value) Set client option
|
||||
* @method mixed getOption() getOption(mixed $name) Get client option
|
||||
* @method string ping() ping() Check the current connection status
|
||||
* @method string|bool get() get(string $key) Get the value related to the specified key
|
||||
* @method bool set() set(string $key, mixed $value, int $timeout = null) Set the string value in argument as value of the key
|
||||
* @method bool setex() setex(string $key, int $ttl, mixed $value) Set the string value in argument as value of the key, with a time to live
|
||||
* @method bool setnx() setnx(string $key, int $ttl) Set the string value in argument as value of the key if the key doesn't already exist in the database
|
||||
* @method float delete() delete(mixed $key) Remove specified keys
|
||||
* @method Redis multi() multi(mixed $mode = 1) Enter and exit transactional mode
|
||||
* @method bool exec() exec() Enter and exit transactional mode
|
||||
* @method void watch() watch(mixed $keys) Watches a key for modifications by another client
|
||||
* @method void unwatch() unwatch(mixed $keys) Watches a key for modifications by another client
|
||||
* @method void subscribe() subscribe(array $channels, mixed $callback) Subscribe to channels. Warning: this function will probably change in the future
|
||||
* @method void publish() publish(string $channel, string $message) Publish messages to channels. Warning: this function will probably change in the future
|
||||
* @method bool exists() exists(string $key) Verify if the specified key exists
|
||||
* @method int incr() incr(string $key) Increment the number stored at key by one
|
||||
* @method int incrBy() incrBy(string $key, int $value) Increment the number stored at key by $value
|
||||
*
|
||||
* @method bool expire() expire(string $key, int $ttl) Sets an expiration date (a timeout) on an item
|
||||
*
|
||||
* @method float zAdd() zAdd(string $key, float $score, string $value) Adds the specified member with a given score to the sorted set stored at key
|
||||
* @method array zRange() zRange(string $key, float $start, float $end, bool $with_scores = false) Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end]
|
||||
* @method float zDelete() zDelete(string $key, string $value) Deletes a specified member from the ordered set.
|
||||
* @method array zRevRange() zRevRange(string $key, float $start, float $end, bool $with_scores = false) Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end]
|
||||
* @method array zRangeByScore() zRangeByScore(string $key, float $start, float $end) Returns the elements of the sorted set stored at the specified key which have scores in the range [start,end]. Adding a parenthesis before start or end excludes it from the range. +inf and -inf are also valid limits. zRevRangeByScore returns the same items in reverse order, when the start and end parameters are swapped.
|
||||
* @method int zRemRangeByScore() zRemRangeByScore(string $key, float $start, float $end) Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].
|
||||
* @method int zRemRangeByRank() zRemRangeByRank(string $key, int $start, int $end) Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].
|
||||
* @method float zCard() zCard(string $key) Returns the cardinality of an ordered set
|
||||
* @method float zScore() zScore(string $key, string $value) Returns the score of a given member in the specified sorted set.
|
||||
* @method float zUnionStore() zUnionStore(string $destination, array $keys, array $weights = array(), string $aggregate = 'sum') Creates an union of sorted sets given in second argument and store in in first argument
|
||||
* @method float zInterStore() zInterStore(string $destination, array $keys, array $weights = array(), string $aggregate = 'sum') Creates an intersection of sorted sets given in second argument and store in in first argument
|
||||
* @method int sAdd() sAdd(string $key, string $value) Adds a value to the set value stored at key. If this value is already in the set, FALSE is returned.
|
||||
* @method int sCard() sCard(string $key) Returns the cardinality of the set identified by key.
|
||||
* @method int sSize() sSize(string $key) Returns the cardinality of the set identified by key.
|
||||
* @method array sMembers() sMembers(string $key) Returns the contents of a set.
|
||||
* @method array sGetMembers() sGetMembers(string $key) Returns the contents of a set.
|
||||
* @method bool sContains() sContains(string $key, string $value) Checks if value is a member of the set stored at the key key.
|
||||
* @method bool sIsMember() sIsMember(string $key, string $value) Checks if value is a member of the set stored at the key key.
|
||||
* @method bool sRem() sRem(string $key, string $member) Removes the specified member from the set value stored at key.
|
||||
* @method bool sRemove() sRemove(string $key, string $member) Removes the specified member from the set value stored at key.
|
||||
* @method array lRange() lRange(string $key, int $start, int $end) Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpretated as indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate
|
||||
* @method int rPush() rPush(string $key, string $value) Adds the string value to the tail (right) of the list. Creates the list if the key didn't exist. If the key exists and is not a list, FALSE is returned.
|
||||
* @method array lTrim() lTrim(string $key, int $start, int $stop) Trims an existing list so that it will contain only a specified range of elements.
|
||||
* @method array sInter
|
||||
*/
|
||||
class Redis
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user