Projects
home:rottame:vhosts-ng:php8-extensions
php8-redis
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 3
View file
php8-redis.changes
Changed
@@ -1,4 +1,14 @@ ------------------------------------------------------------------- +Mon May 19 06:57:04 UTC 2025 - Angelo Grossini <angelo@intercom.it> + +- update to 6.2.0 + +------------------------------------------------------------------- +Fri May 31 14:34:52 UTC 2024 - Angelo Grossini <angelo@intercom.it> + +- update to 6.0.2 + +------------------------------------------------------------------- Wed Aug 16 12:45:51 UTC 2023 - Angelo Grossini <rottame@intercom.it> - vhng versioning
View file
php8-redis.spec
Changed
@@ -18,7 +18,7 @@ %define php_name php8 %define pkg_name redis Name: %{php_name}-%{pkg_name} -Version: 5.3.7 +Version: 6.2.0 Release: lp151.34.1 Summary: API for communicating with Redis servers License: PHP-3.01
View file
redis-5.3.7.tgz/redis-5.3.7/INSTALL.markdown
Deleted
@@ -1,97 +0,0 @@ -# Installation from pecl/pickle - -To pull latest stable released version, from pecl(https://pecl.php.net/package/redis) / pickle(https://wiki.php.net/rfc/deprecate-pear-include-composer): - -~~~ -pecl install redis - -// If using PHP >= 7.3 -pickle install redis -~~~ - -# Installation from sources - -To build this extension for the sources tree: - -~~~ -git clone https://github.com/phpredis/phpredis.git -cd phpredis -phpize -./configure --enable-redis-igbinary --enable-redis-msgpack --enable-redis-lzf --with-liblzf=DIR --enable-redis-zstd -make && make install -~~~ - -If you would like phpredis to serialize your data using the igbinary library, run configure with `--enable-redis-igbinary`. -If you would like to use the msgpack serializer, run configure with `--enable-redis-msgpack` (note: Requires php-msgpack >= 2.0.3) -The extension also may compress data before sending it to Redis server, if you run configure with `--enable-redis-lzf`. If you want to use lzf library pre-installed into your system use `--with-liblzf` configuration option to specify the path where to search files. -`make install` copies `redis.so` to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in `/etc/php5/conf.d` with the following contents: `extension=redis.so`. - -You can generate a debian package for PHP5, accessible from Apache 2 by running `./mkdeb-apache2.sh` or with `dpkg-buildpackage` or `svn-buildpackage`. - -This extension exports a single class, Redis(./README.markdown#class-redis) (and RedisException(./README.markdown#class-redisexception) used in case of errors). Check out https://github.com/ukko/phpredis-phpdoc for a PHP stub that you can use in your IDE for code completion. - - -# Binary packages - -Most distributions provides pre-build binary packages of this extension. - -## Windows: - -Follow the DLL link on the https://pecl.php.net/package/redis(https://pecl.php.net/package/redis) page. - -## Fedora - -Fedora users can install the package from the official repository. - -### Fedora ≥ 29, Version 5 - -Installation of the php-pecl-redis5(https://apps.fedoraproject.org/packages/php-pecl-redis5) package: - -~~~ -dnf install php-pecl-redis5 -~~~ - -## RHEL / CentOS - -Installation of the php-pecl-redis(https://apps.fedoraproject.org/packages/php-pecl-redis) package, from the EPEL repository(https://fedoraproject.org/wiki/EPEL): - -~~~ -yum install php-pecl-redis -~~~ - -### openSUSE ≥ 15.1 - -Installation of the php7-redis(https://software.opensuse.org/package/php7-redis?search_term=php7-redis) package: - -~~~ -zypper in php7-redis -~~~ - - -# Installation on OSX - -If the install fails on OSX, type the following commands in your shell before trying again: -~~~ -MACOSX_DEPLOYMENT_TARGET=10.6 -CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" -CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" -CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" -LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" -export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET -~~~ - -If that still fails and you are running Zend Server CE, try this right before "make": `./configure CFLAGS="-arch i386"`. - -Taken from Compiling phpredis on Zend Server CE/OSX (http://www.tumblr.com/tagged/phpredis). - -See also: Install Redis & PHP Extension PHPRedis with Macports(http://www.lecloud.net/post/3378834922/install-redis-php-extension-phpredis-with-macports). - -You can install it using MacPorts: - -- Get macports-php(https://www.macports.org/) -- `sudo port install php56-redis` (or php53-redis, php54-redis, php55-redis, php70-redis, php71-redis, php72-redis, php73-redis, php74-redis) - -# Building on Windows - -See instructions from @char101(https://github.com/phpredis/phpredis/issues/213#issuecomment-11361242) on how to build phpredis on Windows. -
View file
redis-5.3.7.tgz/redis-5.3.7/README.markdown
Deleted
@@ -1,4394 +0,0 @@ -# PhpRedis - -!Build Status(https://github.com/phpredis/phpredis/actions/workflows/ci.yml/badge.svg)(https://github.com/phpredis/phpredis/actions/workflows/ci.yml) -!Coverity Scan Build Status(https://scan.coverity.com/projects/13205/badge.svg)(https://scan.coverity.com/projects/phpredis-phpredis) -!PHP version from Travis config(https://img.shields.io/travis/php-v/phpredis/phpredis/develop)(https://img.shields.io/travis/php-v/phpredis/phpredis/develop) - -The phpredis extension provides an API for communicating with the Redis(http://redis.io/) key-value store. It is released under the PHP License, version 3.01(http://www.php.net/license/3_01.txt). -This code has been developed and maintained by Owlient from November 2009 to March 2011. - -You can send comments, patches, questions here on github(https://github.com/phpredis/phpredis/issues), to n.favrefelix@gmail.com (@yowgi(https://twitter.com/yowgi)), to michael.grunder@gmail.com (@grumi78(https://twitter.com/grumi78)) or to p.yatsukhnenko@gmail.com (@yatsukhnenko(https://twitter.com/yatsukhnenko)). - -## Supporting the project -PhpRedis will always be free and open source software, but if you or your company has found it useful please consider supporting the project. Developing a large, complex, and performant library like PhpRedis takes a great deal of time and effort, and support would be appreciated! :heart: - -The best way to support the project is through GitHub sponsors(https://github.com/sponsors/michael-grunder). Many of the reward tiers grant access to our slack channel(https://phpredis.slack.com) where myself(https://github.com/michael-grunder) and Pavlo(https://github.com/yatsukhnenko) are regularly available to answer questions. Additionally this will allow you to provide feedback on which fixes and new features to prioritize. - -You can also make a one-time contribution with one of the links below. - -!PayPal(https://img.shields.io/badge/Donate-PayPal-green.svg)(https://www.paypal.me/michaelgrunder/5) -!Bitcoin(https://en.cryptobadges.io/badge/micro/1FXkYHBo5uoaztxFbajiPfbnkgKCbF3ykG)(https://en.cryptobadges.io/donate/1FXkYHBo5uoaztxFbajiPfbnkgKCbF3ykG) -!Ethereum(https://en.cryptobadges.io/badge/micro/0x43D54E32357B96f68dFF0a6B46976d014Bd603E1)(https://en.cryptobadges.io/donate/0x43D54E32357B96f68dFF0a6B46976d014Bd603E1) - -## Sponsors -<a href="https://audiomack.com"><img src="https://styleguide.audiomack.com/assets/dl/inline-orange-large.png" align="center" alt="Audiomack.com" width="150"></a> -<a href="https://bluehost.com"><img src="https://upload.wikimedia.org/wikipedia/commons/2/22/Bluehost-logo.png" align="center" alt="Bluehost.com" width="150"></a> -<a href="https://objectcache.pro"><img src="https://objectcache.pro/assets/wordmark-padded.png" align="center" alt="Object Cache Pro" width="150"></a> -<a href="https://openlms.net"><img src="https://help.openlms.net/wp-content/uploads/2020/05/cropped-open-lms.png" align="center" alt="OpenLMS.net" width="150"></a> - -# Table of contents ------ -1. Installing/Configuring(#installingconfiguring) - * Installation(#installation) - * PHP Session handler(#php-session-handler) - * Distributed Redis Array(#distributed-redis-array) - * Redis Cluster support(#redis-cluster-support) - * Redis Sentinel support(#redis-sentinel-support) - * Running the unit tests(#running-the-unit-tests) -1. Classes and methods(#classes-and-methods) - * Usage(#usage) - * Connection(#connection) - * Retry and backoff(#retry-and-backoff) - * Server(#server) - * Keys and strings(#keys-and-strings) - * Hashes(#hashes) - * Lists(#lists) - * Sets(#sets) - * Sorted sets(#sorted-sets) - * HyperLogLogs(#hyperloglogs) - * Geocoding(#geocoding) - * Streams(#streams) - * Pub/sub(#pubsub) - * Transactions(#transactions) - * Scripting(#scripting) - * Introspection(#introspection) - ------ - -# Installing/Configuring ------ - -## Installation - -For everything you should need to install PhpRedis on your system, -see the INSTALL.markdown(./INSTALL.markdown) page. - -## PHP Session handler - -phpredis can be used to store PHP sessions. To do this, configure `session.save_handler` and `session.save_path` in your php.ini to tell phpredis where to store the sessions: -~~~ -session.save_handler = redis -session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5" -~~~ - -`session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the parameters. The following parameters are available: - -* weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, *host1* stores 20% of all the sessions (1/(1+2+2)) while *host2* and *host3* each store 40% (2/(1+2+2)). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1. -* timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds). -* persistent (integer, should be 1 or 0): defines if a persistent connection should be used. **(experimental setting)** -* prefix (string, defaults to "PHPREDIS_SESSION:"): used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID. -* auth (string, or an array with one or two elements): used to authenticate with the server prior to sending commands. -* database (integer): selects a different database. - -Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with `ini_set()`(http://php.net/ini_set). -The session handler requires a version of Redis supporting `EX` and `NX` options of `SET` command (at least 2.6.12). -phpredis can also connect to a unix domain socket: `session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0"`. - -### Session locking - -**Support**: Locking feature is currently only supported for Redis setup with single master instance (e.g. classic master/slave Sentinel environment). -So locking may not work properly in RedisArray or RedisCluster environments. - -Following INI variables can be used to configure session locking: -~~~ -; Should the locking be enabled? Defaults to: 0. -redis.session.locking_enabled = 1 -; How long should the lock live (in seconds)? Defaults to: value of max_execution_time. -redis.session.lock_expire = 60 -; How long to wait between attempts to acquire lock, in microseconds (µs)?. Defaults to: 2000 -redis.session.lock_wait_time = 50000 -; Maximum number of times to retry (-1 means infinite). Defaults to: 10 -redis.session.lock_retries = 10 -~~~ - -## Distributed Redis Array - -See dedicated page(./arrays.markdown#readme). - -## Redis Cluster support - -See dedicated page(./cluster.markdown#readme). - -## Redis Sentinel support - -See dedicated page(./sentinel.markdown#readme). - -## Running the unit tests - -phpredis uses a small custom unit test suite for testing functionality of the various classes. To run tests, simply do the following: - -~~~ -# Run tests for Redis class (note this is the default) -php tests/TestRedis.php --class Redis - -# Run tests for RedisArray class -tests/mkring.sh start -php tests/TestRedis.php --class RedisArray -tests/mkring.sh stop - -# Run tests for the RedisCluster class -tests/make-cluster.sh start -php tests/TestRedis.php --class RedisCluster -tests/make-cluster.sh stop - -# Run tests for RedisSentinel class -php tests/TestRedis.php --class RedisSentinel -~~~ - -Note that it is possible to run only tests which match a substring of the test itself by passing the additional argument '--test <str>' when invoking. - -~~~ -# Just run the 'echo' test -php tests/TestRedis.php --class Redis --test echo -~~~ - -# Classes and methods ------ - -## Usage - -1. Class Redis(#class-redis) -1. Class RedisException(#class-redisexception) -1. Predefined constants(#predefined-constants) - -### Class Redis ------ -_**Description**_: Creates a Redis client - -##### *Example* - -~~~php -$redis = new Redis(); -~~~ - -### Class RedisException ------ -phpredis throws a RedisException(#class-redisexception) object if it can't reach the Redis server. That can happen in case of connectivity issues, -if the Redis service is down, or if the redis host is overloaded. In any other problematic case that does not involve an -unreachable server (such as a key not existing, an invalid command, etc), phpredis will return `FALSE`. - -### Predefined constants ------ -_**Description**_: Available Redis Constants - -Redis data types, as returned by type(#type) -~~~ -Redis::REDIS_STRING - String -Redis::REDIS_SET - Set -Redis::REDIS_LIST - List -Redis::REDIS_ZSET - Sorted set -Redis::REDIS_HASH - Hash -Redis::REDIS_NOT_FOUND - Not found / other -~~~ - -@TODO: OPT_SERIALIZER, AFTER, BEFORE,... - -## Connection - -1. connect, open(#connect-open) - Connect to a server -1. pconnect, popen(#pconnect-popen) - Connect to a server (persistent) -1. auth(#auth) - Authenticate to the server -1. select(#select) - Change the selected database for the current connection -1. swapdb(#swapdb) - Swaps two Redis databases -1. close(#close) - Close the connection -1. setOption(#setoption) - Set client option -1. getOption(#getoption) - Get client option -1. ping(#ping) - Ping the server -1. echo(#echo) - Echo the given string - -### connect, open
View file
redis-5.3.7.tgz/redis-5.3.7/arrays.markdown
Deleted
@@ -1,185 +0,0 @@ -Redis Arrays -============ - -A Redis array is an isolated namespace in which keys are related in some manner. Keys are distributed across a number of Redis instances, using consistent hashing. A hash function is used to spread the keys across the array in order to keep a uniform distribution. **This feature was added as the result of a generous sponsorship by A+E Networks(http://www.aetn.com/).** - -An array is composed of the following: - -* A list of Redis hosts. -* A key extraction function, used to hash part of the key in order to distribute related keys on the same node (optional). This is set by the "function" option. -* A list of nodes previously in the ring, only present after a node has been added or removed. When a read command is sent to the array (e.g. GET, LRANGE...), the key is first queryied in the main ring, and then in the secondary ring if it was not found in the main one. Optionally, the keys can be migrated automatically when this happens. Write commands will always go to the main ring. This is set by the "previous" option. -* An optional index in the form of a Redis set per node, used to migrate keys when nodes are added or removed; set by the "index" option. -* An option to rehash the array automatically as nodes are added or removed, set by the "autorehash" option. - -## Creating an array - -There are several ways of creating Redis arrays; they can be pre-defined in redis.ini using `new RedisArray(string $name);`, or created dynamically using `new RedisArray(array $hosts, array $options);` - -#### Declaring a new array with a list of nodes -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380")); -</pre> - - -#### Declaring a new array with a list of nodes and a function to extract a part of the key -<pre> -function extract_key_part($k) { - return substr($k, 0, 3); // hash only on first 3 characters. -} -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("function" => "extract_key_part")); -</pre> - -#### Defining a "previous" array when nodes are added or removed. -When a new node is added to an array, phpredis needs to know about it. The old list of nodes becomes the “previous” array, and the new list of nodes is used as a main ring. Right after a node has been added, some read commands will point to the wrong nodes and will need to look up the keys in the previous ring. - -<pre> -// adding host3 to a ring containing host1 and host2. Read commands will look in the previous ring if the data is not found in the main ring. -$ra = new RedisArray(array("host1", "host2", "host3"), array("previous" => array("host1", "host2"))); -</pre> - -#### Specifying the "retry_interval" parameter -The retry_interval is used to specify a delay in milliseconds between reconnection attempts in case the client loses connection with a server -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("retry_timeout" => 100)); -</pre> - -#### Specifying the "lazy_connect" parameter -This option is useful when a cluster has many shards but not of them are necessarily used at one time. -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("lazy_connect" => true)); -</pre> - -#### Specifying the "connect_timeout" parameter -The connect_timeout value is a double and is used to specify a timeout in number of seconds when creating redis socket connections used in the RedisArray. -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("connect_timeout" => 0.5)); -</pre> - -#### Specifying the "read_timeout" parameter -The read_timeout value is a double and is used to specify a timeout in number of seconds when waiting response from the server. -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("read_timeout" => 0.5)); -</pre> - -#### Specifying the "algorithm" parameter -The algorithm value is a string and is used to specify the name of key hashing algorithm. The list of possible values may be found using PHP function `hash_algos`. -If algorithm is not supported by PHP `hash` function default algorithm will be used (CRC32 with 0xffffffff initial value). -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("algorithm" => "md5")); -</pre> - -#### Specifying the "consistent" parameter -The value is boolean. When enabled RedisArray uses "ketama" distribution algorithm (currently without ability to set weight to each server). -This option applies to main and previous ring if specified. -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("consistent" => true)); -</pre> - -#### Specifying the "auth" parameter -The value is string and used to specify the password for authenticate with the server prior to sending commands -<pre> -$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("auth" => "mysecretpassword")); -</pre> - -#### Defining arrays in Redis.ini - -Because php.ini parameters must be pre-defined, Redis Arrays must all share the same .ini settings. - -<pre> -// list available Redis Arrays -ini_set('redis.array.names', 'users,friends'); - -// set host names for each array. -ini_set('redis.arrays.hosts', 'users=localhost:6379&users=localhost:6380&users=localhost:6381&users=localhost:6382&friends=localhost'); - -// set functions -ini_set('redis.arrays.functions', 'users=user_hash'); - -// use index only for users -ini_set('redis.arrays.index', 'users=1,friends=0'); - -// use password for authentication -ini_set('redis.arrays.auth', 'users=mysecretpassword') -</pre> - -## Usage - -Redis arrays can be used just as Redis objects: -<pre> -$ra = new RedisArray("users"); -$ra->set("user1:name", "Joe"); -$ra->set("user2:name", "Mike"); -</pre> - - -## Key hashing -By default and in order to be compatible with other libraries, phpredis will try to find a substring enclosed in curly braces within the key name, and use it to distribute the data. - -For instance, the keys “{user:1}:name” and “{user:1}:email” will be stored on the same server as only “user:1” will be hashed. You can provide a custom function name in your redis array with the "function" option; this function will be called every time a key needs to be hashed. It should take a string and return a string. - - -## Custom key distribution function -In order to control the distribution of keys by hand, you can provide a custom function or closure that returns the server number, which is the index in the array of servers that you created the RedisArray object with. - -For instance, instantiate a RedisArray object with `new RedisArray(array("us-host", "uk-host", "de-host"), array("distributor" => "dist"));` and write a function called "dist" that will return `2` for all the keys that should end up on the "de-host" server. - -### Example -<pre> -$ra = new RedisArray(array("host1", "host2", "host3", "host4", "host5", "host6", "host7", "host8"), array("distributor" => array(2, 2))); -</pre> - -This declares that we started with 2 shards and moved to 4 then 8 shards. The number of initial shards is 2 and the resharding level (or number of iterations) is 2. - -## Migrating keys - -When a node is added or removed from a ring, RedisArray instances must be instantiated with a “previous” list of nodes. A single call to `$ra->_rehash()` causes all the keys to be redistributed according to the new list of nodes. Passing a callback function to `_rehash()` makes it possible to track the progress of that operation: the function is called with a node name and a number of keys that will be examined, e.g. `_rehash(function ($host, $count){ ... });`. - -It is possible to automate this process, by setting `'autorehash' => TRUE` in the constructor options. This will cause keys to be migrated when they need to be read from the previous array. - -In order to migrate keys, they must all be examined and rehashed. If the "index" option was set, a single key per node lists all keys present there. Otherwise, the `KEYS` command is used to list them. -If a “previous” list of servers is provided, it will be used as a backup ring when keys can not be found in the current ring. Writes will always go to the new ring, whilst reads will go to the new ring first, and to the second ring as a backup. - -Adding and/or removing several instances is supported. - -### Example -<pre> -$ra = new RedisArray("users"); // load up a new config from redis.ini, using the “.previous” listing. -$ra->_rehash(); -</pre> - -Running this code will: - -* Create a new ring with the updated list of nodes. -* Server by server, look up all the keys in the previous list of nodes. -* Rehash each key and possibly move it to another server. -* Update the array object with the new list of nodes. - -## Multi/exec -Multi/exec is still available, but must be run on a single node: -<pre> -$host = $ra->_target("{users}:user1:name"); // find host first -$ra->multi($host) // then run transaction on that host. - ->del("{users}:user1:name") - ->srem("{users}:index", "user1") - ->exec(); -</pre> - -## Limitations -Key arrays offer no guarantee when using Redis commands that span multiple keys. Except for the use of MGET, MSET, and DEL, a single connection will be used and all the keys read or written there. Running KEYS() on a RedisArray object will execute the command on each node and return an associative array of keys, indexed by host name. - -## Array info -RedisArray objects provide several methods to help understand the state of the cluster. These methods start with an underscore. - -* `$ra->_hosts()` → returns a list of hosts for the selected array. -* `$ra->_function()` → returns the name of the function used to extract key parts during consistent hashing. -* `$ra->_target($key)` → returns the host to be used for a certain key. -* `$ra->_instance($host)` → returns a redis instance connected to a specific node; use with `_target` to get a single Redis object. -* `$ra->_continuum()` → returns a list of points on continuum; may be useful with custom distributor function. - -## Running the unit tests -<pre> -$ cd tests -$ ./mkring.sh start -$ php array-tests.php -</pre> -
View file
redis-5.3.7.tgz/redis-5.3.7/backoff.c
Deleted
@@ -1,90 +0,0 @@ -#include "common.h" - -#include <ext/standard/php_rand.h> - -#if PHP_VERSION_ID >= 70100 -#include <ext/standard/php_mt_rand.h> -#else -static zend_long php_mt_rand_range(zend_long min, zend_long max) { - zend_long number = php_rand(); - RAND_RANGE(number, min, max, PHP_RAND_MAX); - return number; -} -#endif - -#include "backoff.h" - -static zend_ulong random_range(zend_ulong min, zend_ulong max) { - if (max < min) { - return php_mt_rand_range(max, min); - } - - return php_mt_rand_range(min, max); -} - -static zend_ulong redis_default_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong backoff = retry_index ? self->base : random_range(0, self->base); - return MIN(self->cap, backoff); -} - -static zend_ulong redis_constant_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong backoff = self->base; - return MIN(self->cap, backoff); -} - -static zend_ulong redis_uniform_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong backoff = random_range(0, self->base); - return MIN(self->cap, backoff); -} - -static zend_ulong redis_exponential_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong pow = MIN(retry_index, 10); - zend_ulong backoff = self->base * (1 << pow); - return MIN(self->cap, backoff); -} - -static zend_ulong redis_full_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong pow = MIN(retry_index, 10); - zend_ulong backoff = self->base * (1 << pow); - zend_ulong cap = MIN(self->cap, backoff); - return random_range(0, cap); -} - -static zend_ulong redis_equal_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { - zend_ulong pow = MIN(retry_index, 10); - zend_ulong backoff = self->base * (1 << pow); - zend_ulong temp = MIN(self->cap, backoff); - return temp / 2 + random_range(0, temp) / 2; -} - -static zend_ulong redis_decorrelated_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { - self->previous_backoff = random_range(self->base, self->previous_backoff * 3); - return MIN(self->cap, self->previous_backoff); -} - -typedef zend_ulong (*redis_backoff_algorithm)(struct RedisBackoff *self, unsigned int retry_index); - -static redis_backoff_algorithm redis_backoff_algorithmsREDIS_BACKOFF_ALGORITHMS = { - redis_default_backoff, - redis_decorrelated_jitter_backoff, - redis_full_jitter_backoff, - redis_equal_jitter_backoff, - redis_exponential_backoff, - redis_uniform_backoff, - redis_constant_backoff, -}; - -void redis_initialize_backoff(struct RedisBackoff *self, unsigned long retry_interval) { - self->algorithm = 0; // default backoff - self->base = retry_interval; - self->cap = retry_interval; - self->previous_backoff = 0; -} - -void redis_backoff_reset(struct RedisBackoff *self) { - self->previous_backoff = 0; -} - -zend_ulong redis_backoff_compute(struct RedisBackoff *self, unsigned int retry_index) { - return redis_backoff_algorithmsself->algorithm(self, retry_index); -}
View file
redis-5.3.7.tgz/redis-5.3.7/cluster.markdown
Deleted
@@ -1,189 +0,0 @@ -Redis Cluster -============= - -Redis introduces cluster support as of version 3.0.0, and to communicate with a cluster using phpredis one needs to use the RedisCluster class. For the majority of operations the RedisCluster class can act as a drop-in replacement for the Redis class without needing to modify how it's called. **This feature was added as the result of a generous sponsorship by Tradesy(https://www.tradesy.com/)** - -## Creating and connecting to a cluster - -To maintain consistency with the RedisArray class, one can create and connect to a cluster either by passing it one or more 'seed' nodes, or by defining these in redis.ini as a 'named' cluster. - -#### Declaring a cluster with an array of seeds -~~~php -// Create a cluster setting three nodes as seeds -$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003')); - -// Connect and specify timeout and read_timeout -$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5); - -// Connect with read/write timeout as well as specify that phpredis should use -// persistent connections to each node. -$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true); - -// Connect with cluster using password. -$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true, "password"); -~~~ - -#### Loading a cluster configuration by name -In order to load a named array, one must first define the seed nodes in redis.ini. The following lines would define the cluster 'mycluster', and be loaded automatically by phpredis. - -~~~ini -# In redis.ini -redis.clusters.seeds = "mycluster=localhost:7000&test=localhost:7001" -redis.clusters.timeout = "mycluster=5" -redis.clusters.read_timeout = "mycluster=10" -redis.clusters.auth = "mycluster=password" -~~~ - -Then, this cluster can be loaded by doing the following - -~~~php -$obj_cluster = new RedisCluster('mycluster'); -~~~ - -## Connection process - -On construction, the RedisCluster class will iterate over the provided seed nodes until it can attain a connection to the cluster and run CLUSTER SLOTS to map every node in the cluster locally. Once the keyspace is mapped, RedisCluster will only connect to nodes when it needs to (e.g. you're getting a key that we believe is on that node.) - -## Slot caching -Each time the `RedisCluster` class is constructed from scratch, phpredis needs to execute a `CLUSTER SLOTS` command to map the keyspace. Although this isn't an expensive command, it does require a round trip for each newly created object, which is inefficient. Starting from PhpRedis 5.0.0 these slots can be cached by setting `redis.clusters.cache_slots = 1` in `php.ini`. - -## Timeouts -Because Redis cluster is intended to provide high availability, timeouts do not work in the same way they do in normal socket communication. It's fully possible to have a timeout or even exception on a given socket (say in the case that a master node has failed), and continue to serve the request if and when a slave can be promoted as the new master. - -The way RedisCluster handles user specified timeout values is that every time a command is sent to the cluster, we record the time at the start of the request and then again every time we have to re-issue the command to a different node (either because Redis cluster responded with MOVED/ASK or because we failed to communicate with a given node). Once we detect having been in the command loop for longer than our specified timeout, an error is raised. - -## Keyspace map -As previously described, RedisCluster makes an initial mapping of every master (and any slaves) on construction, which it uses to determine which nodes to direct a given command. However, one of the core functionalities of Redis cluster is that this keyspace can change while the cluster is running. - -Because of this, the RedisCluster class will update its keyspace mapping whenever it receives a MOVED error when requesting data. In the case that we receive ASK redirection, it follows the Redis specification and requests the key from the ASK node, prefixed with an ASKING command. - -## Automatic slave failover / distribution -By default, RedisCluster will only ever send commands to master nodes, but can be configured differently for readonly commands if requested. - -~~~php -// The default option, only send commands to master nodes -$obj_cluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_NONE); - -// In the event we can't reach a master, and it has slaves, failover for read commands -$obj_cluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_ERROR); - -// Always distribute readonly commands between masters and slaves, at random -$obj_cluster->setOption( - RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE -); - -// Always distribute readonly commands to the slaves, at random -$obj_cluster->setOption( - RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES -); -~~~ - -## Main command loop -With the exception of commands that are directed to a specific node, each command executed via RedisCluster is processed through a command loop, where we make the request, handle any MOVED or ASK redirection, and repeat if necessary. This continues until one of the following conditions is met: - -1. We fail to communicate with *any* node that we are aware of, in which case a ~~~RedisClusterException~~~ is raised. -2. We have been bounced around longer than the timeout which was set on construction. -3. Redis cluster returns to us a ~~~CLUSTERDOWN~~~ error, in which case a ~~~RedisClusterException~~~ is raised. -4. We receive a valid response, in which case the data is returned to the caller. - -## Transactions -The RedisCluster class fully supports MULTI ... EXEC transactions, including commands such as MGET and MSET which operate on multiple keys. There are considerations that must be taken into account here however. - -When you call ~~~RedisCluster->multi()~~~, the cluster is put into a MULTI state, but the MULTI command is not delivered to any nodes until a key is requested on that node. In addition, calls to EXEC will always return an array (even in the event that a transaction to a given node failed), as the commands can be going to any number of nodes depending on what is called. - -Consider the following example: - -~~~php -// Cluster is put into MULTI state locally -$obj_cluster->multi(); - -// The cluster will issue MULTI on this node first (and only once) -$obj_cluster->get("mykey"); -$obj_cluster->set("mykey", "new_value"); - -// If 'myotherkey' maps to a different node, MULTI will be issued there -// before requesting the key -$obj_cluster->get("myotherkey"); - -// This will always return an array, even in the event of a failed transaction -// on one of the nodes, in which case that element will be FALSE -print_r($obj_cluster->exec()); -~~~ - -## Pipelining -The RedisCluster class does not support pipelining as there is no way to detect whether the keys still live where our map indicates that they do and would therefore be inherently unsafe. It would be possible to implement this support as an option if there is demand for such a feature. - -## Multiple key commands -Redis cluster does allow commands that operate on multiple keys, but only if all of those keys hash to the same slot. Note that it is not enough that the keys are all on the same node, but must actually hash to the exact same hash slot. - -For all of these multiple key commands (with the exception of MGET and MSET), the RedisCluster class will verify each key maps to the same hash slot and raise a "CROSSSLOT" warning, returning false if they don't. - -### MGET, MSET, DEL, and UNLINK -RedisCluster has specialized processing for MGET, MSET, DEL, and UNLINK which allows you to send any number of keys (hashing to whichever slots) without having to consider where they live. The way this works, is that the RedisCluster class will split the command as it iterates through keys, delivering a subset of commands per each key's slot. - -*Note: If you send keys that hash to more than one slot, these commands are no longer atomic.* - -~~~php -// This will send two `MGET` commands. One for `{hash1}` keys, and one for `otherkey` -$obj_cluster->mget("{hash1}key1","{hash1}key2","{hash1}key3","otherkey"); -~~~ - -This operation can also be done in MULTI mode transparently. - -## Directed node commands -There are a variety of commands which have to be directed at a specific node. In the case of these commands, the caller can either pass a key (which will be hashed and used to direct our command), or an array with host:port. - -~~~php -// This will be directed at the slot/node which would store "mykey" -$obj_cluster->echo("mykey","Hello World!"); - -// Here we're iterating all of our known masters, and delivering the command there -foreach ($obj_cluster->_masters() as $arr_master) { - $obj_cluster->echo($arr_master, "Hello: " . implode(':', $arr_master)); -} -~~~ - -In the case of all commands which need to be directed at a node, the calling convention is identical to the Redis call, except that they require an additional (first) argument in order to deliver the command. Following is a list of each of these commands: - -1. SAVE -2. BGSAVE -3. FLUSHDB -4. FLUSHALL -5. DBSIZE -6. BGREWRITEAOF -7. LASTSAVE -8. INFO -9. CLIENT -10. CLUSTER -11. CONFIG -12. PUBSUB -13. SLOWLOG -14. RANDOMKEY -15. PING -16. SCAN - -## Session Handler -You can use the cluster functionality of phpredis to store PHP session information in a Redis cluster as you can with a non cluster-enabled Redis instance. - -To do this, you must configure your `session.save_handler` and `session.save_path` INI variables to give phpredis enough information to communicate with the cluster. - -~~~ini -session.save_handler = rediscluster -session.save_path = "seed=host1:port1&seed=host2:port2&seed=hostN:portN&timeout=2&read_timeout=2&failover=error&persistent=1&auth=password&streamverify_peer=0" -~~~ - -### session.session_handler -Set this variable to "rediscluster" to inform phpredis that this is a cluster instance. - -### session.save_path -The save path for cluster based session storage takes the form of a PHP GET request, and requires that you specify at least one `seed` node. Other options you can specify are as follows: - -* _timeout (double)_: The amount of time phpredis will wait when connecting or writing to the cluster. -* _read_timeout (double)_: The amount of time phpredis will wait for a result from the cluster. -* _persistent_: Tells phpredis whether persistent connections should be used. -* _failover (string)_: How phpredis should distribute session reads between master and slave nodes. - * _none_ : phpredis will only communicate with master nodes - * _error_: phpredis will communicate with master nodes unless one fails, in which case an attempt will be made to read session information from a slave. - * _distribute_: phpredis will randomly distribute session reads between masters and any attached slaves (load balancing). -* _auth (string, empty by default)_: The password used to authenticate with the server prior to sending commands. -* _stream (array)_: ssl/tls stream context options.
View file
redis-5.3.7.tgz/redis-5.3.7/cluster_library.c
Deleted
@@ -1,2945 +0,0 @@ -#include "php_redis.h" -#include "common.h" -#include "library.h" -#include "redis_commands.h" -#include "cluster_library.h" -#include "crc16.h" -#include <zend_exceptions.h> - -extern zend_class_entry *redis_cluster_exception_ce; -int le_cluster_slot_cache; - -/* Debugging methods/ -static void cluster_dump_nodes(redisCluster *c) { - redisClusterNode *p; - - ZEND_HASH_FOREACH_PTR(c->nodes, p) { - if (p == NULL) { - continue; - } - - const char *slave = (p->slave) ? "slave" : "master"; - php_printf("%d %s %d %d", p->sock->port, slave,p->sock->prefix_len, - p->slot); - - php_printf("\n"); - } ZEND_HASH_FOREACH_END(); -} - -static void cluster_log(char *fmt, ...) -{ - va_list args; - char buffer1024; - - va_start(args, fmt); - vsnprintf(buffer,sizeof(buffer),fmt,args); - va_end(args); - - fprintf(stderr, "%s\n", buffer); -} - -// Debug function to dump a clusterReply structure recursively -static void dump_reply(clusterReply *reply, int indent) { - smart_string buf = {0}; - int i; - - switch(reply->type) { - case TYPE_ERR: - smart_string_appendl(&buf, "(error) ", sizeof("(error) ")-1); - smart_string_appendl(&buf, reply->str, reply->len); - break; - case TYPE_LINE: - smart_string_appendl(&buf, reply->str, reply->len); - break; - case TYPE_INT: - smart_string_appendl(&buf, "(integer) ", sizeof("(integer) ")-1); - smart_string_append_long(&buf, reply->integer); - break; - case TYPE_BULK: - smart_string_appendl(&buf,"\"", 1); - smart_string_appendl(&buf, reply->str, reply->len); - smart_string_appendl(&buf, "\"", 1); - break; - case TYPE_MULTIBULK: - if (reply->elements < 0) { - smart_string_appendl(&buf, "(nil)", sizeof("(nil)")-1); - } else { - for (i = 0; i < reply->elements; i++) { - dump_reply(reply->elementi, indent+2); - } - } - break; - default: - break; - } - - if (buf.len > 0) { - for (i = 0; i < indent; i++) { - php_printf(" "); - } - - smart_string_0(&buf); - php_printf("%s", buf.c); - php_printf("\n"); - - efree(buf.c); - } -} -*/ - - -/* Recursively free our reply object. If free_data is non-zero we'll also free - * the payload data (strings) themselves. If not, we just free the structs */ -void cluster_free_reply(clusterReply *reply, int free_data) { - long long i; - - switch(reply->type) { - case TYPE_ERR: - case TYPE_LINE: - case TYPE_BULK: - if (free_data && reply->str) - efree(reply->str); - break; - case TYPE_MULTIBULK: - if (reply->element) { - if (reply->elements > 0) { - for (i = 0; i < reply->elements && reply->elementi; i++) { - cluster_free_reply(reply->elementi, free_data); - } - } - efree(reply->element); - } - break; - default: - break; - } - efree(reply); -} - -static int -cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements, - clusterReply **element, int status_strings) -{ - int i; - size_t sz; - clusterReply *r; - long len; - char buf1024; - - for (i = 0; i < elements; i++) { - r = elementi = ecalloc(1, sizeof(clusterReply)); - - // Bomb out, flag error condition on a communication failure - if (redis_read_reply_type(sock, &r->type, &len) < 0) { - return FAILURE; - } - - /* Set our reply len */ - r->len = len; - - switch(r->type) { - case TYPE_ERR: - case TYPE_LINE: - if (redis_sock_gets(sock,buf,sizeof(buf),&sz) < 0) { - return FAILURE; - } - r->len = (long long)sz; - if (status_strings) r->str = estrndup(buf, r->len); - break; - case TYPE_INT: - r->integer = len; - break; - case TYPE_BULK: - if (r->len >= 0) { - r->str = redis_sock_read_bulk_reply(sock,r->len); - if (!r->str) { - return FAILURE; - } - } - break; - case TYPE_MULTIBULK: - r->elements = r->len; - if (r->elements > 0) { - r->element = ecalloc(r->len, sizeof(*r->element)); - if (cluster_multibulk_resp_recursive(sock, r->elements, r->element, status_strings) < 0) { - return FAILURE; - } - } - break; - default: - return FAILURE; - } - } - return SUCCESS; -} - -/* Return the socket for a slot and slave index */ -static RedisSock *cluster_slot_sock(redisCluster *c, unsigned short slot, - zend_ulong slaveidx) -{ - redisClusterNode *node; - - /* Return the master if we're not looking for a slave */ - if (slaveidx == 0) { - return SLOT_SOCK(c, slot); - } - - /* Abort if we can't find this slave */ - if (!SLOT_SLAVES(c, slot) || - (node = zend_hash_index_find_ptr(SLOT_SLAVES(c,slot), slaveidx)) == NULL - ) { - return NULL; - } - - /* Success, return the slave */ - return node->sock; -} - -/* Read the response from a cluster */ -clusterReply *cluster_read_resp(redisCluster *c, int status_strings) {
View file
redis-5.3.7.tgz/redis-5.3.7/cluster_library.h
Deleted
@@ -1,512 +0,0 @@ -#ifndef _PHPREDIS_CLUSTER_LIBRARY_H -#define _PHPREDIS_CLUSTER_LIBRARY_H - -#include "common.h" - -#ifdef ZTS -#include "TSRM.h" -#endif - -/* Redis cluster hash slots and N-1 which we'll use to find it */ -#define REDIS_CLUSTER_SLOTS 16384 -#define REDIS_CLUSTER_MOD (REDIS_CLUSTER_SLOTS-1) - -/* Complete representation for various commands in RESP */ -#define RESP_MULTI_CMD "*1\r\n$5\r\nMULTI\r\n" -#define RESP_EXEC_CMD "*1\r\n$4\r\nEXEC\r\n" -#define RESP_DISCARD_CMD "*1\r\n$7\r\nDISCARD\r\n" -#define RESP_UNWATCH_CMD "*1\r\n$7\r\nUNWATCH\r\n" -#define RESP_CLUSTER_SLOTS_CMD "*2\r\n$7\r\nCLUSTER\r\n$5\r\nSLOTS\r\n" -#define RESP_ASKING_CMD "*1\r\n$6\r\nASKING\r\n" -#define RESP_READONLY_CMD "*1\r\n$8\r\nREADONLY\r\n" -#define RESP_READWRITE_CMD "*1\r\n$9\r\nREADWRITE\r\n" - -#define RESP_READONLY_CMD_LEN (sizeof(RESP_READONLY_CMD)-1) - -/* MOVED/ASK comparison macros */ -#define IS_MOVED(p) (p0=='M' && p1=='O' && p2=='V' && p3=='E' && \ - p4=='D' && p5==' ') -#define IS_ASK(p) (p0=='A' && p1=='S' && p2=='K' && p3==' ') - -/* MOVED/ASK lengths */ -#define MOVED_LEN (sizeof("MOVED ")-1) -#define ASK_LEN (sizeof("ASK ")-1) - -/* Initial allocation size for key distribution container */ -#define CLUSTER_KEYDIST_ALLOC 8 - -/* Macros to access nodes, sockets, and streams for a given slot */ -#define SLOT(c,s) (c->masters) -#define SLOT_SOCK(c,s) (SLOT(c,s)->sock) -#define SLOT_STREAM(c,s) (SLOT_SOCK(c,s)->stream) -#define SLOT_SLAVES(c,s) (c->masters->slaves) - -/* Macros to access socket and stream for the node we're communicating with */ -#define CMD_SOCK(c) (c->cmd_sock) -#define CMD_STREAM(c) (c->cmd_sock->stream) - -/* Compare redirection slot information with the passed node */ -#define CLUSTER_REDIR_CMP(c, sock) \ - (sock->port != c->redir_port || \ - ZSTR_LEN(sock->host) != c->redir_host_len || \ - memcmp(ZSTR_VAL(sock->host),c->redir_host,c->redir_host_len)) - -/* Clear out our "last error" */ -#define CLUSTER_CLEAR_ERROR(c) do { \ - if (c->err) { \ - zend_string_release(c->err); \ - c->err = NULL; \ - } \ - c->clusterdown = 0; \ -} while (0) - -/* Protected sending of data down the wire to a RedisSock->stream */ -#define CLUSTER_SEND_PAYLOAD(sock, buf, len) \ - (sock && !redis_sock_server_open(sock) && sock->stream && !redis_check_eof(sock, 1 ) && \ - php_stream_write(sock->stream, buf, len)==len) - -/* Macro to read our reply type character */ -#define CLUSTER_VALIDATE_REPLY_TYPE(sock, type) \ - (redis_check_eof(sock, 1) == 0 && \ - (php_stream_getc(sock->stream) == type)) - -/* Reset our last single line reply buffer and length */ -#define CLUSTER_CLEAR_REPLY(c) \ - *c->line_reply = '\0'; c->reply_len = 0; - -/* Helper to determine if we're in MULTI mode */ -#define CLUSTER_IS_ATOMIC(c) (c->flags->mode != MULTI) - -/* Helper that either returns false or adds false in multi mode */ -#define CLUSTER_RETURN_FALSE(c) \ - if(CLUSTER_IS_ATOMIC(c)) { \ - RETURN_FALSE; \ - } else { \ - add_next_index_bool(&c->multi_resp, 0); \ - return; \ - } - -/* Helper to either return a bool value or add it to MULTI response */ -#define CLUSTER_RETURN_BOOL(c, b) \ - if(CLUSTER_IS_ATOMIC(c)) { \ - RETURN_BOOL(b); \ - } else { \ - add_next_index_bool(&c->multi_resp, b); \ - } - -/* Helper to respond with a double or add it to our MULTI response */ -#define CLUSTER_RETURN_DOUBLE(c, d) \ - if(CLUSTER_IS_ATOMIC(c)) { \ - RETURN_DOUBLE(d); \ - } else { \ - add_next_index_double(&c->multi_resp, d); \ - } - -/* Helper to return a string value */ -#define CLUSTER_RETURN_STRING(c, str, len) \ - if(CLUSTER_IS_ATOMIC(c)) { \ - RETVAL_STRINGL(str, len); \ - } else { \ - add_next_index_stringl(&c->multi_resp, str, len); \ - } \ - -/* Return a LONG value */ -#define CLUSTER_RETURN_LONG(c, val) \ - if(CLUSTER_IS_ATOMIC(c)) { \ - RETURN_LONG(val); \ - } else { \ - add_next_index_long(&c->multi_resp, val); \ - } - -/* Macro to clear out a clusterMultiCmd structure */ -#define CLUSTER_MULTI_CLEAR(mc) \ - mc->cmd.len = 0; \ - mc->args.len = 0; \ - mc->argc = 0; \ - -/* Initialzie a clusterMultiCmd with a keyword and length */ -#define CLUSTER_MULTI_INIT(mc, keyword, keyword_len) \ - mc.kw = keyword; \ - mc.kw_len = keyword_len; \ - -#define CLUSTER_CACHING_ENABLED() (INI_INT("redis.clusters.cache_slots") == 1) - -/* Cluster redirection enum */ -typedef enum CLUSTER_REDIR_TYPE { - REDIR_NONE, - REDIR_MOVED, - REDIR_ASK -} CLUSTER_REDIR_TYPE; - -/* MULTI BULK response callback typedef */ -typedef int (*mbulk_cb)(RedisSock*,zval*,long long, void*); - -/* A list of covered slot ranges */ -typedef struct redisSlotRange { - unsigned short low; - unsigned short high; -} redisSlotRange; - -/* Simple host/port information for our cache */ -typedef struct redisCachedHost { - zend_string *addr; - unsigned short port; -} redisCachedHost; - -/* Storage for a cached master node */ -typedef struct redisCachedMaster { - redisCachedHost host; - - redisSlotRange *slot; /* Slots and count */ - size_t slots; - - redisCachedHost *slave; /* Slaves and their count */ - size_t slaves; -} redisCachedMaster; - -typedef struct redisCachedCluster { - // int rsrc_id; /* Zend resource ID */ - zend_string *hash; /* What we're cached by */ - redisCachedMaster *master; /* Array of masters */ - size_t count; /* Number of masters */ -} redisCachedCluster; - -/* A Redis Cluster master node */ -typedef struct redisClusterNode { - RedisSock *sock; /* Our Redis socket in question */ - short slot; /* One slot we believe this node serves */ - zend_llist slots; /* List of all slots we believe this node serves */ - unsigned short slave; /* Are we a slave */ - HashTable *slaves; /* Hash table of slaves */ -} redisClusterNode; - -/* Forward declarations */ -typedef struct clusterFoldItem clusterFoldItem; - -/* RedisCluster implementation structure */ -typedef struct redisCluster { - - /* One RedisSock struct for serialization and prefix information */ - RedisSock *flags; - - /* How long in milliseconds should we wait when being bounced around */ - long waitms; - - /* Are we flagged as being in readonly mode, meaning we could fall back to - * a given master's slave */ - short readonly; - - /* RedisCluster failover options (never, on error, to load balance) */
View file
redis-5.3.7.tgz/redis-5.3.7/common.h
Deleted
@@ -1,785 +0,0 @@ -#include "php.h" -#include "php_ini.h" - -#ifndef REDIS_COMMON_H -#define REDIS_COMMON_H - -#define PHPREDIS_NOTUSED(v) ((void)v) - -#include "zend_llist.h" -#include <ext/standard/php_var.h> -#include <ext/standard/php_math.h> -#include <zend_smart_str.h> -#include <ext/standard/php_smart_string.h> - -#define PHPREDIS_GET_OBJECT(class_entry, o) (class_entry *)((char *)o - XtOffsetOf(class_entry, std)) -#define PHPREDIS_ZVAL_GET_OBJECT(class_entry, z) PHPREDIS_GET_OBJECT(class_entry, Z_OBJ_P(z)) - -/* NULL check so Eclipse doesn't go crazy */ -#ifndef NULL -#define NULL ((void *) 0) -#endif - -#include "backoff.h" - -typedef enum { - REDIS_SOCK_STATUS_FAILED = -1, - REDIS_SOCK_STATUS_DISCONNECTED, - REDIS_SOCK_STATUS_CONNECTED, - REDIS_SOCK_STATUS_READY -} redis_sock_status; - -#define _NL "\r\n" - -/* properties */ -#define REDIS_NOT_FOUND 0 -#define REDIS_STRING 1 -#define REDIS_SET 2 -#define REDIS_LIST 3 -#define REDIS_ZSET 4 -#define REDIS_HASH 5 -#define REDIS_STREAM 6 - -#ifdef PHP_WIN32 -#define PHP_REDIS_API __declspec(dllexport) -#define phpredis_atoi64(p) _atoi64((p)) -#else -#define PHP_REDIS_API -#define phpredis_atoi64(p) atoll((p)) -#endif - -/* reply types */ -typedef enum _REDIS_REPLY_TYPE { - TYPE_EOF = -1, - TYPE_LINE = '+', - TYPE_INT = ':', - TYPE_ERR = '-', - TYPE_BULK = '$', - TYPE_MULTIBULK = '*' -} REDIS_REPLY_TYPE; - -/* SCAN variants */ -typedef enum _REDIS_SCAN_TYPE { - TYPE_SCAN, - TYPE_SSCAN, - TYPE_HSCAN, - TYPE_ZSCAN -} REDIS_SCAN_TYPE; - -/* PUBSUB subcommands */ -typedef enum _PUBSUB_TYPE { - PUBSUB_CHANNELS, - PUBSUB_NUMSUB, - PUBSUB_NUMPAT -} PUBSUB_TYPE; - -/* options */ -#define REDIS_OPT_SERIALIZER 1 -#define REDIS_OPT_PREFIX 2 -#define REDIS_OPT_READ_TIMEOUT 3 -#define REDIS_OPT_SCAN 4 -#define REDIS_OPT_FAILOVER 5 -#define REDIS_OPT_TCP_KEEPALIVE 6 -#define REDIS_OPT_COMPRESSION 7 -#define REDIS_OPT_REPLY_LITERAL 8 -#define REDIS_OPT_COMPRESSION_LEVEL 9 -#define REDIS_OPT_NULL_MBULK_AS_NULL 10 -#define REDIS_OPT_MAX_RETRIES 11 -#define REDIS_OPT_BACKOFF_ALGORITHM 12 -#define REDIS_OPT_BACKOFF_BASE 13 -#define REDIS_OPT_BACKOFF_CAP 14 - -/* cluster options */ -#define REDIS_FAILOVER_NONE 0 -#define REDIS_FAILOVER_ERROR 1 -#define REDIS_FAILOVER_DISTRIBUTE 2 -#define REDIS_FAILOVER_DISTRIBUTE_SLAVES 3 -/* serializers */ -typedef enum { - REDIS_SERIALIZER_NONE, - REDIS_SERIALIZER_PHP, - REDIS_SERIALIZER_IGBINARY, - REDIS_SERIALIZER_MSGPACK, - REDIS_SERIALIZER_JSON -} redis_serializer; -/* compression */ -#define REDIS_COMPRESSION_NONE 0 -#define REDIS_COMPRESSION_LZF 1 -#define REDIS_COMPRESSION_ZSTD 2 -#define REDIS_COMPRESSION_LZ4 3 - -/* SCAN options */ -#define REDIS_SCAN_NORETRY 0 -#define REDIS_SCAN_RETRY 1 -#define REDIS_SCAN_PREFIX 2 -#define REDIS_SCAN_NOPREFIX 3 - -/* BACKOFF_ALGORITHM options */ -#define REDIS_BACKOFF_ALGORITHMS 7 -#define REDIS_BACKOFF_ALGORITHM_DEFAULT 0 -#define REDIS_BACKOFF_ALGORITHM_DECORRELATED_JITTER 1 -#define REDIS_BACKOFF_ALGORITHM_FULL_JITTER 2 -#define REDIS_BACKOFF_ALGORITHM_EQUAL_JITTER 3 -#define REDIS_BACKOFF_ALGORITHM_EXPONENTIAL 4 -#define REDIS_BACKOFF_ALGORITHM_UNIFORM 5 -#define REDIS_BACKOFF_ALGORITHM_CONSTANT 6 - -/* GETBIT/SETBIT offset range limits */ -#define BITOP_MIN_OFFSET 0 -#define BITOP_MAX_OFFSET 4294967295U - -/* Transaction modes */ -#define ATOMIC 0 -#define MULTI 1 -#define PIPELINE 2 - -#define PHPREDIS_DEBUG_LOGGING 0 - -#if PHPREDIS_DEBUG_LOGGING == 1 -#define redisDbgFmt(fmt, ...) \ - php_printf("%s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, __VA_ARGS__) -#define redisDbgStr(str) phpredisDebugFmt("%s", str) -#else -#define redisDbgFmt(fmt, ...) ((void)0) -#define redisDbgStr(str) ((void)0) -#endif - -#define IS_ATOMIC(redis_sock) (redis_sock->mode == ATOMIC) -#define IS_MULTI(redis_sock) (redis_sock->mode & MULTI) -#define IS_PIPELINE(redis_sock) (redis_sock->mode & PIPELINE) - -#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) do { \ - if (redis_sock->pipeline_cmd == NULL) { \ - redis_sock->pipeline_cmd = zend_string_init(cmd, cmd_len, 0); \ - } else { \ - size_t pipeline_len = ZSTR_LEN(redis_sock->pipeline_cmd); \ - redis_sock->pipeline_cmd = zend_string_realloc(redis_sock->pipeline_cmd, pipeline_len + cmd_len, 0); \ - memcpy(&ZSTR_VAL(redis_sock->pipeline_cmd)pipeline_len, cmd, cmd_len); \ - } \ -} while (0) - -#define SOCKET_WRITE_COMMAND(redis_sock, cmd, cmd_len) \ - if(redis_sock_write(redis_sock, cmd, cmd_len) < 0) { \ - efree(cmd); \ - RETURN_FALSE; \ -} - -#define REDIS_SAVE_CALLBACK(callback, closure_context) do { \ - fold_item *fi = malloc(sizeof(fold_item)); \ - fi->fun = callback; \ - fi->ctx = closure_context; \ - fi->next = NULL; \ - if (redis_sock->current) { \ - redis_sock->current->next = fi; \ - } \ - redis_sock->current = fi; \ - if (NULL == redis_sock->head) { \ - redis_sock->head = redis_sock->current; \ - } \ -} while (0) - -#define REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len) \ - if (IS_PIPELINE(redis_sock)) { \ - PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len); \ - } else { \ - SOCKET_WRITE_COMMAND(redis_sock, cmd, cmd_len); \ - } \ - efree(cmd); - -#define REDIS_PROCESS_RESPONSE_CLOSURE(function, closure_context) \ - if (!IS_PIPELINE(redis_sock)) { \ - if (redis_response_enqueued(redis_sock) != SUCCESS) { \ - RETURN_FALSE; \ - } \ - } \ - REDIS_SAVE_CALLBACK(function, closure_context); \ - RETURN_ZVAL(getThis(), 1, 0); \ - -#define REDIS_PROCESS_RESPONSE(function) else { \ - REDIS_PROCESS_RESPONSE_CLOSURE(function, NULL) \
View file
redis-5.3.7.tgz/redis-5.3.7/config.m4
Deleted
@@ -1,327 +0,0 @@ -dnl $Id$ -dnl config.m4 for extension redis - -PHP_ARG_ENABLE(redis, whether to enable redis support, -dnl Make sure that the comment is aligned: - --enable-redis Enable redis support) - -PHP_ARG_ENABLE(redis-session, whether to enable sessions, - --disable-redis-session Disable session support, yes, no) - -PHP_ARG_ENABLE(redis-json, whether to enable json serializer support, - --disable-redis-json Disable json serializer support, yes, no) - -PHP_ARG_ENABLE(redis-igbinary, whether to enable igbinary serializer support, - --enable-redis-igbinary Enable igbinary serializer support, no, no) - -PHP_ARG_ENABLE(redis-msgpack, whether to enable msgpack serializer support, - --enable-redis-msgpack Enable msgpack serializer support, no, no) - -PHP_ARG_ENABLE(redis-lzf, whether to enable lzf compression, - --enable-redis-lzf Enable lzf compression support, no, no) - -PHP_ARG_WITH(liblzf, use system liblzf, - --with-liblzf=DIR Use system liblzf, no, no) - -PHP_ARG_ENABLE(redis-zstd, whether to enable Zstd compression, - --enable-redis-zstd Enable Zstd compression support, no, no) - -PHP_ARG_WITH(libzstd, use system libsztd, - --with-libzstd=DIR Use system libzstd, yes, no) - -PHP_ARG_ENABLE(redis-lz4, whether to enable lz4 compression, - --enable-redis-lz4 Enable lz4 compression support, no, no) - -PHP_ARG_WITH(liblz4, use system liblz4, - --with-liblz4=DIR Use system liblz4, no, no) - -if test "$PHP_REDIS" != "no"; then - - if test "$PHP_REDIS_SESSION" != "no"; then - AC_DEFINE(PHP_SESSION,1,redis sessions) - fi - - AC_MSG_CHECKING(for hash includes) - hash_inc_path="" - if test -f "$abs_srcdir/include/php/ext/hash/php_hash.h"; then - hash_inc_path="$abs_srcdir/include/php" - elif test -f "$abs_srcdir/ext/hash/php_hash.h"; then - hash_inc_path="$abs_srcdir" - elif test -f "$phpincludedir/ext/hash/php_hash.h"; then - hash_inc_path="$phpincludedir" - else - for i in php php7; do - if test -f "$prefix/include/$i/ext/hash/php_hash.h"; then - hash_inc_path="$prefix/include/$i" - fi - done - fi - - if test "$hash_inc_path" = ""; then - AC_MSG_ERROR(Cannot find php_hash.h) - else - AC_MSG_RESULT($hash_inc_path) - fi - - if test "$PHP_REDIS_JSON" != "no"; then - AC_MSG_CHECKING(for json includes) - json_inc_path="" - if test -f "$abs_srcdir/include/php/ext/json/php_json.h"; then - json_inc_path="$abs_srcdir/include/php" - elif test -f "$abs_srcdir/ext/json/php_json.h"; then - json_inc_path="$abs_srcdir" - elif test -f "$phpincludedir/ext/json/php_json.h"; then - json_inc_path="$phpincludedir" - else - for i in php php7; do - if test -f "$prefix/include/$i/ext/json/php_json.h"; then - json_inc_path="$prefix/include/$i" - fi - done - fi - - if test "$json_inc_path" = ""; then - AC_MSG_ERROR(Cannot find php_json.h) - else - AC_MSG_RESULT($json_inc_path) - fi - fi - - AC_MSG_CHECKING(for redis json support) - if test "$PHP_REDIS_JSON" != "no"; then - AC_MSG_RESULT(enabled) - AC_DEFINE(HAVE_REDIS_JSON,1,Whether redis json serializer is enabled) - JSON_INCLUDES="-I$json_inc_path" - JSON_EXT_DIR="$json_inc_path/ext" - ifdef(PHP_ADD_EXTENSION_DEP, - - PHP_ADD_EXTENSION_DEP(redis, json) - ) - PHP_ADD_INCLUDE($JSON_EXT_DIR) - else - JSON_INCLUDES="" - AC_MSG_RESULT(disabled) - fi - - if test "$PHP_REDIS_IGBINARY" != "no"; then - AC_MSG_CHECKING(for igbinary includes) - igbinary_inc_path="" - - if test -f "$abs_srcdir/include/php/ext/igbinary/igbinary.h"; then - igbinary_inc_path="$abs_srcdir/include/php" - elif test -f "$abs_srcdir/ext/igbinary/igbinary.h"; then - igbinary_inc_path="$abs_srcdir" - elif test -f "$phpincludedir/ext/igbinary/igbinary.h"; then - igbinary_inc_path="$phpincludedir" - else - for i in php php7; do - if test -f "$prefix/include/$i/ext/igbinary/igbinary.h"; then - igbinary_inc_path="$prefix/include/$i" - fi - done - fi - - if test "$igbinary_inc_path" = ""; then - AC_MSG_ERROR(Cannot find igbinary.h) - else - AC_MSG_RESULT($igbinary_inc_path) - fi - fi - - AC_MSG_CHECKING(for redis igbinary support) - if test "$PHP_REDIS_IGBINARY" != "no"; then - AC_MSG_RESULT(enabled) - AC_DEFINE(HAVE_REDIS_IGBINARY,1,Whether redis igbinary serializer is enabled) - IGBINARY_INCLUDES="-I$igbinary_inc_path" - IGBINARY_EXT_DIR="$igbinary_inc_path/ext" - ifdef(PHP_ADD_EXTENSION_DEP, - - PHP_ADD_EXTENSION_DEP(redis, igbinary) - ) - PHP_ADD_INCLUDE($IGBINARY_EXT_DIR) - else - IGBINARY_INCLUDES="" - AC_MSG_RESULT(disabled) - fi - - if test "$PHP_REDIS_MSGPACK" != "no"; then - AC_MSG_CHECKING(for msgpack includes) - msgpack_inc_path="" - - if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then - msgpack_inc_path="$abs_srcdir/include/php" - elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then - msgpack_inc_path="$abs_srcdir" - elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then - msgpack_inc_path="$phpincludedir" - else - for i in php php7; do - if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then - msgpack_inc_path="$prefix/include/$i" - fi - done - fi - - if test "$msgpack_inc_path" = ""; then - AC_MSG_ERROR(Cannot find php_msgpack.h) - else - AC_MSG_RESULT($msgpack_inc_path) - fi - fi - - if test "$PHP_REDIS_MSGPACK" != "no"; then - AC_MSG_CHECKING(for php msgpack version >= 2.0.3) - MSGPACK_VERSION=`$EGREP "define PHP_MSGPACK_VERSION" $msgpack_inc_path/ext/msgpack/php_msgpack.h | $SED -e 's/^0-9\.//g'` - if test `echo $MSGPACK_VERSION | $SED -e 's/^0-9/ /g' | $AWK '{print $1*1000 + $2*100 + $3*10 + $4}'` -lt 2030; then - AC_MSG_ERROR(version >= 2.0.3 required) - else - AC_MSG_RESULT(yes) - fi - - AC_DEFINE(HAVE_REDIS_MSGPACK,1,Whether redis msgpack serializer is enabled) - MSGPACK_INCLUDES="-I$msgpack_inc_path" - MSGPACK_EXT_DIR="$msgpack_inc_path/ext" - ifdef(PHP_ADD_EXTENSION_DEP, - - PHP_ADD_EXTENSION_DEP(redis, msgpack) - ) - PHP_ADD_INCLUDE($MSGPACK_EXT_DIR) - else - MSGPACK_INCLUDES="" - fi - - AC_PATH_PROG(PKG_CONFIG, pkg-config, no) - - if test "$PHP_REDIS_LZF" != "no"; then - AC_DEFINE(HAVE_REDIS_LZF, 1, ) - - if test "$PHP_LIBLZF" = "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists liblzf; then - AC_MSG_CHECKING(for liblzf using pkg-config)
View file
redis-5.3.7.tgz/redis-5.3.7/library.c
Deleted
@@ -1,3666 +0,0 @@ -#include "php_redis.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "common.h" -#include "php_network.h" -#include <sys/types.h> - -#ifdef HAVE_REDIS_IGBINARY -#include "igbinary/igbinary.h" -#endif -#ifdef HAVE_REDIS_MSGPACK -#include "msgpack/php_msgpack.h" -#endif - -#ifdef HAVE_REDIS_LZF -#include <lzf.h> - - #ifndef LZF_MARGIN - #define LZF_MARGIN 128 - #endif -#endif - -#ifdef HAVE_REDIS_ZSTD -#include <zstd.h> -#endif - -#ifdef HAVE_REDIS_LZ4 -#include <lz4.h> -#include <lz4hc.h> - -/* uint8_t crf + int length */ -#define REDIS_LZ4_HDR_SIZE (sizeof(uint8_t) + sizeof(int)) -#if defined(LZ4HC_CLEVEL_MAX) -/* version >= 1.7.5 */ -#define REDIS_LZ4_MAX_CLEVEL LZ4HC_CLEVEL_MAX - -#elif defined (LZ4HC_MAX_CLEVEL) -/* version >= 1.7.3 */ -#define REDIS_LZ4_MAX_CLEVEL LZ4HC_MAX_CLEVEL - -#else -/* older versions */ -#define REDIS_LZ4_MAX_CLEVEL 12 -#endif -#endif - -#include <zend_exceptions.h> -#include "php_redis.h" -#include "library.h" -#include "redis_commands.h" - -#ifdef HAVE_REDIS_JSON -#include <ext/json/php_json.h> -#endif - -#include <ext/standard/php_rand.h> -#include <ext/hash/php_hash.h> - -#define UNSERIALIZE_NONE 0 -#define UNSERIALIZE_KEYS 1 -#define UNSERIALIZE_VALS 2 -#define UNSERIALIZE_ALL 3 - -#define SCORE_DECODE_NONE 0 -#define SCORE_DECODE_INT 1 -#define SCORE_DECODE_DOUBLE 2 - -#ifndef PHP_WIN32 - #include <netinet/tcp.h> /* TCP_NODELAY */ - #include <sys/socket.h> /* SO_KEEPALIVE */ -#else - #include <winsock.h> -#endif - -extern zend_class_entry *redis_ce; -extern zend_class_entry *redis_exception_ce; - -extern int le_redis_pconnect; - -static int redis_mbulk_reply_zipped_raw_variant(RedisSock *redis_sock, zval *zret, int count); - -/* Register a persistent resource in a a way that works for every PHP 7 version. */ -void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id) { -#if PHP_VERSION_ID < 70300 - zend_resource res; - res.type = le_id; - res.ptr = ptr; - - zend_hash_str_update_mem(&EG(persistent_list), ZSTR_VAL(id), ZSTR_LEN(id), &res, sizeof(res)); -#else - zend_register_persistent_resource(ZSTR_VAL(id), ZSTR_LEN(id), ptr, le_id); -#endif -} - -static ConnectionPool * -redis_sock_get_connection_pool(RedisSock *redis_sock) -{ - ConnectionPool *pool; - zend_resource *le; - zend_string *persistent_id; - - /* Generate our unique pool id depending on configuration */ - persistent_id = redis_pool_spprintf(redis_sock, INI_STR("redis.pconnect.pool_pattern")); - - /* Return early if we can find the pool */ - if ((le = zend_hash_find_ptr(&EG(persistent_list), persistent_id))) { - zend_string_release(persistent_id); - return le->ptr; - } - - /* Create the pool and store it in our persistent list */ - pool = pecalloc(1, sizeof(*pool), 1); - zend_llist_init(&pool->list, sizeof(php_stream *), NULL, 1); - redis_register_persistent_resource(persistent_id, pool, le_redis_pconnect); - - zend_string_release(persistent_id); - return pool; -} - -/* Helper to reselect the proper DB number when we reconnect */ -static int reselect_db(RedisSock *redis_sock) { - char *cmd, *response; - int cmd_len, response_len; - - cmd_len = redis_spprintf(redis_sock, NULL, &cmd, "SELECT", "d", - redis_sock->dbNumber); - - if (redis_sock_write(redis_sock, cmd, cmd_len) < 0) { - efree(cmd); - return -1; - } - - efree(cmd); - - if ((response = redis_sock_read(redis_sock, &response_len)) == NULL) { - return -1; - } - - if (strncmp(response, "+OK", 3)) { - efree(response); - return -1; - } - - efree(response); - return 0; -} - -/* Attempt to read a single +OK response */ -static int redis_sock_read_ok(RedisSock *redis_sock) { - char buf64; - size_t len; - - if (redis_sock_read_single_line(redis_sock, buf, sizeof(buf), &len, 0) < 0) - return FAILURE; - - return REDIS_STRCMP_STATIC(buf, len, "OK") ? SUCCESS : FAILURE; -} - -/* Append an AUTH command to a smart string if neccessary. This will either - * append the new style AUTH <user> <password>, old style AUTH <password>, or - * append no command at all. Function returns 1 if we appended a command - * and 0 otherwise. */ -static int redis_sock_append_auth(RedisSock *redis_sock, smart_string *str) { - /* We need a password at least */ - if (redis_sock->pass == NULL) - return 0; - - REDIS_CMD_INIT_SSTR_STATIC(str, !!redis_sock->user + !!redis_sock->pass, "AUTH"); - - if (redis_sock->user) - redis_cmd_append_sstr_zstr(str, redis_sock->user); - - redis_cmd_append_sstr_zstr(str, redis_sock->pass); - - /* We appended a command */ - return 1; -} - -PHP_REDIS_API void -redis_sock_copy_auth(RedisSock *dst, RedisSock *src) { - redis_sock_set_auth(dst, src->user, src->pass); -} - -PHP_REDIS_API void -redis_sock_set_auth(RedisSock *redis_sock, zend_string *user, zend_string *pass) -{ - /* Release existing user/pass */ - redis_sock_free_auth(redis_sock); - - /* Set new user/pass */ - redis_sock->user = user ? zend_string_copy(user) : NULL; - redis_sock->pass = pass ? zend_string_copy(pass) : NULL; -} - - -PHP_REDIS_API void
View file
redis-5.3.7.tgz/redis-5.3.7/library.h
Deleted
@@ -1,192 +0,0 @@ -#ifndef REDIS_LIBRARY_H -#define REDIS_LIBRARY_H - -/* Non cluster command helper */ -#define REDIS_SPPRINTF(ret, kw, fmt, ...) \ - redis_spprintf(redis_sock, NULL, ret, kw, fmt, ##__VA_ARGS__) - -#define REDIS_CMD_APPEND_SSTR_STATIC(sstr, str) \ - redis_cmd_append_sstr(sstr, str, sizeof(str)-1); - -#define REDIS_CMD_APPEND_SSTR_OPT_STATIC(sstr, opt, str) \ - if (opt) REDIS_CMD_APPEND_SSTR_STATIC(sstr, str); - -#define REDIS_CMD_INIT_SSTR_STATIC(sstr, argc, keyword) \ - redis_cmd_init_sstr(sstr, argc, keyword, sizeof(keyword)-1); - -#define REDIS_THROW_EXCEPTION(msg, code) \ - zend_throw_exception(redis_exception_ce, (msg), code) - -#define CLUSTER_THROW_EXCEPTION(msg, code) \ - zend_throw_exception(redis_cluster_exception_ce, (msg), code) - -#define redis_sock_write_sstr(redis_sock, sstr) \ - redis_sock_write(redis_sock, (sstr)->c, (sstr)->len) - -#if PHP_VERSION_ID < 80000 - #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(ZSTR_VAL((zstr)), ZSTR_LEN((zstr))) -#else - #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(zstr) -#endif - -void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id); - -PHP_REDIS_API int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass); - -int redis_cmd_init_sstr(smart_string *str, int num_args, char *keyword, int keyword_len); -int redis_cmd_append_sstr(smart_string *str, char *append, int append_len); -int redis_cmd_append_sstr_int(smart_string *str, int append); -int redis_cmd_append_sstr_long(smart_string *str, long append); -int redis_cmd_append_sstr_i64(smart_string *str, int64_t append); -int redis_cmd_append_sstr_dbl(smart_string *str, double value); -int redis_cmd_append_sstr_zstr(smart_string *str, zend_string *zstr); -int redis_cmd_append_sstr_zval(smart_string *str, zval *z, RedisSock *redis_sock); -int redis_cmd_append_sstr_key(smart_string *str, char *key, size_t len, RedisSock *redis_sock, short *slot); -int redis_cmd_append_sstr_arrkey(smart_string *cmd, zend_string *kstr, zend_ulong idx); - -PHP_REDIS_API int redis_spprintf(RedisSock *redis_sock, short *slot, char **ret, char *kw, char *fmt, ...); -PHP_REDIS_API zend_string *redis_pool_spprintf(RedisSock *redis_sock, char *fmt, ...); - -PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len); -PHP_REDIS_API int redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size, size_t* line_len); -PHP_REDIS_API int redis_1_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval* z_tab, void *ctx); -typedef void (*SuccessCallback)(RedisSock *redis_sock); -PHP_REDIS_API int redis_boolean_response_impl(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx, SuccessCallback success_callback); -PHP_REDIS_API int redis_boolean_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API void redis_single_line_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - zval *z_tab, void *ctx); -PHP_REDIS_API int redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API void redis_parse_info_response(char *response, zval *z_ret); -PHP_REDIS_API void redis_parse_client_list_response(char *response, zval *z_ret); -PHP_REDIS_API int redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API RedisSock* redis_sock_create(char *host, int host_len, int port, double timeout, double read_timeout, int persistent, char *persistent_id, long retry_interval); -PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock); -PHP_REDIS_API int redis_sock_server_open(RedisSock *redis_sock); -PHP_REDIS_API int redis_sock_auth(RedisSock *redis_sock); -PHP_REDIS_API char *redis_sock_auth_cmd(RedisSock *redis_sock, int *cmdlen); -PHP_REDIS_API void redis_sock_set_auth(RedisSock *redis_sock, zend_string *user, zend_string *pass); -PHP_REDIS_API void redis_sock_set_auth_zval(RedisSock *redis_sock, zval *zv); -PHP_REDIS_API void redis_sock_copy_auth(RedisSock *dst, RedisSock *src); -PHP_REDIS_API void redis_sock_free_auth(RedisSock *redis_sock); -PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock, int force); -PHP_REDIS_API zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab); -PHP_REDIS_API int redis_sock_read_single_line(RedisSock *redis_sock, char *buffer, - size_t buflen, size_t *linelen, int set_err); -PHP_REDIS_API char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes); -PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *_z_tab, void *ctx); -PHP_REDIS_API void redis_mbulk_reply_loop(RedisSock *redis_sock, zval *z_tab, int count, int unserialize); - - -PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_mbulk_reply_zipped_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_mbulk_reply_zipped_vals(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_mbulk_reply_zipped_keys_int(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_mbulk_reply_zipped_keys_dbl(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); - -PHP_REDIS_API int redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, REDIS_SCAN_TYPE type, zend_long *iter); - - -PHP_REDIS_API int redis_xrange_reply(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_xread_reply(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_xclaim_reply(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_xinfo_reply(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); - -PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_unsubscribe_response(INTERNAL_FUNCTION_PARAMETERS, - RedisSock *redis_sock, zval *z_tab, void *ctx); - -PHP_REDIS_API int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz); -PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw); -PHP_REDIS_API RedisSock *redis_sock_get(zval *id, int nothrow); -PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock); -PHP_REDIS_API void redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len); -PHP_REDIS_API int redis_sock_set_stream_context(RedisSock *redis_sock, zval *options); - -PHP_REDIS_API int -redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len); -PHP_REDIS_API int -redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len); - -PHP_REDIS_API int -redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret); - -PHP_REDIS_API int -redis_compress(RedisSock *redis_sock, char **dst, size_t *dstlen, char *buf, size_t len); -PHP_REDIS_API int -redis_uncompress(RedisSock *redis_sock, char **dst, size_t *dstlen, const char *src, size_t len); - -PHP_REDIS_API int redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len); -PHP_REDIS_API int redis_unpack(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret); - -PHP_REDIS_API int -redis_read_stream_messages(RedisSock *redis_sock, int count, zval *z_ret); -PHP_REDIS_API int -redis_read_stream_messages_multi(RedisSock *redis_sock, int count, zval *z_ret); -PHP_REDIS_API int -redis_read_xclaim_response(RedisSock *redis_sock, int count, zval *rv); -PHP_REDIS_API int -redis_read_xinfo_response(RedisSock *redis_sock, zval *z_ret, int elements); - -/* Specialized ACL reply handlers */ -PHP_REDIS_API int redis_read_acl_getuser_reply(RedisSock *redis_sock, zval *zret, long len); -PHP_REDIS_API int redis_acl_getuser_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_read_acl_log_reply(RedisSock *redis_sock, zval *zret, long count); -PHP_REDIS_API int redis_acl_log_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); - -/* -* Variant Read methods, mostly to implement eval -*/ - -PHP_REDIS_API int redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type, long *reply_info); -PHP_REDIS_API int redis_read_variant_bulk(RedisSock *redis_sock, int size, zval *z_ret); -PHP_REDIS_API int redis_read_multibulk_recursive(RedisSock *redis_sock, long long elements, int status_strings, zval *z_ret); -PHP_REDIS_API int redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_read_raw_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_read_variant_reply_strings(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); -PHP_REDIS_API int redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); - -/* Helper methods to get configuration values from a HashTable. */ - -#define REDIS_HASH_STR_FIND_STATIC(ht, sstr) \ - zend_hash_str_find(ht, sstr, sizeof(sstr) - 1) -#define REDIS_HASH_STR_FIND_TYPE_STATIC(ht, sstr, type) \ - redis_hash_str_find_type(ht, sstr, sizeof(sstr) - 1, type) - -#define REDIS_CONF_DOUBLE_STATIC(ht, sstr, dval) \ - redis_conf_double(ht, sstr, sizeof(sstr) - 1, dval) -#define REDIS_CONF_BOOL_STATIC(ht, sstr, rval) \ - redis_conf_bool(ht, sstr, sizeof(sstr) - 1, rval) -#define REDIS_CONF_ZEND_BOOL_STATIC(ht, sstr, bval) \ - redis_conf_zend_bool(ht, sstr, sizeof(sstr) - 1, bval) -#define REDIS_CONF_LONG_STATIC(ht, sstr, lval) \ - redis_conf_long(ht, sstr, sizeof(sstr) - 1, lval) -#define REDIS_CONF_INT_STATIC(ht, sstr, ival) \ - redis_conf_int(ht, sstr, sizeof(sstr) - 1, ival) -#define REDIS_CONF_STRING_STATIC(ht, sstr, sval) \ - redis_conf_string(ht, sstr, sizeof(sstr) - 1, sval) -#define REDIS_CONF_ZVAL_STATIC(ht, sstr, zret, copy, dtor) \ - redis_conf_zval(ht, sstr, sizeof(sstr) - 1, zret, copy, dtor) -#define REDIS_CONF_AUTH_STATIC(ht, sstr, user, pass) \ - redis_conf_auth(ht, sstr, sizeof(sstr) - 1, user, pass) - -zval *redis_hash_str_find_type(HashTable *ht, const char *key, int keylen, int type); -void redis_conf_double(HashTable *ht, const char *key, int keylen, double *dval); -void redis_conf_bool(HashTable *ht, const char *key, int keylen, int *bval); -void redis_conf_zend_bool(HashTable *ht, const char *key, int keylen, zend_bool *bval); -void redis_conf_long(HashTable *ht, const char *key, int keylen, zend_long *lval); -void redis_conf_int(HashTable *ht, const char *key, int keylen, int *ival); -void redis_conf_string(HashTable *ht, const char *key, size_t keylen, zend_string **sval); -void redis_conf_zval(HashTable *ht, const char *key, size_t keylen, zval *zret, int copy, int dtor); -void redis_conf_auth(HashTable *ht, const char *key, size_t keylen, zend_string **user, zend_string **pass); - -#endif
View file
redis-5.3.7.tgz/redis-5.3.7/php_redis.h
Deleted
@@ -1,305 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | - | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | - +----------------------------------------------------------------------+ -*/ - -#include "common.h" - -#ifndef PHP_REDIS_H -#define PHP_REDIS_H - -/* phpredis version */ -#define PHP_REDIS_VERSION "5.3.7" - -PHP_METHOD(Redis, __construct); -PHP_METHOD(Redis, __destruct); -PHP_METHOD(Redis, acl); -PHP_METHOD(Redis, append); -PHP_METHOD(Redis, auth); -PHP_METHOD(Redis, bgSave); -PHP_METHOD(Redis, bgrewriteaof); -PHP_METHOD(Redis, bitcount); -PHP_METHOD(Redis, bitop); -PHP_METHOD(Redis, bitpos); -PHP_METHOD(Redis, blPop); -PHP_METHOD(Redis, brPop); -PHP_METHOD(Redis, bzPopMax); -PHP_METHOD(Redis, bzPopMin); -PHP_METHOD(Redis, close); -PHP_METHOD(Redis, connect); -PHP_METHOD(Redis, dbSize); -PHP_METHOD(Redis, decr); -PHP_METHOD(Redis, decrBy); -PHP_METHOD(Redis, del); -PHP_METHOD(Redis, echo); -PHP_METHOD(Redis, exists); -PHP_METHOD(Redis, expire); -PHP_METHOD(Redis, expireAt); -PHP_METHOD(Redis, flushAll); -PHP_METHOD(Redis, flushDB); -PHP_METHOD(Redis, get); -PHP_METHOD(Redis, getBit); -PHP_METHOD(Redis, getRange); -PHP_METHOD(Redis, getSet); -PHP_METHOD(Redis, incr); -PHP_METHOD(Redis, incrBy); -PHP_METHOD(Redis, incrByFloat); -PHP_METHOD(Redis, info); -PHP_METHOD(Redis, keys); -PHP_METHOD(Redis, lInsert); -PHP_METHOD(Redis, lLen); -PHP_METHOD(Redis, lPop); -PHP_METHOD(Redis, lPush); -PHP_METHOD(Redis, lPushx); -PHP_METHOD(Redis, lSet); -PHP_METHOD(Redis, lastSave); -PHP_METHOD(Redis, lindex); -PHP_METHOD(Redis, lrange); -PHP_METHOD(Redis, lrem); -PHP_METHOD(Redis, ltrim); -PHP_METHOD(Redis, mget); -PHP_METHOD(Redis, move); -PHP_METHOD(Redis, object); -PHP_METHOD(Redis, pconnect); -PHP_METHOD(Redis, persist); -PHP_METHOD(Redis, pexpire); -PHP_METHOD(Redis, pexpireAt); -PHP_METHOD(Redis, ping); -PHP_METHOD(Redis, psetex); -PHP_METHOD(Redis, pttl); -PHP_METHOD(Redis, rPop); -PHP_METHOD(Redis, rPush); -PHP_METHOD(Redis, rPushx); -PHP_METHOD(Redis, randomKey); -PHP_METHOD(Redis, rename); -PHP_METHOD(Redis, renameNx); -PHP_METHOD(Redis, sAdd); -PHP_METHOD(Redis, sAddArray); -PHP_METHOD(Redis, sDiff); -PHP_METHOD(Redis, sDiffStore); -PHP_METHOD(Redis, sInter); -PHP_METHOD(Redis, sInterStore); -PHP_METHOD(Redis, sMembers); -PHP_METHOD(Redis, sMisMember); -PHP_METHOD(Redis, sMove); -PHP_METHOD(Redis, sPop); -PHP_METHOD(Redis, sRandMember); -PHP_METHOD(Redis, sUnion); -PHP_METHOD(Redis, sUnionStore); -PHP_METHOD(Redis, save); -PHP_METHOD(Redis, scard); -PHP_METHOD(Redis, select); -PHP_METHOD(Redis, set); -PHP_METHOD(Redis, setBit); -PHP_METHOD(Redis, setRange); -PHP_METHOD(Redis, setex); -PHP_METHOD(Redis, setnx); -PHP_METHOD(Redis, sismember); -PHP_METHOD(Redis, slaveof); -PHP_METHOD(Redis, sort); -PHP_METHOD(Redis, sortAsc); -PHP_METHOD(Redis, sortAscAlpha); -PHP_METHOD(Redis, sortDesc); -PHP_METHOD(Redis, sortDescAlpha); -PHP_METHOD(Redis, srem); -PHP_METHOD(Redis, strlen); -PHP_METHOD(Redis, swapdb); -PHP_METHOD(Redis, ttl); -PHP_METHOD(Redis, type); -PHP_METHOD(Redis, unlink); -PHP_METHOD(Redis, zAdd); -PHP_METHOD(Redis, zCard); -PHP_METHOD(Redis, zCount); -PHP_METHOD(Redis, zIncrBy); -PHP_METHOD(Redis, zLexCount); -PHP_METHOD(Redis, zPopMax); -PHP_METHOD(Redis, zPopMin); -PHP_METHOD(Redis, zRange); -PHP_METHOD(Redis, zRangeByLex); -PHP_METHOD(Redis, zRangeByScore); -PHP_METHOD(Redis, zRank); -PHP_METHOD(Redis, zRem); -PHP_METHOD(Redis, zRemRangeByLex); -PHP_METHOD(Redis, zRemRangeByRank); -PHP_METHOD(Redis, zRemRangeByScore); -PHP_METHOD(Redis, zRevRange); -PHP_METHOD(Redis, zRevRangeByLex); -PHP_METHOD(Redis, zRevRangeByScore); -PHP_METHOD(Redis, zRevRank); -PHP_METHOD(Redis, zScore); -PHP_METHOD(Redis, zinterstore); -PHP_METHOD(Redis, zunionstore); - -PHP_METHOD(Redis, eval); -PHP_METHOD(Redis, evalsha); -PHP_METHOD(Redis, script); -PHP_METHOD(Redis, debug); -PHP_METHOD(Redis, dump); -PHP_METHOD(Redis, restore); -PHP_METHOD(Redis, migrate); - -PHP_METHOD(Redis, time); -PHP_METHOD(Redis, role); - -PHP_METHOD(Redis, getLastError); -PHP_METHOD(Redis, clearLastError); -PHP_METHOD(Redis, _prefix); -PHP_METHOD(Redis, _pack); -PHP_METHOD(Redis, _unpack); - -PHP_METHOD(Redis, _serialize); -PHP_METHOD(Redis, _unserialize); - -PHP_METHOD(Redis, _compress); -PHP_METHOD(Redis, _uncompress); - -PHP_METHOD(Redis, mset); -PHP_METHOD(Redis, msetnx); -PHP_METHOD(Redis, rpoplpush); -PHP_METHOD(Redis, brpoplpush); - -PHP_METHOD(Redis, hGet); -PHP_METHOD(Redis, hSet); -PHP_METHOD(Redis, hSetNx); -PHP_METHOD(Redis, hDel); -PHP_METHOD(Redis, hLen); -PHP_METHOD(Redis, hKeys); -PHP_METHOD(Redis, hVals); -PHP_METHOD(Redis, hGetAll); -PHP_METHOD(Redis, hExists); -PHP_METHOD(Redis, hIncrBy); -PHP_METHOD(Redis, hIncrByFloat); -PHP_METHOD(Redis, hMset); -PHP_METHOD(Redis, hMget); -PHP_METHOD(Redis, hStrLen); - -PHP_METHOD(Redis, multi); -PHP_METHOD(Redis, discard); -PHP_METHOD(Redis, exec); -PHP_METHOD(Redis, watch); -PHP_METHOD(Redis, unwatch); - -PHP_METHOD(Redis, pipeline); - -PHP_METHOD(Redis, publish); -PHP_METHOD(Redis, subscribe);
View file
redis-5.3.7.tgz/redis-5.3.7/redis.c
Deleted
@@ -1,3900 +0,0 @@ -/* -*- Mode: C; tab-width: 4 -*- */ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | - | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - +----------------------------------------------------------------------+ -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_redis.h" -#include "redis_array.h" -#include "redis_cluster.h" -#include "redis_commands.h" -#include "redis_sentinel.h" -#include <standard/php_random.h> -#include <zend_exceptions.h> -#include <ext/standard/info.h> -#include <ext/hash/php_hash.h> - - -#ifdef PHP_SESSION -#include <ext/session/php_session.h> -#endif - -#include "library.h" - -#ifdef HAVE_REDIS_ZSTD -#include <zstd.h> -#endif - -#ifdef HAVE_REDIS_LZ4 -#include <lz4.h> -#endif - -#ifdef PHP_SESSION -extern ps_module ps_mod_redis; -extern ps_module ps_mod_redis_cluster; -#endif - -extern zend_class_entry *redis_array_ce; -extern zend_class_entry *redis_cluster_ce; -extern zend_class_entry *redis_cluster_exception_ce; -extern zend_class_entry *redis_sentinel_ce; - -zend_class_entry *redis_ce; -zend_class_entry *redis_exception_ce; - -extern int le_cluster_slot_cache; - -extern zend_function_entry redis_array_functions; -extern zend_function_entry redis_cluster_functions; -extern zend_function_entry redis_sentinel_functions; - -int le_redis_pconnect; - -PHP_INI_BEGIN() - /* redis arrays */ - PHP_INI_ENTRY("redis.arrays.algorithm", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.auth", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.autorehash", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.connecttimeout", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.distributor", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.functions", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.hosts", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.index", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.lazyconnect", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.names", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.pconnect", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.previous", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.readtimeout", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.retryinterval", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.arrays.consistent", "0", PHP_INI_ALL, NULL) - - /* redis cluster */ - PHP_INI_ENTRY("redis.clusters.cache_slots", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.clusters.auth", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.clusters.persistent", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.clusters.read_timeout", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.clusters.seeds", "", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.clusters.timeout", "0", PHP_INI_ALL, NULL) - - /* redis pconnect */ - PHP_INI_ENTRY("redis.pconnect.pooling_enabled", "1", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.pconnect.connection_limit", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.pconnect.echo_check_liveness", "1", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.pconnect.pool_detect_dirty", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.pconnect.pool_poll_timeout", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.pconnect.pool_pattern", "", PHP_INI_ALL, NULL) - - /* redis session */ - PHP_INI_ENTRY("redis.session.locking_enabled", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.session.lock_expire", "0", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.session.lock_retries", "10", PHP_INI_ALL, NULL) - PHP_INI_ENTRY("redis.session.lock_wait_time", "2000", PHP_INI_ALL, NULL) -PHP_INI_END() - -/** {{{ Argument info for commands in redis 1.0 */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_connect, 0, 0, 1) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, port) - ZEND_ARG_INFO(0, timeout) - ZEND_ARG_INFO(0, retry_interval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 0) - ZEND_ARG_INFO(0, option) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_multi, 0, 0, 0) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_client, 0, 0, 1) - ZEND_ARG_INFO(0, cmd) - ZEND_ARG_VARIADIC_INFO(0, args) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_config, 0, 0, 2) - ZEND_ARG_INFO(0, cmd) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0) - ZEND_ARG_INFO(0, async) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_pubsub, 0, 0, 1) - ZEND_ARG_INFO(0, cmd) - ZEND_ARG_VARIADIC_INFO(0, args) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_slowlog, 0, 0, 1) - ZEND_ARG_INFO(0, arg) - ZEND_ARG_INFO(0, option) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_pconnect, 0, 0, 1) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, port) - ZEND_ARG_INFO(0, timeout) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mget, 0, 0, 1) - ZEND_ARG_ARRAY_INFO(0, keys, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_exists, 0, 0, 1) - ZEND_ARG_INFO(0, key) - ZEND_ARG_VARIADIC_INFO(0, other_keys) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_del, 0, 0, 1) - ZEND_ARG_INFO(0, key) - ZEND_ARG_VARIADIC_INFO(0, other_keys) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_keys, 0, 0, 1) - ZEND_ARG_INFO(0, pattern) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_generic_sort, 0, 0, 1) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, get) - ZEND_ARG_INFO(0, start) - ZEND_ARG_INFO(0, end) - ZEND_ARG_INFO(0, getList) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_lrem, 0, 0, 3) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) - ZEND_ARG_INFO(0, count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_auth, 0, 0, 1) - ZEND_ARG_INFO(0, auth) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_select, 0, 0, 1) - ZEND_ARG_INFO(0, dbindex) -ZEND_END_ARG_INFO() -
View file
redis-5.3.7.tgz/redis-5.3.7/redis_array.c
Deleted
@@ -1,1383 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - +----------------------------------------------------------------------+ -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "common.h" -#include "library.h" -#include "redis_array.h" -#include "redis_array_impl.h" - -#include <ext/standard/info.h> -#include <zend_exceptions.h> - -/* Simple macro to detect failure in a RedisArray call */ -#define RA_CALL_FAILED(rv, cmd) ( \ - (Z_TYPE_P(rv) == IS_FALSE) || \ - (Z_TYPE_P(rv) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(rv)) == 0) || \ - (Z_TYPE_P(rv) == IS_LONG && Z_LVAL_P(rv) == 0 && !strcasecmp(cmd, "TYPE")) \ -) - -extern zend_class_entry *redis_ce; -zend_class_entry *redis_array_ce; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) - ZEND_ARG_INFO(0, name_or_hosts) - ZEND_ARG_ARRAY_INFO(0, options, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_call, 0, 0, 2) - ZEND_ARG_INFO(0, function_name) - ZEND_ARG_INFO(0, arguments) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_target, 0, 0, 1) - ZEND_ARG_INFO(0, key) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_instance, 0, 0, 1) - ZEND_ARG_INFO(0, host) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_rehash, 0, 0, 0) - ZEND_ARG_INFO(0, callable) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_select, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mget, 0, 0, 1) - ZEND_ARG_INFO(0, keys) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mset, 0, 0, 1) - ZEND_ARG_INFO(0, pairs) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_del, 0, 0, 1) - ZEND_ARG_INFO(0, keys) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_getopt, 0, 0, 1) - ZEND_ARG_INFO(0, opt) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_setopt, 0, 0, 2) - ZEND_ARG_INFO(0, opt) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_keys, 0, 0, 1) - ZEND_ARG_INFO(0, pattern) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_multi, 0, 0, 1) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0) - ZEND_ARG_INFO(0, async) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2) - ZEND_ARG_INFO(1, iterator) - ZEND_ARG_INFO(0, node) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, count) -ZEND_END_ARG_INFO() - -zend_function_entry redis_array_functions = { - PHP_ME(RedisArray, __call, arginfo_call, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, __construct, arginfo_ctor, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _continuum, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _distributor, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _function, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _hosts, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _instance, arginfo_instance, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _rehash, arginfo_rehash, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, _target, arginfo_target, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, bgsave, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, del, arginfo_del, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, discard, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, exec, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, flushall, arginfo_flush, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, flushdb, arginfo_flush, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, getOption, arginfo_getopt, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, hscan, arginfo_kscan, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, info, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, keys, arginfo_keys, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, mget, arginfo_mget, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, mset, arginfo_mset, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, multi, arginfo_multi, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, ping, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, save, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, scan, arginfo_scan, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, select, arginfo_select, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, setOption,arginfo_setopt, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, sscan, arginfo_kscan, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, unlink, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, unwatch, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisArray, zscan, arginfo_kscan, ZEND_ACC_PUBLIC) - PHP_MALIAS(RedisArray, delete, del, arginfo_del, ZEND_ACC_PUBLIC) - PHP_MALIAS(RedisArray, getMultiple, mget, arginfo_mget, ZEND_ACC_PUBLIC) - PHP_FE_END -}; - -static void -redis_array_free(RedisArray *ra) -{ - int i; - - /* continuum */ - if (ra->continuum) { - efree(ra->continuum->points); - efree(ra->continuum); - } - - /* Redis objects */ - for(i = 0; i< ra->count; i++) { - zval_dtor(&ra->redisi); - zend_string_release(ra->hostsi); - } - efree(ra->redis); - efree(ra->hosts); - - /* delete hash function */ - zval_dtor(&ra->z_fun); - - /* Distributor */ - zval_dtor(&ra->z_dist); - - /* Hashing algorithm */ - if (ra->algorithm) zend_string_release(ra->algorithm); - - /* Delete pur commands */ - zend_hash_destroy(ra->pure_cmds); - FREE_HASHTABLE(ra->pure_cmds); - - /* Free structure itself */ - efree(ra); -} - -typedef struct { - RedisArray *ra; - zend_object std; -} redis_array_object; - -zend_object_handlers redis_array_object_handlers; - -void -free_redis_array_object(zend_object *object) -{ - redis_array_object *obj = PHPREDIS_GET_OBJECT(redis_array_object, object); - - if (obj->ra) { - if (obj->ra->prev) redis_array_free(obj->ra->prev); - redis_array_free(obj->ra); - } - zend_object_std_dtor(&obj->std); -} - -zend_object *
View file
redis-5.3.7.tgz/redis-5.3.7/redis_array.h
Deleted
@@ -1,74 +0,0 @@ -#ifndef REDIS_ARRAY_H -#define REDIS_ARRAY_H - -#if (defined(_MSC_VER) && _MSC_VER <= 1920) -#include "win32/php_stdint.h" -#else -#include <stdint.h> -#endif -#include "common.h" - -PHP_METHOD(RedisArray, __call); -PHP_METHOD(RedisArray, __construct); -PHP_METHOD(RedisArray, _continuum); -PHP_METHOD(RedisArray, _distributor); -PHP_METHOD(RedisArray, _function); -PHP_METHOD(RedisArray, _hosts); -PHP_METHOD(RedisArray, _instance); -PHP_METHOD(RedisArray, _rehash); -PHP_METHOD(RedisArray, _target); -PHP_METHOD(RedisArray, bgsave); -PHP_METHOD(RedisArray, del); -PHP_METHOD(RedisArray, discard); -PHP_METHOD(RedisArray, exec); -PHP_METHOD(RedisArray, flushall); -PHP_METHOD(RedisArray, flushdb); -PHP_METHOD(RedisArray, getOption); -PHP_METHOD(RedisArray, hscan); -PHP_METHOD(RedisArray, info); -PHP_METHOD(RedisArray, keys); -PHP_METHOD(RedisArray, mget); -PHP_METHOD(RedisArray, mset); -PHP_METHOD(RedisArray, multi); -PHP_METHOD(RedisArray, ping); -PHP_METHOD(RedisArray, save); -PHP_METHOD(RedisArray, scan); -PHP_METHOD(RedisArray, select); -PHP_METHOD(RedisArray, setOption); -PHP_METHOD(RedisArray, sscan); -PHP_METHOD(RedisArray, unlink); -PHP_METHOD(RedisArray, unwatch); -PHP_METHOD(RedisArray, zscan); - -typedef struct { - uint32_t value; - int index; -} ContinuumPoint; - -typedef struct { - size_t nb_points; - ContinuumPoint *points; -} Continuum; - -typedef struct RedisArray_ { - int count; - zend_string **hosts; /* array of host:port strings */ - zval *redis; /* array of Redis instances */ - zval *z_multi_exec; /* Redis instance to be used in multi-exec */ - zend_bool index; /* use per-node index */ - zend_bool auto_rehash; /* migrate keys on read operations */ - zend_bool pconnect; /* should we use pconnect */ - zval z_fun; /* key extractor, callable */ - zval z_dist; /* key distributor, callable */ - zend_string *algorithm; /* key hashing algorithm name */ - HashTable *pure_cmds; /* hash table */ - double connect_timeout; /* socket connect timeout */ - double read_timeout; /* socket read timeout */ - Continuum *continuum; - struct RedisArray_ *prev; -} RedisArray; - -zend_object *create_redis_array_object(zend_class_entry *ce); -void free_redis_array_object(zend_object *object); - -#endif
View file
redis-5.3.7.tgz/redis-5.3.7/redis_array_impl.c
Deleted
@@ -1,1215 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - +----------------------------------------------------------------------+ -*/ -#include "redis_array_impl.h" -#include "php_redis.h" -#include "library.h" - -#include "php_variables.h" -#include "SAPI.h" -#include "ext/standard/url.h" -#include "ext/standard/crc32.h" -#include "ext/standard/md5.h" - -#include "ext/hash/php_hash.h" - -#define PHPREDIS_INDEX_NAME "__phpredis_array_index__" - -extern zend_class_entry *redis_ce; - -static RedisArray * -ra_load_hosts(RedisArray *ra, HashTable *hosts, zend_string *user, - zend_string *pass, long retry_interval, zend_bool b_lazy_connect) -{ - int i = 0, host_len; - char *host, *p; - short port; - zval *zpData; - redis_object *redis; - - /* init connections */ - ZEND_HASH_FOREACH_VAL(hosts, zpData) { - if (Z_TYPE_P(zpData) != IS_STRING) { - return NULL; - } - - /* default values */ - host = Z_STRVAL_P(zpData); - host_len = Z_STRLEN_P(zpData); - ra->hostsi = zend_string_init(host, host_len, 0); - port = 6379; - - if((p = strrchr(host, ':'))) { /* found port */ - host_len = p - host; - port = (short)atoi(p+1); - } else if(strchr(host,'/') != NULL) { /* unix socket */ - port = -1; - } - - /* create Redis object */ - object_init_ex(&ra->redisi, redis_ce); - redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, &ra->redisi); - - /* create socket */ - redis->sock = redis_sock_create(host, host_len, port, ra->connect_timeout, - ra->read_timeout, ra->pconnect, NULL, - retry_interval); - - redis_sock_set_auth(redis->sock, user, pass); - - if (!b_lazy_connect) { - if (redis_sock_server_open(redis->sock) < 0) { - ra->count = ++i; - return NULL; - } - } - - ra->count = ++i; - } ZEND_HASH_FOREACH_END(); - - return ra; -} - -/* List pure functions */ -void -ra_init_function_table(RedisArray *ra) -{ - ALLOC_HASHTABLE(ra->pure_cmds); - zend_hash_init(ra->pure_cmds, 0, NULL, NULL, 0); - - zend_hash_str_update_ptr(ra->pure_cmds, "EXISTS", sizeof("EXISTS") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "GET", sizeof("GET") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "GETBIT", sizeof("GETBIT") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "GETRANGE", sizeof("GETRANGE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HEXISTS", sizeof("HEXISTS") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HGET", sizeof("HGET") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HGETALL", sizeof("HGETALL") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HKEYS", sizeof("HKEYS") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HLEN", sizeof("HLEN") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HMGET", sizeof("HMGET") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "HVALS", sizeof("HVALS") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "LINDEX", sizeof("LINDEX") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "LLEN", sizeof("LLEN") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "LRANGE", sizeof("LRANGE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "OBJECT", sizeof("OBJECT") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SCARD", sizeof("SCARD") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SDIFF", sizeof("SDIFF") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SINTER", sizeof("SINTER") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SISMEMBER", sizeof("SISMEMBER") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SMEMBERS", sizeof("SMEMBERS") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SRANDMEMBER", sizeof("SRANDMEMBER") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "STRLEN", sizeof("STRLEN") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "SUNION", sizeof("SUNION") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "TYPE", sizeof("TYPE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZCARD", sizeof("ZCARD") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZCOUNT", sizeof("ZCOUNT") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZRANGE", sizeof("ZRANGE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZRANK", sizeof("ZRANK") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZREVRANGE", sizeof("ZREVRANGE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZREVRANGEBYSCORE", sizeof("ZREVRANGEBYSCORE") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZREVRANK", sizeof("ZREVRANK") - 1, NULL); - zend_hash_str_update_ptr(ra->pure_cmds, "ZSCORE", sizeof("ZSCORE") - 1, NULL); -} - -static int -ra_find_name(const char *name) { - - const char *ini_names, *p, *next; - /* php_printf("Loading redis array with name=%s\n", name); */ - - ini_names = INI_STR("redis.arrays.names"); - for(p = ini_names; p;) { - next = strchr(p, ','); - if(next) { - if(strncmp(p, name, next - p) == 0) { - return 1; - } - } else { - if(strcmp(p, name) == 0) { - return 1; - } - break; - } - p = next + 1; - } - - return 0; -} - -/* load array from INI settings */ -RedisArray *ra_load_array(const char *name) { - zval *z_data, z_tmp, z_fun, z_dist; - zval z_params_hosts; - zval z_params_prev; - RedisArray *ra = NULL; - - zend_string *algorithm = NULL, *user = NULL, *pass = NULL; - zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0, consistent = 0; - zend_long l_retry_interval = 0; - zend_bool b_lazy_connect = 0; - double d_connect_timeout = 0, read_timeout = 0.0; - HashTable *hHosts = NULL, *hPrev = NULL; - size_t name_len = strlen(name); - char *iptr; - - /* find entry */ - if(!ra_find_name(name)) - return ra; - - ZVAL_NULL(&z_fun); - ZVAL_NULL(&z_dist); - - /* find hosts */ - array_init(&z_params_hosts); - if ((iptr = INI_STR("redis.arrays.hosts")) != NULL) { - sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_hosts); - if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_hosts), name, name_len)) != NULL) { - hHosts = Z_ARRVAL_P(z_data); - } - } - - /* find previous hosts */ - array_init(&z_params_prev); - if ((iptr = INI_STR("redis.arrays.previous")) != NULL) { - sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_prev); - if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_prev), name, name_len)) != NULL) { - if (Z_TYPE_P(z_data) == IS_ARRAY) { - hPrev = Z_ARRVAL_P(z_data); - } - } - } - - /* find function */ - if ((iptr = INI_STR("redis.arrays.functions")) != NULL) { - array_init(&z_tmp); - sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp); - redis_conf_zval(Z_ARRVAL(z_tmp), name, name_len, &z_fun, 1, 0);
View file
redis-5.3.7.tgz/redis-5.3.7/redis_cluster.c
Deleted
@@ -1,3267 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Michael Grunder <michael.grunder@gmail.com> | - | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - +----------------------------------------------------------------------+ -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "common.h" -#include "php_redis.h" -#include "ext/standard/info.h" -#include "crc16.h" -#include "redis_cluster.h" -#include "redis_commands.h" -#include <zend_exceptions.h> -#include "library.h" -#include <php_variables.h> -#include <SAPI.h> - -zend_class_entry *redis_cluster_ce; - -/* Exception handler */ -zend_class_entry *redis_cluster_exception_ce; - -/* Handlers for RedisCluster */ -zend_object_handlers RedisCluster_handlers; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) - ZEND_ARG_INFO(0, name) - ZEND_ARG_ARRAY_INFO(0, seeds, 0) - ZEND_ARG_INFO(0, timeout) - ZEND_ARG_INFO(0, read_timeout) - ZEND_ARG_INFO(0, persistent) - ZEND_ARG_INFO(0, auth) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_del, 0, 0, 1) - ZEND_ARG_INFO(0, key) - ZEND_ARG_VARIADIC_INFO(0, other_keys) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mget, 0, 0, 1) - ZEND_ARG_ARRAY_INFO(0, keys, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_keys, 0, 0, 1) - ZEND_ARG_INFO(0, pattern) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_key_or_address, 0, 0, 1) - ZEND_ARG_INFO(0, key_or_address) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_key_or_address_variadic, 0, 0, 1) - ZEND_ARG_INFO(0, key_or_address) - ZEND_ARG_INFO(0, arg) - ZEND_ARG_VARIADIC_INFO(0, other_args) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 1) - ZEND_ARG_INFO(0, key_or_address) - ZEND_ARG_INFO(0, option) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 1) - ZEND_ARG_INFO(0, key_or_address) - ZEND_ARG_INFO(0, async) -ZEND_END_ARG_INFO() - -/* Argument info for HSCAN, SSCAN, HSCAN */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan_cl, 0, 0, 2) - ZEND_ARG_INFO(0, str_key) - ZEND_ARG_INFO(1, i_iterator) - ZEND_ARG_INFO(0, str_pattern) - ZEND_ARG_INFO(0, i_count) -ZEND_END_ARG_INFO() - -/* Argument info for SCAN */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_scan_cl, 0, 0, 2) - ZEND_ARG_INFO(1, i_iterator) - ZEND_ARG_INFO(0, str_node) - ZEND_ARG_INFO(0, str_pattern) - ZEND_ARG_INFO(0, i_count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_acl_cl, 0, 0, 2) - ZEND_ARG_INFO(0, key_or_address) - ZEND_ARG_INFO(0, subcmd) - ZEND_ARG_VARIADIC_INFO(0, args) -ZEND_END_ARG_INFO() - -/* Function table */ -zend_function_entry redis_cluster_functions = { - PHP_ME(RedisCluster, __construct, arginfo_ctor, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _masters, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _prefix, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _redir, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _serialize, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _unserialize, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _compress, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _uncompress, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _pack, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, _unpack, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, acl, arginfo_acl_cl, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, append, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bgrewriteaof, arginfo_key_or_address, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bgsave, arginfo_key_or_address, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bitcount, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bitop, arginfo_bitop, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bitpos, arginfo_bitpos, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, blpop, arginfo_blrpop, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, brpop, arginfo_blrpop, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, brpoplpush, arginfo_brpoplpush, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, clearlasterror, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bzpopmax, arginfo_blrpop, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, bzpopmin, arginfo_blrpop, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, client, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, close, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, cluster, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, command, arginfo_command, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, config, arginfo_key_or_address_variadic, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, dbsize, arginfo_key_or_address, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, decr, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, decrby, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, del, arginfo_del, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, discard, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, dump, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, echo, arginfo_echo, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, eval, arginfo_eval, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, evalsha, arginfo_evalsha, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, exec, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, exists, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, expire, arginfo_expire, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, expireat, arginfo_key_timestamp, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, flushall, arginfo_flush, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, flushdb, arginfo_flush, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, geoadd, arginfo_geoadd, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, geodist, arginfo_geodist, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, geohash, arginfo_key_members, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, geopos, arginfo_key_members, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, georadius, arginfo_georadius, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, georadius_ro, arginfo_georadius, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, georadiusbymember, arginfo_georadiusbymember, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, georadiusbymember_ro, arginfo_georadiusbymember, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, get, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getbit, arginfo_key_offset, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getlasterror, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getmode, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getoption, arginfo_getoption, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getrange, arginfo_key_start_end, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, getset, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hdel, arginfo_key_members, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hexists, arginfo_key_member, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hget, arginfo_key_member, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hgetall, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hincrby, arginfo_key_member_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hincrbyfloat, arginfo_key_member_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hkeys, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hlen, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hmget, arginfo_hmget, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hmset, arginfo_hmset, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hscan, arginfo_kscan_cl, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hset, arginfo_key_member_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hsetnx, arginfo_key_member_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hstrlen, arginfo_key_member, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, hvals, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, incr, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, incrby, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, incrbyfloat, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, info, arginfo_info, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, keys, arginfo_keys, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lastsave, arginfo_key_or_address, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lget, arginfo_lindex, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lindex, arginfo_lindex, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, linsert, arginfo_linsert, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, llen, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lpop, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lpush, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lpushx, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lrange, arginfo_key_start_end, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lrem, arginfo_key_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, lset, arginfo_lset, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, ltrim, arginfo_ltrim, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, mget, arginfo_mget, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, mset, arginfo_pairs, ZEND_ACC_PUBLIC) - PHP_ME(RedisCluster, msetnx, arginfo_pairs, ZEND_ACC_PUBLIC)
View file
redis-5.3.7.tgz/redis-5.3.7/redis_cluster.h
Deleted
@@ -1,303 +0,0 @@ -#ifndef REDIS_CLUSTER_H -#define REDIS_CLUSTER_H - -#include "cluster_library.h" -#include <php.h> -#include <stddef.h> - -/* Get attached object context */ -#define GET_CONTEXT() PHPREDIS_ZVAL_GET_OBJECT(redisCluster, getThis()) - -/* Command building/processing is identical for every command */ -#define CLUSTER_BUILD_CMD(name, c, cmd, cmd_len, slot) \ - redis_##name##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &cmd, \ - &cmd_len, &slot) - -/* Append information required to handle MULTI commands to the tail of our MULTI - * linked list. */ -#define CLUSTER_ENQUEUE_RESPONSE(c, slot, cb, ctx) \ - clusterFoldItem *_item; \ - _item = emalloc(sizeof(clusterFoldItem)); \ - _item->callback = cb; \ - _item->slot = slot; \ - _item->ctx = ctx; \ - _item->next = NULL; \ - if(c->multi_head == NULL) { \ - c->multi_head = _item; \ - c->multi_curr = _item; \ - } else { \ - c->multi_curr->next = _item; \ - c->multi_curr = _item; \ - } \ - -/* Simple macro to free our enqueued callbacks after we EXEC */ -#define CLUSTER_FREE_QUEUE(c) \ - clusterFoldItem *_item = c->multi_head, *_tmp; \ - while(_item) { \ - _tmp = _item->next; \ - efree(_item); \ - _item = _tmp; \ - } \ - c->multi_head = c->multi_curr = NULL; \ - -/* Reset anything flagged as MULTI */ -#define CLUSTER_RESET_MULTI(c) \ - redisClusterNode *_node; \ - ZEND_HASH_FOREACH_PTR(c->nodes, _node) { \ - if (_node == NULL) break; \ - _node->sock->watching = 0; \ - _node->sock->mode = ATOMIC; \ - } ZEND_HASH_FOREACH_END(); \ - c->flags->watching = 0; \ - c->flags->mode = ATOMIC; \ - -/* Simple 1-1 command -> response macro */ -#define CLUSTER_PROCESS_CMD(cmdname, resp_func, readcmd) \ - redisCluster *c = GET_CONTEXT(); \ - c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \ - char *cmd; int cmd_len; short slot; void *ctx=NULL; \ - if(redis_##cmdname##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,c->flags, &cmd, \ - &cmd_len, &slot, &ctx)==FAILURE) { \ - RETURN_FALSE; \ - } \ - if(cluster_send_command(c,slot,cmd,cmd_len)<0 || c->err!=NULL) {\ - efree(cmd); \ - RETURN_FALSE; \ - } \ - efree(cmd); \ - if(c->flags->mode == MULTI) { \ - CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_func, ctx); \ - RETURN_ZVAL(getThis(), 1, 0); \ - } \ - resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx); - -/* More generic processing, where only the keyword differs */ -#define CLUSTER_PROCESS_KW_CMD(kw, cmdfunc, resp_func, readcmd) \ - redisCluster *c = GET_CONTEXT(); \ - c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \ - char *cmd; int cmd_len; short slot; void *ctx=NULL; \ - if(cmdfunc(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,\ - &slot,&ctx)==FAILURE) { \ - RETURN_FALSE; \ - } \ - if(cluster_send_command(c,slot,cmd,cmd_len)<0 || c->err!=NULL) { \ - efree(cmd); \ - RETURN_FALSE; \ - } \ - efree(cmd); \ - if(c->flags->mode == MULTI) { \ - CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_func, ctx); \ - RETURN_ZVAL(getThis(), 1, 0); \ - } \ - resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx); - -/* Create cluster context */ -zend_object *create_cluster_context(zend_class_entry *class_type); - -/* Free cluster context struct */ -void free_cluster_context(zend_object *object); - -/* RedisCluster method implementation */ -PHP_METHOD(RedisCluster, __construct); -PHP_METHOD(RedisCluster, acl); -PHP_METHOD(RedisCluster, close); -PHP_METHOD(RedisCluster, get); -PHP_METHOD(RedisCluster, set); -PHP_METHOD(RedisCluster, mget); -PHP_METHOD(RedisCluster, mset); -PHP_METHOD(RedisCluster, msetnx); -PHP_METHOD(RedisCluster, mset); -PHP_METHOD(RedisCluster, del); -PHP_METHOD(RedisCluster, unlink); -PHP_METHOD(RedisCluster, dump); -PHP_METHOD(RedisCluster, setex); -PHP_METHOD(RedisCluster, psetex); -PHP_METHOD(RedisCluster, setnx); -PHP_METHOD(RedisCluster, getset); -PHP_METHOD(RedisCluster, exists); -PHP_METHOD(RedisCluster, keys); -PHP_METHOD(RedisCluster, type); -PHP_METHOD(RedisCluster, persist); -PHP_METHOD(RedisCluster, lpop); -PHP_METHOD(RedisCluster, rpop); -PHP_METHOD(RedisCluster, spop); -PHP_METHOD(RedisCluster, rpush); -PHP_METHOD(RedisCluster, lpush); -PHP_METHOD(RedisCluster, blpop); -PHP_METHOD(RedisCluster, brpop); -PHP_METHOD(RedisCluster, rpushx); -PHP_METHOD(RedisCluster, lpushx); -PHP_METHOD(RedisCluster, linsert); -PHP_METHOD(RedisCluster, lindex); -PHP_METHOD(RedisCluster, lrem); -PHP_METHOD(RedisCluster, brpoplpush); -PHP_METHOD(RedisCluster, rpoplpush); -PHP_METHOD(RedisCluster, llen); -PHP_METHOD(RedisCluster, scard); -PHP_METHOD(RedisCluster, smembers); -PHP_METHOD(RedisCluster, sismember); -PHP_METHOD(RedisCluster, sadd); -PHP_METHOD(RedisCluster, saddarray); -PHP_METHOD(RedisCluster, srem); -PHP_METHOD(RedisCluster, sunion); -PHP_METHOD(RedisCluster, sunionstore); -PHP_METHOD(RedisCluster, sinter); -PHP_METHOD(RedisCluster, sinterstore); -PHP_METHOD(RedisCluster, sdiff); -PHP_METHOD(RedisCluster, sdiffstore); -PHP_METHOD(RedisCluster, strlen); -PHP_METHOD(RedisCluster, ttl); -PHP_METHOD(RedisCluster, pttl); -PHP_METHOD(RedisCluster, zcard); -PHP_METHOD(RedisCluster, zscore); -PHP_METHOD(RedisCluster, zcount); -PHP_METHOD(RedisCluster, zrem); -PHP_METHOD(RedisCluster, zremrangebyscore); -PHP_METHOD(RedisCluster, zrank); -PHP_METHOD(RedisCluster, zrevrank); -PHP_METHOD(RedisCluster, zadd); -PHP_METHOD(RedisCluster, zincrby); -PHP_METHOD(RedisCluster, hlen); -PHP_METHOD(RedisCluster, hget); -PHP_METHOD(RedisCluster, hkeys); -PHP_METHOD(RedisCluster, hvals); -PHP_METHOD(RedisCluster, hmget); -PHP_METHOD(RedisCluster, hmset); -PHP_METHOD(RedisCluster, hdel); -PHP_METHOD(RedisCluster, hgetall); -PHP_METHOD(RedisCluster, hexists); -PHP_METHOD(RedisCluster, hincrby); -PHP_METHOD(RedisCluster, hincrbyfloat); -PHP_METHOD(RedisCluster, hset); -PHP_METHOD(RedisCluster, hsetnx); -PHP_METHOD(RedisCluster, hstrlen); -PHP_METHOD(RedisCluster, incr); -PHP_METHOD(RedisCluster, decr); -PHP_METHOD(RedisCluster, incrby); -PHP_METHOD(RedisCluster, decrby); -PHP_METHOD(RedisCluster, incrbyfloat); -PHP_METHOD(RedisCluster, expire); -PHP_METHOD(RedisCluster, expireat); -PHP_METHOD(RedisCluster, pexpire); -PHP_METHOD(RedisCluster, pexpireat); -PHP_METHOD(RedisCluster, append); -PHP_METHOD(RedisCluster, getbit); -PHP_METHOD(RedisCluster, setbit); -PHP_METHOD(RedisCluster, bitop); -PHP_METHOD(RedisCluster, bitpos); -PHP_METHOD(RedisCluster, bitcount); -PHP_METHOD(RedisCluster, lget); -PHP_METHOD(RedisCluster, getrange); -PHP_METHOD(RedisCluster, ltrim); -PHP_METHOD(RedisCluster, lrange); -PHP_METHOD(RedisCluster, zremrangebyrank); -PHP_METHOD(RedisCluster, publish); -PHP_METHOD(RedisCluster, lset); -PHP_METHOD(RedisCluster, rename); -PHP_METHOD(RedisCluster, renamenx); -PHP_METHOD(RedisCluster, pfcount); -PHP_METHOD(RedisCluster, pfadd);
View file
redis-5.3.7.tgz/redis-5.3.7/redis_commands.c
Deleted
@@ -1,4303 +0,0 @@ -/* -*- Mode: C; tab-width: 4 -*- */ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Original Author: Michael Grunder <michael.grunder@gmail.com | - | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - +----------------------------------------------------------------------+ -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "redis_commands.h" - -#include "php_network.h" - -#ifndef PHP_WIN32 -#include <netinet/tcp.h> /* TCP_KEEPALIVE */ -#else -#include <winsock.h> -#endif - -#include <zend_exceptions.h> - -/* Georadius sort type */ -typedef enum geoSortType { - SORT_NONE, - SORT_ASC, - SORT_DESC -} geoSortType; - -/* Georadius store type */ -typedef enum geoStoreType { - STORE_NONE, - STORE_COORD, - STORE_DIST -} geoStoreType; - -/* Georadius options structure */ -typedef struct geoOptions { - int withcoord; - int withdist; - int withhash; - long count; - geoSortType sort; - geoStoreType store; - zend_string *key; -} geoOptions; - -/* Local passthrough macro for command construction. Given that these methods - * are generic (so they work whether the caller is Redis or RedisCluster) we - * will always have redis_sock, slot*, and */ -#define REDIS_CMD_SPPRINTF(ret, kw, fmt, ...) \ - redis_spprintf(redis_sock, slot, ret, kw, fmt, ##__VA_ARGS__) - -/* Generic commands based on method signature and what kind of things we're - * processing. Lots of Redis commands take something like key, value, or - * key, value long. Each unique signature like this is written only once */ - -/* A command that takes no arguments */ -int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, - void **ctx) -{ - *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, ""); - return SUCCESS; -} - -/* Helper to construct a raw command. Given that the cluster and non cluster - * versions are different (RedisCluster needs an additional argument to direct - * the command) we take the start of our array and count */ -int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len) -{ - smart_string cmdstr = {0}; - int i; - - /* Make sure our first argument is a string */ - if (Z_TYPE(z_args0) != IS_STRING) { - php_error_docref(NULL, E_WARNING, - "When sending a 'raw' command, the first argument must be a string!"); - return FAILURE; - } - - /* Initialize our command string */ - redis_cmd_init_sstr(&cmdstr, argc-1, Z_STRVAL(z_args0), Z_STRLEN(z_args0)); - - for (i = 1; i < argc; i++) { - switch (Z_TYPE(z_argsi)) { - case IS_STRING: - redis_cmd_append_sstr(&cmdstr, Z_STRVAL(z_argsi), - Z_STRLEN(z_argsi)); - break; - case IS_LONG: - redis_cmd_append_sstr_long(&cmdstr,Z_LVAL(z_argsi)); - break; - case IS_DOUBLE: - redis_cmd_append_sstr_dbl(&cmdstr,Z_DVAL(z_argsi)); - break; - default: - php_error_docref(NULL, E_WARNING, - "Raw command arguments must be scalar values!"); - efree(cmdstr.c); - return FAILURE; - } - } - - /* Push command and length to caller */ - *cmd = cmdstr.c; - *cmd_len = cmdstr.len; - - return SUCCESS; -} - -smart_string * -redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args) -{ - int i; - zend_string *zstr; - - if (Z_TYPE(z_args0) != IS_STRING) { - return NULL; - } - // Branch based on the directive - if (!strcasecmp(Z_STRVAL(z_args0), "flush") || !strcasecmp(Z_STRVAL(z_args0), "kill")) { - // Simple SCRIPT FLUSH, or SCRIPT_KILL command - REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); - redis_cmd_append_sstr(cmd, Z_STRVAL(z_args0), Z_STRLEN(z_args0)); - } else if (!strcasecmp(Z_STRVAL(z_args0), "load")) { - // Make sure we have a second argument, and it's not empty. If it is - // empty, we can just return an empty array (which is what Redis does) - if (argc < 2 || Z_TYPE(z_args1) != IS_STRING || Z_STRLEN(z_args1) < 1) { - return NULL; - } - // Format our SCRIPT LOAD command - REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); - redis_cmd_append_sstr(cmd, "LOAD", sizeof("LOAD") - 1); - redis_cmd_append_sstr(cmd, Z_STRVAL(z_args1), Z_STRLEN(z_args1)); - } else if (!strcasecmp(Z_STRVAL(z_args0), "exists")) { - // Make sure we have a second argument - if (argc < 2) { - return NULL; - } - /* Construct our SCRIPT EXISTS command */ - REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); - redis_cmd_append_sstr(cmd, "EXISTS", sizeof("EXISTS") - 1); - - for (i = 1; i < argc; ++i) { - zstr = zval_get_string(&z_argsi); - redis_cmd_append_sstr(cmd, ZSTR_VAL(zstr), ZSTR_LEN(zstr)); - zend_string_release(zstr); - } - } else { - /* Unknown directive */ - return NULL; - } - return cmd; -} - -/* Command that takes one optional string */ -int redis_opt_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, - char **cmd, int *cmd_len, short *slot, void **ctx) -{ - char *arg = NULL; - size_t arglen; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &arg, &arglen) == FAILURE) { - return FAILURE; - } - - if (arg != NULL) { - *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", arg, arglen); - } else { - *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, ""); - } - - return SUCCESS; -} - -/* Generic command where we just take a string and do nothing to it*/ -int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, - char **cmd, int *cmd_len, short *slot, void **ctx) -{ - char *arg; - size_t arg_len; - - // Parse args - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) - ==FAILURE) - {
View file
redis-5.3.7.tgz/redis-5.3.7/redis_commands.h
Deleted
@@ -1,326 +0,0 @@ -#ifndef REDIS_COMMANDS_H -#define REDIS_COMMANDS_H - -#include "common.h" -#include "library.h" -#include "cluster_library.h" - -/* Pick a random slot, any slot (for stuff like publish/subscribe) */ -#define CMD_RAND_SLOT(slot) \ - if(slot) *slot = rand() % REDIS_CLUSTER_MOD - -/* Macro for setting the slot if we've been asked to */ -#define CMD_SET_SLOT(slot,key,key_len) \ - if (slot) *slot = cluster_hash_key(key,key_len); - -/* Simple container so we can push subscribe context out */ -typedef struct subscribeContext { - char *kw; - int argc; - zend_fcall_info cb; - zend_fcall_info_cache cb_cache; -} subscribeContext; - -/* Construct a raw command */ -int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len); - -/* Construct a script command */ -smart_string *redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args); - -char *redis_variadic_str_cmd(char *kw, zval *argv, int argc, int *cmd_len); - -/* Redis command generics. Many commands share common prototypes meaning that - * we can write one function to handle all of them. For example, there are - * many COMMAND key value commands, or COMMAND key commands. */ - -int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_opt_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_long_val_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_long_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_str_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_dbl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_varval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_val_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_key_str_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_blocking_pop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -/* Construct SCAN and similar commands, as well as check iterator */ -int redis_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - REDIS_SCAN_TYPE type, char **cmd, int *cmd_len); - -/* ZRANGE, ZREVRANGE, ZRANGEBYSCORE, and ZREVRANGEBYSCORE callback type */ -typedef int (*zrange_cb)(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *,char**,int*,int*,short*,void**); - -int redis_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, int *withscores, short *slot, - void **ctx); - -int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, int *withscores, short *slot, - void **ctx); - -int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_georadiusbymember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); - -/* Commands which need a unique construction mechanism. This is either because - * they don't share a signature with any other command, or because there is - * specific processing we do (e.g. verifying subarguments) that make them - * unique */ - -int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_brpoplpush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_incr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_decr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_hincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_hincrbyfloat_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_hstrlen_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_bitop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_bitcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_bitpos_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_pfcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_pfadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_pfmerge_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_auth_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_setbit_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_linsert_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_lrem_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - -int redis_smove_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx);
View file
redis-5.3.7.tgz/redis-5.3.7/redis_sentinel.c
Deleted
@@ -1,153 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Pavlo Yatsukhnenko <yatsukhnenko@gmail.com> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - +----------------------------------------------------------------------+ -*/ - -#include "php_redis.h" -#include "redis_commands.h" -#include "redis_sentinel.h" -#include <zend_exceptions.h> - -zend_class_entry *redis_sentinel_ce; -extern zend_class_entry *redis_exception_ce; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, port) - ZEND_ARG_INFO(0, timeout) - ZEND_ARG_INFO(0, persistent) - ZEND_ARG_INFO(0, retry_interval) - ZEND_ARG_INFO(0, read_timeout) -ZEND_END_ARG_INFO() - -zend_function_entry redis_sentinel_functions = { - PHP_ME(RedisSentinel, __construct, arginfo_ctor, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, ckquorum, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, failover, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, flushconfig, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, getMasterAddrByName, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, master, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, masters, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, ping, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, reset, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, sentinels, arginfo_value, ZEND_ACC_PUBLIC) - PHP_ME(RedisSentinel, slaves, arginfo_value, ZEND_ACC_PUBLIC) - PHP_FE_END -}; - -PHP_METHOD(RedisSentinel, __construct) -{ - int persistent = 0; - char *persistent_id = NULL; - double timeout = 0.0, read_timeout = 0.0; - zend_long port = 26379, retry_interval = 0; - redis_sentinel_object *obj; - zend_string *host; - zval *auth = NULL, *zv = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ldz!ldz", - &host, &port, &timeout, &zv, - &retry_interval, &read_timeout, - &auth) == FAILURE) { - RETURN_FALSE; - } - - if (port < 0 || port > UINT16_MAX) { - REDIS_THROW_EXCEPTION("Invalid port", 0); - RETURN_FALSE; - } - - if (timeout < 0L || timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid connect timeout", 0); - RETURN_FALSE; - } - - if (read_timeout < 0L || read_timeout > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid read timeout", 0); - RETURN_FALSE; - } - - if (retry_interval < 0L || retry_interval > INT_MAX) { - REDIS_THROW_EXCEPTION("Invalid retry interval", 0); - RETURN_FALSE; - } - - if (zv) { - ZVAL_DEREF(zv); - if (Z_TYPE_P(zv) == IS_STRING) { - persistent_id = Z_STRVAL_P(zv); - persistent = 1; /* even empty */ - } else { - persistent = zval_is_true(zv); - } - } - - obj = PHPREDIS_ZVAL_GET_OBJECT(redis_sentinel_object, getThis()); - obj->sock = redis_sock_create(ZSTR_VAL(host), ZSTR_LEN(host), port, - timeout, read_timeout, persistent, persistent_id, retry_interval); - if (auth) { - redis_sock_set_auth_zval(obj->sock, auth); - } -} - -PHP_METHOD(RedisSentinel, ckquorum) -{ - REDIS_PROCESS_KW_CMD("ckquorum", redis_sentinel_str_cmd, redis_boolean_response); -} - -PHP_METHOD(RedisSentinel, failover) -{ - REDIS_PROCESS_KW_CMD("failover", redis_sentinel_str_cmd, redis_boolean_response); -} - -PHP_METHOD(RedisSentinel, flushconfig) -{ - REDIS_PROCESS_KW_CMD("flushconfig", redis_sentinel_cmd, redis_boolean_response); -} - -PHP_METHOD(RedisSentinel, getMasterAddrByName) -{ - REDIS_PROCESS_KW_CMD("get-master-addr-by-name", redis_sentinel_str_cmd, redis_mbulk_reply_raw); -} - -PHP_METHOD(RedisSentinel, master) -{ - REDIS_PROCESS_KW_CMD("master", redis_sentinel_str_cmd, redis_mbulk_reply_zipped_raw); -} - -PHP_METHOD(RedisSentinel, masters) -{ - REDIS_PROCESS_KW_CMD("masters", redis_sentinel_cmd, sentinel_mbulk_reply_zipped_assoc); -} - -PHP_METHOD(RedisSentinel, ping) -{ - REDIS_PROCESS_KW_CMD("ping", redis_empty_cmd, redis_boolean_response); -} - -PHP_METHOD(RedisSentinel, reset) -{ - REDIS_PROCESS_KW_CMD("reset", redis_sentinel_str_cmd, redis_boolean_response); -} - -PHP_METHOD(RedisSentinel, sentinels) -{ - REDIS_PROCESS_KW_CMD("sentinels", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); -} - -PHP_METHOD(RedisSentinel, slaves) -{ - REDIS_PROCESS_KW_CMD("slaves", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); -}
View file
redis-5.3.7.tgz/redis-5.3.7/redis_sentinel.h
Deleted
@@ -1,20 +0,0 @@ -#ifndef REDIS_SENTINEL_H -#define REDIS_SENTINEL_H - -#include "sentinel_library.h" - -#define PHP_REDIS_SENTINEL_VERSION "0.1" - -PHP_METHOD(RedisSentinel, __construct); -PHP_METHOD(RedisSentinel, ckquorum); -PHP_METHOD(RedisSentinel, failover); -PHP_METHOD(RedisSentinel, flushconfig); -PHP_METHOD(RedisSentinel, getMasterAddrByName); -PHP_METHOD(RedisSentinel, master); -PHP_METHOD(RedisSentinel, masters); -PHP_METHOD(RedisSentinel, ping); -PHP_METHOD(RedisSentinel, reset); -PHP_METHOD(RedisSentinel, sentinels); -PHP_METHOD(RedisSentinel, slaves); - -#endif /* REDIS_SENTINEL_H */
View file
redis-5.3.7.tgz/redis-5.3.7/redis_session.c
Deleted
@@ -1,1112 +0,0 @@ -/* -*- Mode: C; tab-width: 4 -*- */ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | - | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | - | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | - | Maintainer: Michael Grunder <michael.grunder@gmail.com> | - +----------------------------------------------------------------------+ -*/ - -#include "common.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef PHP_SESSION -#include "ext/standard/info.h" -#include "php_redis.h" -#include "redis_session.h" -#include <zend_exceptions.h> - -#include "library.h" -#include "cluster_library.h" - -#include "php.h" -#include "php_ini.h" -#include "php_variables.h" -#include "SAPI.h" -#include "ext/standard/url.h" - -#define REDIS_SESSION_PREFIX "PHPREDIS_SESSION:" -#define CLUSTER_SESSION_PREFIX "PHPREDIS_CLUSTER_SESSION:" - -/* Session lock LUA as well as its SHA1 hash */ -#define LOCK_RELEASE_LUA_STR "if redis.call(\"get\",KEYS1) == ARGV1 then return redis.call(\"del\",KEYS1) else return 0 end" -#define LOCK_RELEASE_LUA_LEN (sizeof(LOCK_RELEASE_LUA_STR) - 1) -#define LOCK_RELEASE_SHA_STR "b70c2384248f88e6b75b9f89241a180f856ad852" -#define LOCK_RELEASE_SHA_LEN (sizeof(LOCK_RELEASE_SHA_STR) - 1) - -/* Check if a response is the Redis +OK status response */ -#define IS_REDIS_OK(r, len) (r != NULL && len == 3 && !memcmp(r, "+OK", 3)) -#define NEGATIVE_LOCK_RESPONSE 1 - -#define CLUSTER_DEFAULT_PREFIX() \ - zend_string_init(CLUSTER_SESSION_PREFIX, sizeof(CLUSTER_SESSION_PREFIX) - 1, 0) - -ps_module ps_mod_redis = { - PS_MOD_UPDATE_TIMESTAMP(redis) -}; - -ps_module ps_mod_redis_cluster = { - PS_MOD(rediscluster) -}; - -typedef struct { - zend_bool is_locked; - zend_string *session_key; - zend_string *lock_key; - zend_string *lock_secret; -} redis_session_lock_status; - -typedef struct redis_pool_member_ { - - RedisSock *redis_sock; - int weight; - int database; - struct redis_pool_member_ *next; - -} redis_pool_member; - -typedef struct { - - int totalWeight; - int count; - - redis_pool_member *head; - redis_session_lock_status lock_status; - -} redis_pool; - -// static char *session_conf_string(HashTable *ht, const char *key, size_t keylen) { -// } - -PHP_REDIS_API void -redis_pool_add(redis_pool *pool, RedisSock *redis_sock, int weight, int database) -{ - redis_pool_member *rpm = ecalloc(1, sizeof(redis_pool_member)); - rpm->redis_sock = redis_sock; - rpm->weight = weight; - rpm->database = database; - - rpm->next = pool->head; - pool->head = rpm; - - pool->totalWeight += weight; -} - -PHP_REDIS_API void -redis_pool_free(redis_pool *pool) { - - redis_pool_member *rpm, *next; - rpm = pool->head; - while (rpm) { - next = rpm->next; - redis_sock_disconnect(rpm->redis_sock, 0); - redis_free_socket(rpm->redis_sock); - efree(rpm); - rpm = next; - } - - /* Cleanup after our lock */ - if (pool->lock_status.session_key) zend_string_release(pool->lock_status.session_key); - if (pool->lock_status.lock_secret) zend_string_release(pool->lock_status.lock_secret); - if (pool->lock_status.lock_key) zend_string_release(pool->lock_status.lock_key); - - /* Cleanup pool itself */ - efree(pool); -} - -/* Retreive session.gc_maxlifetime from php.ini protecting against an integer overflow */ -static int session_gc_maxlifetime() { - zend_long value = INI_INT("session.gc_maxlifetime"); - if (value > INT_MAX) { - php_error_docref(NULL, E_NOTICE, "session.gc_maxlifetime overflows INT_MAX, truncating."); - return INT_MAX; - } else if (value <= 0) { - php_error_docref(NULL, E_NOTICE, "session.gc_maxlifetime is <= 0, defaulting to 1440 seconds"); - return 1440; - } - - return value; -} - -/* Send a command to Redis. Returns byte count written to socket (-1 on failure) */ -static int redis_simple_cmd(RedisSock *redis_sock, char *cmd, int cmdlen, - char **reply, int *replylen) -{ - *reply = NULL; - int len_written = redis_sock_write(redis_sock, cmd, cmdlen); - - if (len_written >= 0) { - *reply = redis_sock_read(redis_sock, replylen); - } - - return len_written; -} - -static void -redis_pool_member_select(redis_pool_member *rpm) { - RedisSock *redis_sock = rpm->redis_sock; - char *response, *cmd; - int response_len, cmd_len; - - cmd_len = REDIS_SPPRINTF(&cmd, "SELECT", "d", rpm->database); - if (redis_sock_write(redis_sock, cmd, cmd_len) >= 0) { - if ((response = redis_sock_read(redis_sock, &response_len))) { - efree(response); - } - } - efree(cmd); -} - -PHP_REDIS_API redis_pool_member * -redis_pool_get_sock(redis_pool *pool, const char *key) { - - unsigned int pos, i; - memcpy(&pos, key, sizeof(pos)); - pos %= pool->totalWeight; - - redis_pool_member *rpm = pool->head; - - for(i = 0; i < pool->totalWeight;) { - if (pos >= i && pos < i + rpm->weight) { - if (redis_sock_server_open(rpm->redis_sock) == 0) { - if (rpm->database >= 0) { /* default is -1 which leaves the choice to redis. */ - redis_pool_member_select(rpm); - } - - return rpm; - } - } - i += rpm->weight; - rpm = rpm->next; - } - - return NULL; -} -
View file
redis-5.3.7.tgz/redis-5.3.7/redis_session.h
Deleted
@@ -1,25 +0,0 @@ -#ifndef REDIS_SESSION_H -#define REDIS_SESSION_H -#ifdef PHP_SESSION -#include "ext/session/php_session.h" - -PS_OPEN_FUNC(redis); -PS_CLOSE_FUNC(redis); -PS_READ_FUNC(redis); -PS_WRITE_FUNC(redis); -PS_DESTROY_FUNC(redis); -PS_GC_FUNC(redis); -PS_CREATE_SID_FUNC(redis); - -PS_VALIDATE_SID_FUNC(redis); -PS_UPDATE_TIMESTAMP_FUNC(redis); - -PS_OPEN_FUNC(rediscluster); -PS_CLOSE_FUNC(rediscluster); -PS_READ_FUNC(rediscluster); -PS_WRITE_FUNC(rediscluster); -PS_DESTROY_FUNC(rediscluster); -PS_GC_FUNC(rediscluster); - -#endif -#endif
View file
redis-5.3.7.tgz/redis-5.3.7/sentinel.markdown
Deleted
@@ -1,196 +0,0 @@ -Redis Sentinel -============== - -Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures. - -Redis Sentinel also provides other collateral tasks such as monitoring, notifications and acts as a configuration provider for clients. - -## Class RedisSentinel ------ - -##### *Parameters* - -*host*: String, IP address or hostname -*port*: Int (optional, default is 26379) -*timeout*: Float, value in seconds (optional, default is 0 meaning unlimited) -*persistent*: String, persistent connection id (optional, default is NULL meaning not persistent) -*retry_interval*: Int, value in milliseconds (optional, default is 0) -*read_timeout*: Float, value in seconds (optional, default is 0 meaning unlimited) -*auth*:String, or an Array with one or two elements, used to authenticate with the redis-sentinel. (optional, default is NULL meaning NOAUTH) - -##### *Example* - -~~~php -$sentinel = new RedisSentinel('127.0.0.1'); // default parameters -$sentinel = new RedisSentinel('127.0.0.1', 26379, 2.5); // 2.5 sec timeout. -$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, 'sentinel'); // persistent connection with id 'sentinel' -$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, ''); // also persistent connection with id '' -$sentinel = new RedisSentinel('127.0.0.1', 26379, 1, null, 100); // 1 sec timeout, 100ms delay between reconnection attempts. -$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, NULL, 0, 0, "secret"); // connect sentinel with password authentication -~~~ - -### Usage ------ - -* ckquorum(#ckquorum) - Check if the current Sentinel configuration is able to reach the quorum needed to failover. -* failover(#failover) - Force a failover as if the master was not reachable. -* flushconfig(#flushconfig) - Force Sentinel to rewrite its configuration on disk. -* getMasterAddrByName(#getMasterAddrByName) - Return the ip and port number of the master with that name. -* master(#master) - Return the state and info of the specified master. -* masters(#masters) - Return a list of monitored masters and their state. -* ping(#ping) - Ping the sentinel. -* reset(#reset) - Reset all the masters with matching name. -* sentinels(#sentinels) - Return a list of sentinel instances for this master, and their state. -* slaves(#slaves) - Return a list of replicas for this master, and their state. - ------ - -### ckquorum ------ -_**Description**_: Check if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok. - -##### *Parameters* -*String*: master name - -##### *Return value* -*Bool*: `TRUE` in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->ckquorum('mymaster'); -~~~ - -### failover ------ -_**Description**_: Force a failover as if the master was not reachable, and without asking for agreement to other Sentinels (however a new version of the configuration will be published so that the other Sentinels will update their configurations). - -##### *Parameters* -*String*: master name - -##### *Return value* -*Bool*: `TRUE` in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->failover('mymaster'); -~~~ - -### flushconfig ------ -_**Description**_: Force Sentinel to rewrite its configuration on disk, including the current Sentinel state. Normally Sentinel rewrites the configuration every time something changes in its state (in the context of the subset of the state which is persisted on disk across restart). However sometimes it is possible that the configuration file is lost because of operation errors, disk failures, package upgrade scripts or configuration managers. In those cases a way to to force Sentinel to rewrite the configuration file is handy. This command works even if the previous configuration file is completely missing. - -##### *Parameters* -(none) - -##### *Return value* -*Bool*: `TRUE` in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->flushconfig(); -~~~ - -### getMasterAddrByName ------ -_**Description**_: Return the ip and port number of the master with that name. If a failover is in progress or terminated successfully for this master it returns the address and port of the promoted replica. - -##### *Parameters* -*String*: master name - -##### *Return value* -*Array*, *Bool*: 'address', 'port' in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->getMasterAddrByName('mymaster'); -~~~ - -### master ------ -_**Description**_: Return the state and info of the specified master. - -##### *Parameters* -*String*: master name - -##### *Return value* -*Array*, *Bool*: Associative array with info in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->master('mymaster'); -~~~ - -### masters ------ -_**Description**_: Return a list of monitored masters and their state. - -##### *Parameters* -(none) - -##### *Return value* -*Array*, *Bool*: List of arrays with info for each master in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->masters(); -~~~ - -### ping ------ -_**Description**_: Ping the sentinel. - -##### *Parameters* -(none) - -##### *Return value* -*Bool*: `TRUE` in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->ping(); -~~~ - -### reset ------ -_**Description**_: This command will reset all the masters with matching name. The pattern argument is a glob-style pattern. The reset process clears any previous state in a master (including a failover in progress), and removes every replica and sentinel already discovered and associated with the master. - -##### *Parameters* -*String*: pattern - -##### *Return value* -*Bool*: `TRUE` in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->reset('*'); -~~~ - -### sentinels ------ -_**Description**_: Return a list of sentinel instances for this master, and their state. - -##### *Parameters* -*String*: master name - -##### *Return value* -*Array*, *Bool*: List of arrays with info for each sentinels in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->sentinels('mymaster'); -~~~ - -### slaves ------ -_**Description**_: Return a list of replicas for this master, and their state. - -##### *Parameters* -*String*: master name - -##### *Return value* -*Array*, *Bool*: List of arrays with info for each replicas in case of success, `FALSE` in case of failure. - -##### *Example* -~~~php -$sentinel->slaves('mymaster'); -~~~
View file
redis-5.3.7.tgz/redis-5.3.7/sentinel_library.c
Deleted
@@ -1,66 +0,0 @@ -#include "sentinel_library.h" - -static zend_object_handlers redis_sentinel_object_handlers; - -static void -free_redis_sentinel_object(zend_object *object) -{ - redis_sentinel_object *obj = PHPREDIS_GET_OBJECT(redis_sentinel_object, object); - - if (obj->sock) { - redis_sock_disconnect(obj->sock, 0); - redis_free_socket(obj->sock); - } - zend_object_std_dtor(&obj->std); -} - -zend_object * -create_sentinel_object(zend_class_entry *ce) -{ - redis_sentinel_object *obj = ecalloc(1, sizeof(*obj) + zend_object_properties_size(ce)); - - zend_object_std_init(&obj->std, ce); - object_properties_init(&obj->std, ce); - - memcpy(&redis_sentinel_object_handlers, zend_get_std_object_handlers(), sizeof(redis_sentinel_object_handlers)); - redis_sentinel_object_handlers.offset = XtOffsetOf(redis_sentinel_object, std); - redis_sentinel_object_handlers.free_obj = free_redis_sentinel_object; - obj->std.handlers = &redis_sentinel_object_handlers; - - return &obj->std; -} - -PHP_REDIS_API int -sentinel_mbulk_reply_zipped_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) -{ - char inbuf4096; - int i, nelem; - size_t len; - zval z_ret; - - /* Throws exception on failure */ - if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0) { - RETVAL_FALSE; - return FAILURE; - } - - if (*inbuf != TYPE_MULTIBULK) { - if (*inbuf == TYPE_ERR) { - redis_sock_set_err(redis_sock, inbuf + 1, len - 1); - } - - RETVAL_FALSE; - return FAILURE; - } - array_init(&z_ret); - nelem = atoi(inbuf + 1); - for (i = 0; i < nelem; ++i) { - /* redis_mbulk_reply_zipped_raw calls redis_mbulk_reply_zipped - * which puts result into return_value via RETVAL_ZVAL */ - redis_mbulk_reply_zipped_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, ctx); - add_next_index_zval(&z_ret, return_value); - } - - RETVAL_ZVAL(&z_ret, 0, 1); - return SUCCESS; -}
View file
redis-5.3.7.tgz/redis-5.3.7/tests/RedisArrayTest.php
Deleted
@@ -1,668 +0,0 @@ -<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); -require_once(dirname($_SERVER'PHP_SELF')."/TestSuite.php"); - -define('REDIS_ARRAY_DATA_SIZE', 1000); - -function custom_hash($str) { - // str has the following format: $APPID_fb$FACEBOOKID_$key. - $pos = strpos($str, '_fb'); - if(preg_match("#\w+_fb(?<facebook_id>\d+)_\w+#", $str, $out)) { - return $out'facebook_id'; - } - return $str; -} - -function parseHostPort($str, &$host, &$port) { - $pos = strrpos($str, ':'); - $host = substr($str, 0, $pos); - $port = substr($str, $pos+1); -} - -function getRedisVersion($obj_r) { - $arr_info = $obj_r->info(); - if (!$arr_info || !isset($arr_info'redis_version')) { - return "0.0.0"; - } - return $arr_info'redis_version'; -} - -/* Determine the lowest redis version attached to this RedisArray object */ -function getMinVersion($obj_ra) { - $min_version = "0.0.0"; - foreach ($obj_ra->_hosts() as $host) { - $version = getRedisVersion($obj_ra->_instance($host)); - if (version_compare($version, $min_version) > 0) { - $min_version = $version; - } - } - - return $min_version; -} - -class Redis_Array_Test extends TestSuite -{ - private $min_version; - private $strings; - public $ra = NULL; - private $data = NULL; - - public function setUp() { - // initialize strings. - $n = REDIS_ARRAY_DATA_SIZE; - $this->strings = array(); - for($i = 0; $i < $n; $i++) { - $this->strings'key-'.$i = 'val-'.$i; - } - - global $newRing, $oldRing, $useIndex; - $options = 'previous' => $oldRing, 'index' => $useIndex; - if ($this->getAuth()) { - $options'auth' = $this->getAuth(); - } - $this->ra = new RedisArray($newRing, $options); - $this->min_version = getMinVersion($this->ra); - } - - public function testMSet() { - // run mset - $this->assertTrue(TRUE === $this->ra->mset($this->strings)); - - // check each key individually using the array - foreach($this->strings as $k => $v) { - $this->assertTrue($v === $this->ra->get($k)); - } - - // check each key individually using a new connection - foreach($this->strings as $k => $v) { - parseHostPort($this->ra->_target($k), $host, $port); - - $target = $this->ra->_target($k); - $pos = strrpos($target, ':'); - - $host = substr($target, 0, $pos); - $port = substr($target, $pos+1); - - $r = new Redis; - $r->pconnect($host, (int)$port); - if ($this->getAuth()) { - $this->assertTrue($r->auth($this->getAuth())); - } - $this->assertTrue($v === $r->get($k)); - } - } - - public function testMGet() { - $this->assertTrue(array_values($this->strings) === $this->ra->mget(array_keys($this->strings))); - } - - private function addData($commonString) { - $this->data = array(); - for($i = 0; $i < REDIS_ARRAY_DATA_SIZE; $i++) { - $k = rand().'_'.$commonString.'_'.rand(); - $this->data$k = rand(); - } - $this->ra->mset($this->data); - } - - private function checkCommonLocality() { - // check that they're all on the same node. - $lastNode = NULL; - foreach($this->data as $k => $v) { - $node = $this->ra->_target($k); - if($lastNode) { - $this->assertTrue($node === $lastNode); - } - $this->assertTrue($this->ra->get($k) == $v); - $lastNode = $node; - } - } - - public function testKeyLocality() { - - // basic key locality with default hash - $this->addData('{hashed part of the key}'); - $this->checkCommonLocality(); - - // with common hashing function - global $newRing, $oldRing, $useIndex; - $options = 'previous' => $oldRing, 'index' => $useIndex, 'function' => 'custom_hash'; - if ($this->getAuth()) { - $options'auth' = $this->getAuth(); - } - $this->ra = new RedisArray($newRing, $options); - - // basic key locality with custom hash - $this->addData('fb'.rand()); - $this->checkCommonLocality(); - } - - public function customDistributor($key) - { - $a = unpack("N*", md5($key, true)); - global $newRing; - $pos = abs($a1) % count($newRing); - - return $pos; - } - - public function testKeyDistributor() - { - global $newRing, $useIndex; - $options = 'index' => $useIndex, 'function' => 'custom_hash', 'distributor' => $this, "customDistributor"; - if ($this->getAuth()) { - $options'auth' = $this->getAuth(); - } - $this->ra = new RedisArray($newRing, $options); - - // custom key distribution function. - $this->addData('fb'.rand()); - - // check that they're all on the expected node. - $lastNode = NULL; - foreach($this->data as $k => $v) { - $node = $this->ra->_target($k); - $pos = $this->customDistributor($k); - $this->assertTrue($node === $newRing$pos); - } - } - - /* Scan a whole key and return the overall result */ - protected function execKeyScan($cmd, $key) { - $res = ; - - $it = NULL; - do { - $chunk = $this->ra->$cmd($key, $it); - foreach ($chunk as $field => $value) { - $res$field = $value; - } - } while ($it !== 0); - - return $res; - } - - public function testKeyScanning() { - $h_vals = 'foo' => 'bar', 'baz' => 'bop'; - $z_vals = 'one' => 1, 'two' => 2, 'three' => 3; - $s_vals = 'mem1', 'mem2', 'mem3'; - - $this->ra->del('scan-hash', 'scan-set', 'scan-zset'); - - $this->ra->hMSet('scan-hash', $h_vals); - foreach ($z_vals as $k => $v) - $this->ra->zAdd('scan-zset', $v, $k); - $this->ra->sAdd('scan-set', ...$s_vals); - - $s_scan = $this->execKeyScan('sScan', 'scan-set'); - $this->assertTrue(count(array_diff_key(array_flip($s_vals), array_flip($s_scan))) == 0); - - $this->assertEquals($h_vals, $this->execKeyScan('hScan', 'scan-hash'));
View file
redis-5.3.7.tgz/redis-5.3.7/tests/RedisClusterTest.php
Deleted
@@ -1,782 +0,0 @@ -<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); -require_once(dirname($_SERVER'PHP_SELF')."/RedisTest.php"); - -/** - * Most RedisCluster tests should work the same as the standard Redis object - * so we only override specific functions where the prototype is different or - * where we're validating specific cluster mechanisms - */ -class Redis_Cluster_Test extends Redis_Test { - private static $_arr_node_map = ; - - private $_arr_redis_types = - Redis::REDIS_STRING, - Redis::REDIS_SET, - Redis::REDIS_LIST, - Redis::REDIS_ZSET, - Redis::REDIS_HASH - ; - - private $_arr_failover_types = - RedisCluster::FAILOVER_NONE, - RedisCluster::FAILOVER_ERROR, - RedisCluster::FAILOVER_DISTRIBUTE - ; - - /** - * @var string - */ - protected $sessionPrefix = 'PHPREDIS_CLUSTER_SESSION:'; - - /** - * @var string - */ - protected $sessionSaveHandler = 'rediscluster'; - - /* Tests we'll skip all together in the context of RedisCluster. The - * RedisCluster class doesn't implement specialized (non-redis) commands - * such as sortAsc, or sortDesc and other commands such as SELECT are - * simply invalid in Redis Cluster */ - public function testSortAsc() { return $this->markTestSkipped(); } - public function testSortDesc() { return $this->markTestSkipped(); } - public function testWait() { return $this->markTestSkipped(); } - public function testSelect() { return $this->markTestSkipped(); } - public function testReconnectSelect() { return $this->markTestSkipped(); } - public function testMultipleConnect() { return $this->markTestSkipped(); } - public function testDoublePipeNoOp() { return $this->markTestSkipped(); } - public function testSwapDB() { return $this->markTestSkipped(); } - public function testConnectException() { return $this->markTestSkipped(); } - public function testTlsConnect() { return $this->markTestSkipped(); } - public function testInvalidAuthArgs() { return $this->markTestSkipped(); } - - public function testlMove() { return $this->markTestSkipped(); } - public function testsMisMember() { return $this->markTestSkipped(); } - public function testzDiff() { return $this->markTestSkipped(); } - public function testzDiffStore() { return $this->markTestSkipped(); } - public function testzMscore() { return $this->marktestSkipped(); } - public function testCopy() { return $this->marktestSkipped(); } - - /* Session locking feature is currently not supported in in context of Redis Cluster. - The biggest issue for this is the distribution nature of Redis cluster */ - public function testSession_lockKeyCorrect() { return $this->markTestSkipped(); } - public function testSession_lockingDisabledByDefault() { return $this->markTestSkipped(); } - public function testSession_lockReleasedOnClose() { return $this->markTestSkipped(); } - public function testSession_ttlMaxExecutionTime() { return $this->markTestSkipped(); } - public function testSession_ttlLockExpire() { return $this->markTestSkipped(); } - public function testSession_lockHoldCheckBeforeWrite_otherProcessHasLock() { return $this->markTestSkipped(); } - public function testSession_lockHoldCheckBeforeWrite_nobodyHasLock() { return $this->markTestSkipped(); } - public function testSession_correctLockRetryCount() { return $this->markTestSkipped(); } - public function testSession_defaultLockRetryCount() { return $this->markTestSkipped(); } - public function testSession_noUnlockOfOtherProcess() { return $this->markTestSkipped(); } - public function testSession_lockWaitTime() { return $this->markTestSkipped(); } - - /* Load our seeds on construction */ - public function __construct($str_host, $i_port, $str_auth) { - parent::__construct($str_host, $i_port, $str_auth); - - $str_nodemap_file = dirname($_SERVER'PHP_SELF') . '/nodes/nodemap'; - - if (!file_exists($str_nodemap_file)) { - fprintf(STDERR, "Error: Can't find nodemap file for seeds!\n"); - exit(1); - } - - /* Store our node map */ - if (!self::$_arr_node_map) { - self::$_arr_node_map = array_filter( - explode("\n", file_get_contents($str_nodemap_file) - )); - } - } - - /* Override setUp to get info from a specific node */ - public function setUp() { - $this->redis = $this->newInstance(); - $info = $this->redis->info(uniqid()); - $this->version = (isset($info'redis_version')?$info'redis_version':'0.0.0'); - } - - /* Override newInstance as we want a RedisCluster object */ - protected function newInstance() { - return new RedisCluster(NULL, self::$_arr_node_map, 30, 30, true, $this->getAuth()); - } - - /* Overrides for RedisTest where the function signature is different. This - * is only true for a few commands, which by definition have to be directed - * at a specific node */ - - public function testPing() { - for ($i = 0; $i < 20; $i++) { - $this->assertTrue($this->redis->ping("key:$i")); - $this->assertEquals('BEEP', $this->redis->ping("key:$i", 'BEEP')); - } - - /* Make sure both variations work in MULTI mode */ - $this->redis->multi(); - $this->redis->ping('{ping-test}'); - $this->redis->ping('{ping-test}','BEEP'); - $this->assertEquals(true, 'BEEP', $this->redis->exec()); - } - - public function testRandomKey() { - /* Ensure some keys are present to test */ - for ($i = 0; $i < 1000; $i++) { - if (rand(1, 2) == 1) { - $this->redis->set("key:$i", "val:$i"); - } - } - - for ($i = 0; $i < 1000; $i++) { - $k = $this->redis->randomKey("key:$i"); - $this->assertTrue($this->redis->exists($k)); - } - } - - public function testEcho() { - $this->assertEquals($this->redis->echo('k1', 'hello'), 'hello'); - $this->assertEquals($this->redis->echo('k2', 'world'), 'world'); - $this->assertEquals($this->redis->echo('k3', " 0123 "), " 0123 "); - } - - public function testSortPrefix() { - $this->redis->setOption(Redis::OPT_PREFIX, 'some-prefix:'); - $this->redis->del('some-item'); - $this->redis->sadd('some-item', 1); - $this->redis->sadd('some-item', 2); - $this->redis->sadd('some-item', 3); - - $this->assertEquals(array('1','2','3'), $this->redis->sort('some-item')); - - // Kill our set/prefix - $this->redis->del('some-item'); - $this->redis->setOption(Redis::OPT_PREFIX, ''); - } - - public function testDBSize() { - for ($i = 0; $i < 10; $i++) { - $str_key = "key:$i"; - $this->assertTrue($this->redis->flushdb($str_key)); - $this->redis->set($str_key, "val:$i"); - $this->assertEquals(1, $this->redis->dbsize($str_key)); - } - } - - public function testInfo() { - $arr_check_keys = - "redis_version", "arch_bits", "uptime_in_seconds", "uptime_in_days", - "connected_clients", "connected_slaves", "used_memory", - "total_connections_received", "total_commands_processed", - "role" - ; - - for ($i = 0; $i < 3; $i++) { - $arr_info = $this->redis->info("k:$i"); - foreach ($arr_check_keys as $str_check_key) { - $this->assertTrue(isset($arr_info$str_check_key)); - } - } - } - - public function testClient() { - $str_key = 'key-' . rand(1,100); - - $this->assertTrue($this->redis->client($str_key, 'setname', 'cluster_tests')); - - $arr_clients = $this->redis->client($str_key, 'list'); - $this->assertTrue(is_array($arr_clients)); - - /* Find us in the list */ - $str_addr = NULL; - foreach ($arr_clients as $arr_client) { - if ($arr_client'name' == 'cluster_tests') { - $str_addr = $arr_client'addr'; - break; - } - } - - /* We should be in there */ - $this->assertFalse(empty($str_addr)); -
View file
redis-5.3.7.tgz/redis-5.3.7/tests/RedisSentinelTest.php
Deleted
@@ -1,113 +0,0 @@ -<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); - -require_once(dirname($_SERVER'PHP_SELF')."/TestSuite.php"); - -class Redis_Sentinel_Test extends TestSuite -{ - const NAME = 'mymaster'; - - /** - * @var RedisSentinel - */ - public $sentinel; - - /** - * Common fields - */ - protected $fields = - 'name', - 'ip', - 'port', - 'runid', - 'flags', - 'link-pending-commands', - 'link-refcount', - 'last-ping-sent', - 'last-ok-ping-reply', - 'last-ping-reply', - 'down-after-milliseconds', - ; - - protected function newInstance() - { - return new RedisSentinel($this->getHost()); - } - - public function setUp() - { - $this->sentinel = $this->newInstance(); - } - - public function testCkquorum() - { - $this->assertTrue(is_bool($this->sentinel->ckquorum(self::NAME))); - } - - public function testFailover() - { - $this->assertFalse($this->sentinel->failover(self::NAME)); - } - - public function testFlushconfig() - { - $this->assertTrue($this->sentinel->flushconfig()); - } - - public function testGetMasterAddrByName() - { - $result = $this->sentinel->getMasterAddrByName(self::NAME); - $this->assertTrue(is_array($result)); - $this->assertEquals(2, count($result)); - } - - protected function checkFields(array $fields) - { - foreach ($this->fields as $k) { - $this->assertTrue(array_key_exists($k, $fields)); - } - } - - public function testMaster() - { - $result = $this->sentinel->master(self::NAME); - $this->assertTrue(is_array($result)); - $this->checkFields($result); - } - - public function testMasters() - { - $result = $this->sentinel->masters(); - $this->assertTrue(is_array($result)); - foreach ($result as $master) { - $this->checkFields($master); - } - } - - public function testPing() - { - $this->assertTrue($this->sentinel->ping()); - } - - public function testReset() - { - $this->assertFalse($this->sentinel->reset('*')); - } - - public function testSentinels() - { - $result = $this->sentinel->sentinels(self::NAME); - $this->assertTrue(is_array($result)); - foreach ($result as $sentinel) { - $this->checkFields($sentinel); - } - } - - public function testSlaves() - { - $result = $this->sentinel->slaves(self::NAME); - $this->assertTrue(is_array($result)); - foreach ($result as $slave) { - $this->checkFields($slave); - } - } -}
View file
redis-5.3.7.tgz/redis-5.3.7/tests/RedisTest.php
Deleted
@@ -1,7018 +0,0 @@ -<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); - -require_once(dirname($_SERVER'PHP_SELF')."/TestSuite.php"); - -class Redis_Test extends TestSuite -{ - /* City lat/long */ - protected $cities = - 'Chico' => -121.837478, 39.728494, - 'Sacramento' => -121.494400, 38.581572, - 'Gridley' => -121.693583, 39.363777, - 'Marysville' => -121.591355, 39.145725, - 'Cupertino' => -122.032182, 37.322998 - ; - - protected $serializers = - Redis::SERIALIZER_NONE, - Redis::SERIALIZER_PHP, - ; - - /** - * @var Redis - */ - public $redis; - - /** - * @var string - */ - protected $sessionPrefix = 'PHPREDIS_SESSION:'; - - /** - * @var string - */ - protected $sessionSaveHandler = 'redis'; - - public function setUp() { - $this->redis = $this->newInstance(); - $info = $this->redis->info(); - $this->version = (isset($info'redis_version')?$info'redis_version':'0.0.0'); - - if (defined('Redis::SERIALIZER_IGBINARY')) { - $this->serializers = Redis::SERIALIZER_IGBINARY; - } - } - - protected function minVersionCheck($version) { - return version_compare($this->version, $version) >= 0; - } - - protected function mstime() { - return round(microtime(true)*1000); - } - - protected function getAuthParts(&$user, &$pass) { - $user = $pass = NULL; - - $auth = $this->getAuth(); - if ( ! $auth) - return; - - if (is_array($auth)) { - if (count($auth) > 1) { - list($user, $pass) = $auth; - } else { - $pass = $auth0; - } - } else { - $pass = $auth; - } - } - - protected function getAuthFragment() { - static $_authidx = 0; - $_authidx++; - - $this->getAuthParts($user, $pass); - - if ($user && $pass) { - if ($_authidx % 2 == 0) - return "authuser=$user&authpass=$pass"; - else - return "auth=$user&auth=$pass"; - } else if ($pass) { - if ($_authidx % 3 == 0) - return "authpass=$pass"; - if ($_authidx % 2 == 0) - return "auth=$pass"; - else - return "auth=$pass"; - } else { - return NULL; - } - } - - protected function getFullHostPath() - { - $fullHostPath = parent::getFullHostPath(); - $authFragment = $this->getAuthFragment(); - - if (isset($fullHostPath) && $authFragment) { - $fullHostPath .= "?$authFragment"; - } - return $fullHostPath; - } - - protected function newInstance() { - $r = new Redis(); - - $r->connect($this->getHost(), $this->getPort()); - - if($this->getAuth()) { - $this->assertTrue($r->auth($this->getAuth())); - } - return $r; - } - - public function tearDown() { - if($this->redis) { - $this->redis->close(); - } - } - - public function reset() - { - $this->setUp(); - $this->tearDown(); - } - - /* Helper function to determine if the clsas has pipeline support */ - protected function havePipeline() { - $str_constant = get_class($this->redis) . '::PIPELINE'; - return defined($str_constant); - } - - public function testMinimumVersion() - { - // Minimum server version required for tests - $this->assertTrue(version_compare($this->version, "2.4.0") >= 0); - } - - public function testPing() { - /* Reply literal off */ - $this->assertTrue($this->redis->ping()); - $this->assertTrue($this->redis->ping(NULL)); - $this->assertEquals('BEEP', $this->redis->ping('BEEP')); - - /* Make sure we're good in MULTI mode */ - $this->redis->multi(); - - $this->redis->ping(); - $this->redis->ping('BEEP'); - $this->assertEquals(true, 'BEEP', $this->redis->exec()); - } - - public function testPipelinePublish() { - if (!$this->havePipeline()) { - $this->markTestSkipped(); - } - - $ret = $this->redis->pipeline() - ->publish('chan', 'msg') - ->exec(); - - $this->assertTrue(is_array($ret) && count($ret) === 1 && $ret0 >= 0); - } - - // Run some simple tests against the PUBSUB command. This is problematic, as we - // can't be sure what's going on in the instance, but we can do some things. - public function testPubSub() { - // Only available since 2.8.0 - if (version_compare($this->version, "2.8.0") < 0) { - $this->markTestSkipped(); - return; - } - - // PUBSUB CHANNELS ... - $result = $this->redis->pubsub("channels", "*"); - $this->assertTrue(is_array($result)); - $result = $this->redis->pubsub("channels"); - $this->assertTrue(is_array($result)); - - // PUBSUB NUMSUB - - $c1 = uniqid() . '-' . rand(1,100); - $c2 = uniqid() . '-' . rand(1,100); - - $result = $this->redis->pubsub("numsub", $c1, $c2); - - // Should get an array back, with two elements - $this->assertTrue(is_array($result)); - $this->assertEquals(count($result), 2); - - // Make sure the elements are correct, and have zero counts - foreach($c1,$c2 as $channel) { - $this->assertTrue(isset($result$channel)); - $this->assertEquals($result$channel, 0); - } - - // PUBSUB NUMPAT
View file
redis-5.3.7.tgz/redis-5.3.7/tests/TestRedis.php
Deleted
@@ -1,86 +0,0 @@ -<?php define('PHPREDIS_TESTRUN', true); - -require_once(dirname($_SERVER'PHP_SELF')."/TestSuite.php"); -require_once(dirname($_SERVER'PHP_SELF')."/RedisTest.php"); -require_once(dirname($_SERVER'PHP_SELF')."/RedisArrayTest.php"); -require_once(dirname($_SERVER'PHP_SELF')."/RedisClusterTest.php"); -require_once(dirname($_SERVER'PHP_SELF')."/RedisSentinelTest.php"); - -/* Make sure errors go to stdout and are shown */ -error_reporting(E_ALL); -ini_set( 'display_errors','1'); - -/* Grab options */ -$arr_args = getopt('', 'host:', 'port:', 'class:', 'test:', 'nocolors', 'user:', 'auth:'); - -/* Grab the test the user is trying to run */ -$arr_valid_classes = 'redis', 'redisarray', 'rediscluster', 'redissentinel'; -$str_class = isset($arr_args'class') ? strtolower($arr_args'class') : 'redis'; -$boo_colorize = !isset($arr_args'nocolors'); - -/* Get our test filter if provided one */ -$str_filter = isset($arr_args'test') ? $arr_args'test' : NULL; - -/* Grab override host/port if it was passed */ -$str_host = isset($arr_args'host') ? $arr_args'host' : '127.0.0.1'; -$i_port = isset($arr_args'port') ? intval($arr_args'port') : 6379; - -/* Get optional username and auth (password) */ -$str_user = isset($arr_args'user') ? $arr_args'user' : NULL; -$str_auth = isset($arr_args'auth') ? $arr_args'auth' : NULL; - -/* Massage the actual auth arg */ -$auth = NULL; -if ($str_user && $str_auth) { - $auth = $str_user, $str_auth; -} else if ($str_auth) { - $auth = $str_auth; -} else if ($str_user) { - echo TestSuite::make_warning("User passed without a password, ignoring!\n"); -} - -/* Validate the class is known */ -if (!in_array($str_class, $arr_valid_classes)) { - echo "Error: Valid test classes are Redis, RedisArray, RedisCluster and RedisSentinel!\n"; - exit(1); -} - -/* Toggle colorization in our TestSuite class */ -TestSuite::flagColorization($boo_colorize); - -/* Let the user know this can take a bit of time */ -echo "Note: these tests might take up to a minute. Don't worry :-)\n"; -echo "Using PHP version " . PHP_VERSION . " (" . (PHP_INT_SIZE*8) . " bits)\n"; - -/* Depending on the classes being tested, run our tests on it */ -echo "Testing class "; -if ($str_class == 'redis') { - echo TestSuite::make_bold("Redis") . "\n"; - exit(TestSuite::run("Redis_Test", $str_filter, $str_host, $i_port, $auth)); -} else if ($str_class == 'redisarray') { - echo TestSuite::make_bold("RedisArray") . "\n"; - global $useIndex; - foreach(array(true, false) as $useIndex) { - echo "\n".($useIndex?"WITH":"WITHOUT"). " per-node index:\n"; - - /* The various RedisArray subtests we can run */ - $arr_ra_tests = - 'Redis_Array_Test', 'Redis_Rehashing_Test', 'Redis_Auto_Rehashing_Test', - 'Redis_Multi_Exec_Test', 'Redis_Distributor_Test' - ; - - foreach ($arr_ra_tests as $str_test) { - /* Run until we encounter a failure */ - if (run_tests($str_test, $str_filter, $str_host, $auth) != 0) { - exit(1); - } - } - } -} else if ($str_class == 'rediscluster') { - echo TestSuite::make_bold("RedisCluster") . "\n"; - exit(TestSuite::run("Redis_Cluster_Test", $str_filter, $str_host, $i_port, $auth)); -} else { - echo TestSuite::make_bold("RedisSentinel") . "\n"; - exit(TestSuite::run("Redis_Sentinel_Test", $str_filter, $str_host, $i_port, $auth)); -} -?>
View file
redis-5.3.7.tgz/redis-5.3.7/tests/TestSuite.php
Deleted
@@ -1,305 +0,0 @@ -<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); - -/* A specific exception for when we skip a test */ -class TestSkippedException extends Exception {} - -// phpunit is such a pain to install, we're going with pure-PHP here. -class TestSuite -{ - /* Host and port the unit tests will use */ - private $str_host; - private $i_port = 6379; - - /* Redis authentication we'll use */ - private $auth; - - private static $_boo_colorize = false; - - private static $BOLD_ON = "\0331m"; - private static $BOLD_OFF = "\0330m"; - - private static $BLACK = "\0330;30m"; - private static $DARKGRAY = "\0331;30m"; - private static $BLUE = "\0330;34m"; - private static $PURPLE = "\0330;35m"; - private static $GREEN = "\0330;32m"; - private static $YELLOW = "\0330;33m"; - private static $RED = "\0330;31m"; - - public static $errors = ; - public static $warnings = ; - - public function __construct($str_host, $i_port, $auth) { - $this->str_host = $str_host; - $this->i_port = $i_port; - $this->auth = $auth; - } - - public function getHost() { return $this->str_host; } - public function getPort() { return $this->i_port; } - public function getAuth() { return $this->auth; } - - public static function getAvailableCompression() { - $result = Redis::COMPRESSION_NONE; - if (defined('Redis::COMPRESSION_LZF')) - $result = Redis::COMPRESSION_LZF; - if (defined('Redis::COMPRESSION_LZ4')) - $result = Redis::COMPRESSION_LZ4; - if (defined('Redis::COMPRESSION_ZSTD')) - $result = Redis::COMPRESSION_ZSTD; - - return $result; - } - - /** - * Returns the fully qualified host path, - * which may be used directly for php.ini parameters like session.save_path - * - * @return null|string - */ - protected function getFullHostPath() - { - return $this->str_host - ? 'tcp://' . $this->str_host . ':' . $this->i_port - : null; - } - - public static function make_bold($str_msg) { - return self::$_boo_colorize - ? self::$BOLD_ON . $str_msg . self::$BOLD_OFF - : $str_msg; - } - - public static function make_success($str_msg) { - return self::$_boo_colorize - ? self::$GREEN . $str_msg . self::$BOLD_OFF - : $str_msg; - } - - public static function make_fail($str_msg) { - return self::$_boo_colorize - ? self::$RED . $str_msg . self::$BOLD_OFF - : $str_msg; - } - - public static function make_warning($str_msg) { - return self::$_boo_colorize - ? self::$YELLOW . $str_msg . self::$BOLD_OFF - : $str_msg; - } - - protected function assertFalse($bool) { - if(!$bool) - return true; - - $bt = debug_backtrace(false); - self::$errors = sprintf("Assertion failed: %s:%d (%s)\n", - $bt0"file", $bt0"line", $bt1"function"); - - return false; - } - - protected function assertTrue($bool) { - if($bool) - return true; - - $bt = debug_backtrace(false); - self::$errors = sprintf("Assertion failed: %s:%d (%s)\n", - $bt0"file", $bt0"line", $bt1"function"); - - return false; - } - - protected function assertInArray($ele, $arr, $cb = NULL) { - if ($cb && !is_callable($cb)) - die("Fatal: assertInArray callback must be callable!\n"); - - if (($in = in_array($ele, $arr)) && (!$cb || $cb($arrarray_search($ele, $arr)))) - return true; - - - $bt = debug_backtrace(false); - $ex = $in ? 'validation' : 'missing'; - self::$errors = sprintf("Assertion failed: %s:%d (%s) %s '%s'\n", - $bt0"file", $bt0"line", $bt1"function", $ex, $ele); - - return false; - } - - protected function assertArrayKey($arr, $key, $cb = NULL) { - if ($cb && !is_callable($cb)) - die("Fatal: assertArrayKey callback must be callable\n"); - - if (($exists = isset($arr$key)) && (!$cb || $cb($arr$key))) - return true; - - $bt = debug_backtrace(false); - $ex = $exists ? 'validation' : 'missing'; - self::$errors = sprintf("Assertion failed: %s:%d (%s) %s '%s'\n", - $bt0"file", $bt0"line", $bt1"function", $ex, $key); - - return false; - } - - protected function assertValidate($val, $cb) { - if ( ! is_callable($cb)) - die("Fatal: Callable assertValidate callback required\n"); - - if ($cb($val)) - return true; - - $bt = debug_backtrace(false); - self::$errors = sprintf("Assertion failed: %s:%d (%s)\n", - $bt0"file", $bt0"line", $bt1"function"); - - return false; - } - - protected function assertThrowsMatch($arg, $cb, $regex = NULL) { - $threw = $match = false; - - if ( ! is_callable($cb)) - die("Fatal: Callable assertThrows callback required\n"); - - try { - $cb($arg); - } catch (Exception $ex) { - $threw = true; - $match = !$regex || preg_match($regex, $ex->getMessage()); - } - - if ($threw && $match) - return true; - - $bt = debug_backtrace(false); - $ex = !$threw ? 'no exception' : "no match '$regex'"; - self::$errors = sprintf("Assertion failed: %s:%d (%s) %s\n", - $bt0"file", $bt0"line", $bt1"function", $ex); - - return false; - } - - protected function assertLess($a, $b) { - if($a < $b) - return; - - $bt = debug_backtrace(false); - self::$errors = sprintf("Assertion failed (%s >= %s): %s: %d (%s\n", - print_r($a, true), print_r($b, true), - $bt0"file", $bt0"line", $bt1"function"); - } - - protected function assertEquals($a, $b) { - if($a === $b) - return; - - $bt = debug_backtrace(false); - self::$errors = sprintf("Assertion failed (%s !== %s): %s:%d (%s)\n", - print_r($a, true), print_r($b, true), - $bt0"file", $bt0"line", $bt1"function");
View file
redis-5.3.7.tgz/redis-5.3.7/tests/getSessionData.php
Deleted
@@ -1,22 +0,0 @@ -<?php -error_reporting(E_ERROR | E_WARNING); - -$redisHost = $argv1; -$saveHandler = $argv2; -$sessionId = $argv3; -$sessionLifetime = $argv4; - -if (empty($redisHost)) { - $redisHost = 'tcp://localhost:6379'; -} - -ini_set('session.save_handler', $saveHandler); -ini_set('session.save_path', $redisHost); -ini_set('session.gc_maxlifetime', $sessionLifetime); - -session_id($sessionId); -if (!session_start()) { - echo "session_start() was nut successful"; -} else { - echo isset($_SESSION'redis_test') ? $_SESSION'redis_test' : 'Key redis_test not found'; -}
View file
redis-5.3.7.tgz/redis-5.3.7/tests/make-cluster.sh
Deleted
@@ -1,225 +0,0 @@ -#!/bin/bash - -# make-cluster.sh -# This is a simple script used to automatically spin up a Redis cluster instance -# simplifying the process of running unit tests. -# -# Usage: -# ./make-cluster.sh start host -# ./make-cluster.sh stop host -# - -BASEDIR=`pwd` -NODEDIR=$BASEDIR/nodes -MAPFILE=$NODEDIR/nodemap - -# Host, nodes, replicas, ports, etc. Change if you want different values -HOST="127.0.0.1" -NOASK=0 -NODES=12 -REPLICAS=3 -START_PORT=7000 -END_PORT=`expr $START_PORT + $NODES` - -# Helper to determine if we have an executable -checkExe() { - if ! hash $1 > /dev/null 2>&1; then - echo "Error: Must have $1 on the path!" - exit 1 - fi -} - -# Run a command and output what we're running -verboseRun() { - echo "Running: $@" - $@ -} - -# Spawn a specific redis instance, cluster enabled -spawnNode() { - # ACL file if we have one - if ! -z "$ACLFILE" ; then - ACLARG="--aclfile $ACLFILE" - fi - - # Attempt to spawn the node - verboseRun redis-server --cluster-enabled yes --dir $NODEDIR --port $PORT \ - --cluster-config-file node-$PORT.conf --daemonize yes --save \'\' \ - --bind $HOST --dbfilename node-$PORT.rdb $ACLARG - - # Abort if we can't spin this instance - if $? -ne 0 ; then - echo "Error: Can't spawn node at port $PORT." - exit 1 - fi -} - -# Spawn nodes from start to end port -spawnNodes() { - for PORT in `seq $START_PORT $END_PORT`; do - # Attempt to spawn the node - spawnNode $PORT - - # Add this host:port to our nodemap so the tests can get seeds - echo "$HOST:$PORT" >> $MAPFILE - done -} - -# Check to see if any nodes are running -checkNodes() { - echo -n "Checking port availability " - - for PORT in `seq $START_PORT $END_PORT`; do - redis-cli -p $PORT ping > /dev/null 2>&1 - if $? -eq 0 ; then - echo "FAIL" - echo "Error: There appears to be an instance running at port $PORT" - exit 1 - fi - done - - echo "OK" -} - -# Create our 'node' directory if it doesn't exist and clean out any previous -# configuration files from a previous run. -cleanConfigInfo() { - verboseRun mkdir -p $NODEDIR - verboseRun rm -f $NODEDIR/* - - if -f "$ACLFILE" ; then - cp $ACLFILE $NODEDIR/$ACLFILE - fi -} - -# Initialize our cluster with redis-trib.rb -initCluster() { - TRIBARGS="" - for PORT in `seq $START_PORT $END_PORT`; do - TRIBARGS="$TRIBARGS $HOST:$PORT" - done - - if ! -z "$USER" ; then - USERARG="--user $USER" - fi - if ! -z "$PASS" ; then - PASSARG="-a $PASS" - fi - - if "$1" -eq "1" ; then - echo yes | redis-cli $USERARG $PASSARG -p $START_PORT --cluster create $TRIBARGS --cluster-replicas $REPLICAS - else - verboseRun redis-cli $USERARG $PASSARG -p $START_PORT --cluster create $TRIBARGS --cluster-replicas $REPLICAS - fi - - if $? -ne 0 ; then - echo "Error: Couldn't create cluster!" - exit 1 - fi -} - -# Attempt to spin up our cluster -startCluster() { - # Make sure none of these nodes are already running - checkNodes - - # Clean out node configuration, etc - cleanConfigInfo - - # Attempt to spawn the nodes - spawnNodes - - # Attempt to initialize the cluster - initCluster $1 -} - -# Shut down nodes in our cluster -stopCluster() { - for PORT in `seq $START_PORT $END_PORT`; do - verboseRun redis-cli -p $PORT SHUTDOWN NOSAVE > /dev/null 2>&1 - done -} - -# Shut down nodes by killing them -killCluster() { - for PORT in `seq $START_PORT $END_PORT`; do - PID=$(ps aux|grep redis-server|grep $PORT|awk '{print $2}') - echo -n "Killing $PID: " - if kill $PID; then - echo "OK" - else - echo "ERROR" - fi - done -} - -printUsage() { - echo "Usage: make-cluster OPTIONS <start|stop|kill>" - echo - echo " Options" - echo - echo " -u Redis username to use when spawning cluster" - echo " -p Redis password to use when spawning cluster" - echo " -a Redis acl filename to use when spawning cluster" - echo " -y Automatically send 'yes' when starting cluster" - echo " -h This message" - echo - exit 0 -} - -# We need redis-server -checkExe redis-server - -while getopts "u:p:a:hy" OPT; do - case $OPT in - h) - printUsage - ;; - a) - if ! -f "$OPTARG" ; then - echo "Error: '$OPTARG' is not a filename!" - exit -1 - fi - ACLFILE=$OPTARG - ;; - u) - USER=$OPTARG - ;; - p) - PASS=$OPTARG - ;; - h) - HOST=$OPTARG - ;; - y) - NOASK=1 - ;; - *) - echo "Unknown option: $OPT" - exit 1
View file
redis-5.3.7.tgz/redis-5.3.7/tests/regenerateSessionId.php
Deleted
@@ -1,84 +0,0 @@ -<?php -error_reporting(E_ERROR | E_WARNING); - -$redisHost = $argv1; -$saveHandler = $argv2; -$sessionId = $argv3; -$locking = !!$argv4; -$destroyPrevious = !!$argv5; -$sessionProxy = !!$argv6; - -if (empty($redisHost)) { - $redisHost = 'tcp://localhost:6379'; -} - -ini_set('session.save_handler', $saveHandler); -ini_set('session.save_path', $redisHost); - -if ($locking) { - ini_set('redis.session.locking_enabled', true); -} - -if (interface_exists('SessionHandlerInterface')) { - class TestHandler implements SessionHandlerInterface - { - /** - * @var SessionHandler - */ - private $handler; - - public function __construct() - { - $this->handler = new SessionHandler(); - } - - public function close() - { - return $this->handler->close(); - } - - public function destroy($session_id) - { - return $this->handler->destroy($session_id); - } - - public function gc($maxlifetime) - { - return $this->handler->gc($maxlifetime); - } - - public function open($save_path, $name) - { - return $this->handler->open($save_path, $name); - } - - public function read($session_id) - { - return $this->handler->read($session_id); - } - - public function write($session_id, $session_data) - { - return $this->handler->write($session_id, $session_data); - } - } -} - -if ($sessionProxy) { - $handler = new TestHandler(); - session_set_save_handler($handler); -} - -session_id($sessionId); -if (!session_start()) { - $result = "FAILED: session_start()"; -} -elseif (!session_regenerate_id($destroyPrevious)) { - $result = "FAILED: session_regenerate_id()"; -} -else { - $result = session_id(); -} -session_write_close(); -echo $result; -
View file
redis-5.3.7.tgz/redis-5.3.7/tests/startSession.php
Deleted
@@ -1,41 +0,0 @@ -<?php -error_reporting(E_ERROR | E_WARNING); - -$redisHost = $argv1; -$saveHandler = $argv2; -$sessionId = $argv3; -$sleepTime = $argv4; -$maxExecutionTime = $argv5; -$lock_retries = $argv6; -$lock_expire = $argv7; -$sessionData = $argv8; -$sessionLifetime = $argv9; - -if (empty($redisHost)) { - $redisHost = 'tcp://localhost:6379'; -} - -ini_set('session.save_handler', $saveHandler); -ini_set('session.save_path', $redisHost); -ini_set('max_execution_time', $maxExecutionTime); -ini_set('redis.session.lock_retries', $lock_retries); -ini_set('redis.session.lock_expire', $lock_expire); -ini_set('session.gc_maxlifetime', $sessionLifetime); - -if (isset($argv10)) { - ini_set('redis.session.locking_enabled', $argv10); -} - -if (isset($argv11)) { - ini_set('redis.session.lock_wait_time', $argv11); -} - -session_id($sessionId); -$sessionStartSuccessful = session_start(); -sleep($sleepTime); -if (!empty($sessionData)) { - $_SESSION'redis_test' = $sessionData; -} -session_write_close(); - -echo $sessionStartSuccessful ? 'SUCCESS' : 'FAILURE';
View file
redis-5.3.7.tgz/package.xml -> redis-6.2.0.tgz/package.xml
Changed
@@ -2,8 +2,9 @@ <package packagerversion="1.10.12" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>redis</name> <channel>pecl.php.net</channel> - <summary>PHP extension for interfacing with Redis</summary> - <description>This extension provides an API for communicating with Redis servers.</description> + <summary>PHP extension for interfacing with key-value stores</summary> + <description>This extension provides an API for communicating with RESP-based key-value + stores, such as Redis, Valkey, and KeyDB.</description> <lead> <name>Michael Grunder</name> <user>mgrunder</user> @@ -16,17 +17,11 @@ <email>p.yatsukhnenko@gmail.com</email> <active>yes</active> </lead> - <lead> - <name>Nicolas Favre-Felix</name> - <user>nff</user> - <email>n.favrefelix@gmail.com</email> - <active>no</active> - </lead> - <date>2022-02-15</date> - <time>18:25:22</time> + <date>2025-03-24</date> + <time>19:00:47</time> <version> - <release>5.3.7</release> - <api>5.3.7</api> + <release>6.2.0</release> + <api>6.2.0</api> </version> <stability> <release>stable</release> @@ -36,32 +31,73 @@ <notes> --- Sponsors --- +A-VISION Advisering - https://a-vision.nu/ Audiomack - https://audiomack.com -Open LMS - https://openlms.net -BlueHost - https://bluehost.com -Object Cache Pro for WordPress - https://objectcache.pro Avtandil Kikabidze - https://github.com/akalongman -Zaher Ghaibeh - https://github.com/zaherg -BatchLabs - https://batch.com -Luis Zarate - https://github.com/jlzaratec - -phpredis 5.3.7 - -- There were no changes between 5.3.7 and 5.3.7RC2. - ---- - -phpredis 5.3.7RC2 +Geoffrey Hoffman - https://github.com/phpguru +Object Cache Pro for WordPress - https://objectcache.pro +Open LMS - https://openlms.net +Salvatore Sanfilippo - https://github.com/antirez +Ty Karok - https://github.com/karock +Vanessa Santana - https://github.com/vanessa-dev -- There were no changes between 5.3.7RC2 and 5.3.7RC1. +* A special thanks to Jakub Onderka for nearly two dozen performance improvements in this release! ---- +--- 6.2.0 --- -phpredis 5.3.7RC1 +Fixed: +* Fix arguments order for SET command f73f5fc (Pavlo Yatsukhnenko) +* Fix error length calculation and UB sanity check e73130fe (michael-grunder) +* Invalidate slot cache on failed cluster connections c7b87843 (James Kennedy) +* Don't cast a uint64_t to a long faa4bc20 (michael-grunder) +* Fix potential NULL dereference 43e6cab8 (peter15914) +* Print cursor as unsigned 64 bit integer 138d07b6 (Bentley O'Kane-Chase) +* Fix XAUTOCLAIM argc when sending COUNT 0fe45d24 (michael-grunder) -- Fix RedisArray::hszscan and tests 08a9d5db, 0264de18 (Pavlo Yatsukhnenko, Michael Grunder) -- Fix RedisArray::scan 8689ab1c (Pavlo Yatsukhnenko) -- Fix LZF decompression logic 0719c1ec (Michael Grunder) +Added: +* Added `serverName()` and `serverVersion()` fa3eb006, cbaf095f, 056c2dbe + (Pavlo Yatsukhnenko, Michael Grunder) +* Added getWithMeta method 9036ffca, 36ab5850 (Pavlo Yatsukhnenko) +* Implement GETDEL command for RedisCluster d342e4ac (michael-grunder) +* Introduce Redis::OPT_PACK_IGNORE_NUMBERS option f9ce9429, 29e5cf0d (michael-grunder) +* Implement Valkey >= 8.1 IFEQ SET option a2eef77f (michael-grunder) +* Implement KeyDB's EXPIREMEMBERAT commands 4cd3f593 (michael-grunder) + +Documentation: +* Fix phpdoc type of $pattern 5cad2076 (OHZEKI Naoki) +* Better documentation for the $tlsOptions parameter of RedisCluster 8144db37 (Jacob Brown) + +Tests/CI: +* Add details to the option doc block abb0f6cc (michael-grunder) +* Update CodeQL to v3 41e11417, a10bca35 (Pavlo Yatsukhnenko) +* Add PHP 8.4 to CI 6097e7ba (Pavlo Yatsukhnenko) +* Pin ubuntu version for KeyDB eb66fc9e, 985b0313 (michael-grunder) +* Windows CI: update setup-php-sdk to v0.10 and enable caching f89d4d8f (Christoph M. Becker) + +Internal: +* Reduce buffer size for signed integer 044b3038, 35c59880 (Bentley O'Kane-Chase) +* Create a strncmp wrapper 085d61ec (michael-grunder) +* Refactor and avoid allocation in rawcommand method f68544f7 (Jakub Onderka) +* Use defines for callback growth + sanity check 42a42769 (michael-grunder) +* Switch from linked list to growing array for reply callbacks a551fdc9 (Jakub Onderka) +* Reuse redis_sock_append_auth method be388562 (Jakub Onderka) +* Switch pipeline_cmd from smart_str to smart_string 571ffbc8 (Jakub Onderka) +* Remove unused redis_debug_response method from library.c 7895636a (Jakub Onderka) +* Optimise HMGET method 2434ba29 (Jakub Onderka) +* Avoid unnecessary allocation in redis_hset_cmd aba09933 (Jakub Onderka) +* Avoid unnecessary allocation in redis_hdel_cmd 4082dd07 (Jakub Onderka) +* Avoid unnecessary allocation in redis_key_varval_cmd 99650e15 (Jakub Onderka) +* Use zval_get_tmp_string method that is faster when provided zval is string f6906470 (Jakub Onderka) +* Optimise constructing Redis command string 2a2f908f (Jakub Onderka) +* If no command is issued in multi mode, return immutable empty array 5156e032 (Jakub Onderka) +* Test for empty pipeline and multi 426de2bb (Jakub Onderka) +* Optimise method array_zip_values_and_scores 400503b8 (Jakub Onderka) +* Faster parameter parsing in redis_key_cmd and redis_key_long_val_cmd 83a19656 (Jakub Onderka) +* Use immutable empty array in Redis::hKeys 3a2f3f45 (Jakub Onderka) +* Use immutable empty array in Redis::exec 60b5a886 (Jakub Onderka) +* Do not allocate empty string or string with one character 64da891e (Jakub Onderka) +* Initialize arrays with known size 99beb922 (Jakub Onderka) +* Use smart str for constructing pipeline cmd b665925e (Jakub Onderka) </notes> <contents> <dir name="/"> @@ -71,56 +107,69 @@ <file md5sum="91a34efea468bc5c6796275f30b12c4b" name="liblzf/lzfP.h" role="src" /> <file md5sum="f56a91842e1a56820efe3f35fcfa486e" name="liblzf/lzf_c.c" role="src" /> <file md5sum="ef8f82dbd4bad7b83629c02724afcfd0" name="liblzf/lzf_d.c" role="src" /> - <file md5sum="60ec28e724fe71b6f4f9c64f39d6c454" name="tests/RedisArrayTest.php" role="test" /> - <file md5sum="c0c75574945110e43500740330c5ca64" name="tests/RedisClusterTest.php" role="test" /> - <file md5sum="c3456487adf190624600fc8c2b52a06f" name="tests/RedisSentinelTest.php" role="test" /> - <file md5sum="d463bb6f338399611fb590789cf3891f" name="tests/RedisTest.php" role="test" /> - <file md5sum="11be96db34a61ad8c6cd0851736a6085" name="tests/TestRedis.php" role="test" /> - <file md5sum="5314211ae095d0090a8beeb0eb1e1aa7" name="tests/TestSuite.php" role="test" /> - <file md5sum="54008d9b652609b7f8761347633768b9" name="tests/getSessionData.php" role="test" /> - <file md5sum="41d74e22d416b8f211e9faa54c91f028" name="tests/regenerateSessionId.php" role="test" /> - <file md5sum="a6405025d1b66c45b72f2c770e791ca2" name="tests/startSession.php" role="test" /> - <file md5sum="68bbc32df6f9ac6952c1929a9a65d984" name="tests/make-cluster.sh" role="test" /> + <file md5sum="429188b3d5c91f528dcca6e4e1653840" name="tests/RedisArrayTest.php" role="test" /> + <file md5sum="868fbc592f577551ea1dd8e10157ac80" name="tests/RedisClusterTest.php" role="test" /> + <file md5sum="94a8cf559d1a40ddc96fb55effb372ee" name="tests/RedisSentinelTest.php" role="test" /> + <file md5sum="24386d59ec0d05bd4bfe990c485ff377" name="tests/RedisTest.php" role="test" /> + <file md5sum="94d564eb6d04723a987854e187a9c8d4" name="tests/TestRedis.php" role="test" /> + <file md5sum="5edc87828956490295b145d29ae8ffc9" name="tests/TestSuite.php" role="test" /> + <file md5sum="f8ba6ee263cf5cdbfe9242513302f24c" name="tests/getSessionData.php" role="test" /> + <file md5sum="e2c0e0b4e6b027cee1a444abffa0601e" name="tests/regenerateSessionId.php" role="test" /> + <file md5sum="2272f4aa4f2febe66a34661464bffc57" name="tests/startSession.php" role="test" /> + <file md5sum="202035ead99dca010e110f9cca79d9c7" name="tests/SessionHelpers.php" role="test" /> + <file md5sum="654496adb29b43100f4a98c8c4127d4e" name="tests/make-cluster.sh" role="test" /> <file md5sum="e9ddcb5f7abcef8507c394d8386f4742" name="tests/mkring.sh" role="test" /> - <file md5sum="cb564efdf78cce8ea6e4b5a4f7c05d97" name="COPYING" role="doc" /> + <file md5sum="cb564efdf78cce8ea6e4b5a4f7c05d97" name="LICENSE" role="doc" /> <file md5sum="d56374bf738d2b10cb1f97cd7c9cfb30" name="CREDITS" role="doc" /> - <file md5sum="98cd5fe0bccf280ce97fefe9e23234f3" name="README.markdown" role="doc" /> - <file md5sum="1535ddd7af4b8ae0e62b97493b3fbeff" name="INSTALL.markdown" role="src" /> - <file md5sum="89d0886085e6a4bcc43ef77948620814" name="arrays.markdown" role="doc" /> - <file md5sum="2c013c82644ae9d40ac4458b2a4aee95" name="cluster.markdown" role="doc" /> - <file md5sum="78c066824f52a49e782c34c2ae551485" name="sentinel.markdown" role="doc" /> - <file md5sum="28ea560988dab4adb4dae32597659d57" name="backoff.c" role="src" /> + <file md5sum="b363573ea0afeea20c55fc81a2fda803" name="README.md" role="doc" /> + <file md5sum="31492dbbf5b3a49cb95c7a304efd2313" name="INSTALL.md" role="src" /> + <file md5sum="12ce8871013788f5b3abc69691fb5a7d" name="arrays.md" role="doc" /> + <file md5sum="072c67a36ff418d3c963c99f767b2203" name="cluster.md" role="doc" /> + <file md5sum="ce0ab3a589e5a034beebced11be601d7" name="sentinel.md" role="doc" /> + <file md5sum="13936f0c8e8d3860fa45f941333ae8aa" name="backoff.c" role="src" /> <file md5sum="af0b29580d83ba055ff816664d7f3d83" name="backoff.h" role="src" /> - <file md5sum="bb06eae679cd075aac1215ad45eb08bb" name="cluster_library.c" role="src" /> - <file md5sum="824c8be057184c70c2b97b50a5963730" name="cluster_library.h" role="src" /> - <file md5sum="d4ac901bacae610806f0ee7d8440e80d" name="common.h" role="src" /> - <file md5sum="029358b0c7c77d845ae42552e5d2027e" name="config.m4" role="src" /> + <file md5sum="654787f8d0e51798e19bb55e59eb42b6" name="cluster_library.c" role="src" /> + <file md5sum="c6e5011da50c08e6aa95fa10de1bd9d6" name="cluster_library.h" role="src" /> + <file md5sum="ebf2923eecfdf7e4b025d63310f4e387" name="common.h" role="src" /> + <file md5sum="9b37d3cd4dc9cd9369322b69766b7165" name="config.m4" role="src" /> <file md5sum="c962cae928bcb4986ebb17bf9d5a3811" name="config.w32" role="src" /> <file md5sum="b21982c70ca8292b4ac540a76cd3bac4" name="crc16.h" role="src" /> - <file md5sum="578a54daaa079a4181249f32e0bd421f" name="library.c" role="src" /> - <file md5sum="5118699f5602316481e994a13b58e84a" name="library.h" role="src" /> - <file md5sum="83b994c10ad6b284b2b7b37b6defd8b9" name="php_redis.h" role="src" /> - <file md5sum="bb99ffba98455abaecd7d89ab3a9481e" name="redis.c" role="src" /> - <file md5sum="e399e0167c50641438f19c9e636a6a3e" name="redis_array.c" role="src" /> - <file md5sum="f4a55424ef6e0429708924926b26781e" name="redis_array.h" role="src" /> - <file md5sum="4482ba14faf00690e930a507bb034d23" name="redis_array_impl.c" role="src" /> + <file md5sum="31f122a8d9794844c96ae48783bfe741" name="library.c" role="src" /> + <file md5sum="7d6885acc7d9247309dbfbb67b919dbd" name="library.h" role="src" /> + <file md5sum="4f7eec17b48b2cf39f1770657fb8f0f8" name="php_redis.h" role="src" /> + <file md5sum="40d48396b7e33a63c16332b37115470c" name="redis.c" role="src" /> + <file md5sum="4f0ff1839c329172e4035d3702ee3357" name="redis.stub.php" role="src" /> + <file md5sum="8086e5f124074bcad4dc0a456d0cbcbc" name="redis_arginfo.h" role="src" /> + <file md5sum="a4ac9a3186c156669e502740f8933800" name="redis_legacy_arginfo.h" role="src" /> + <file md5sum="45dc2c335c3fbd274d0567d77e509082" name="redis_array.c" role="src" /> + <file md5sum="6bccb2758b3625ccdc183a8a9ee4e4c4" name="redis_array.h" role="src" /> + <file md5sum="d6b4544e2563087cd81a8e9ad747535e" name="redis_array.stub.php" role="src" /> + <file md5sum="14520411b0ef3f66db4c00a309714f39" name="redis_array_arginfo.h" role="src" /> + <file md5sum="4b29ca76bb3efe98e333ef899f99ccc4" name="redis_array_legacy_arginfo.h" role="src" /> + <file md5sum="a6379f4be513741492ca9e216b300ac0" name="redis_array_impl.c" role="src" />
View file
redis-6.2.0.tgz/redis-6.2.0/CREDITS
Changed
(renamed from redis-5.3.7/CREDITS)
View file
redis-6.2.0.tgz/redis-6.2.0/INSTALL.md
Added
@@ -0,0 +1,94 @@ +# Installation from pecl + +To pull latest stable released version, from pecl(https://pecl.php.net/package/redis) + +~~~ +pecl install redis +~~~ + +# Installation from sources + +To build this extension for the sources tree: + +~~~ +git clone https://github.com/phpredis/phpredis.git +cd phpredis +phpize +./configure --enable-redis-igbinary --enable-redis-msgpack --enable-redis-lzf --with-liblzf=DIR --enable-redis-zstd --enable-redis-lz4 +make && make install +~~~ + +If you would like phpredis to serialize your data using the igbinary library, run configure with `--enable-redis-igbinary`. +If you would like to use the msgpack serializer, run configure with `--enable-redis-msgpack` (note: Requires php-msgpack >= 2.0.3) +The extension also may compress data before sending it to Redis server, if you run configure with `--enable-redis-lzf`. If you want to use lzf library pre-installed into your system use `--with-liblzf` configuration option to specify the path where to search files. +`make install` copies `redis.so` to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in `/etc/php5/conf.d` with the following contents: `extension=redis.so`. + +You can generate a debian package for PHP5, accessible from Apache 2 by running `./mkdeb-apache2.sh` or with `dpkg-buildpackage` or `svn-buildpackage`. + +This extension exports a single class, Redis(./README.md#class-redis) (and RedisException(./README.md#class-redisexception) used in case of errors). Check out https://github.com/ukko/phpredis-phpdoc for a PHP stub that you can use in your IDE for code completion. + + +# Binary packages + +Most distributions provides pre-build binary packages of this extension. + +## Windows: + +Follow the DLL link on the https://pecl.php.net/package/redis(https://pecl.php.net/package/redis) page or use https://windows.php.net/downloads/pecl/releases/redis/(https://windows.php.net/downloads/pecl/releases/redis/) + +## Fedora + +Fedora users can install the package from the official repository. + +### Fedora ≥ 29, Version 5 + +Installation of the php-pecl-redis5(https://packages.fedoraproject.org/pkgs/php-pecl-redis5/php-pecl-redis5/) package: + +~~~ +dnf install php-pecl-redis5 +~~~ + +## RHEL / CentOS + +Installation of the php-pecl-redis(https://apps.fedoraproject.org/packages/php-pecl-redis) package, from the EPEL repository(https://fedoraproject.org/wiki/EPEL): + +~~~ +yum install php-pecl-redis +~~~ + +### openSUSE ≥ 15.1 + +Installation of the php7-redis(https://software.opensuse.org/package/php7-redis?search_term=php7-redis) package: + +~~~ +zypper in php7-redis +~~~ + + +# Installation on OSX + +If the install fails on OSX, type the following commands in your shell before trying again: +~~~ +MACOSX_DEPLOYMENT_TARGET=10.6 +CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" +CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" +CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" +LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" +export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET +~~~ + +If that still fails and you are running Zend Server CE, try this right before "make": `./configure CFLAGS="-arch i386"`. + +Taken from Compiling phpredis on Zend Server CE/OSX (http://www.tumblr.com/tagged/phpredis). + +See also: Install Redis & PHP Extension PHPRedis with Macports(http://www.lecloud.net/post/3378834922/install-redis-php-extension-phpredis-with-macports). + +You can install it using MacPorts: + +- Get macports-php(https://www.macports.org/) +- `sudo port install php56-redis` (or php53-redis, php54-redis, php55-redis, php70-redis, php71-redis, php72-redis, php73-redis, php74-redis) + +# Building on Windows + +See instructions from @char101(https://github.com/phpredis/phpredis/issues/213#issuecomment-11361242) on how to build phpredis on Windows. +
View file
redis-6.2.0.tgz/redis-6.2.0/LICENSE
Changed
(renamed from redis-5.3.7/COPYING)
View file
redis-6.2.0.tgz/redis-6.2.0/README.md
Added
@@ -0,0 +1,4570 @@ +# PhpRedis + +!Build Status(https://github.com/phpredis/phpredis/actions/workflows/ci.yml/badge.svg)(https://github.com/phpredis/phpredis/actions/workflows/ci.yml) +!Coverity Scan Build Status(https://scan.coverity.com/projects/13205/badge.svg)(https://scan.coverity.com/projects/phpredis-phpredis) +!PHP version(https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg)(https://github.com/phpredis/phpredis) + +The phpredis extension provides an API for communicating with the Redis(http://redis.io/) key-value store. It also supports KeyDB(https://docs.keydb.dev/) and Valkey(https://valkey.io/), which are open source alternatives to Redis. + +It is released under the PHP License, version 3.01(http://www.php.net/license/3_01.txt). + +You can send comments, patches, questions here on github(https://github.com/phpredis/phpredis/issues), to michael.grunder@gmail.com (Twitter(https://twitter.com/grumi78), <a rel="me" href="https://phpc.social/@mgrunder">Mastodon</a>), p.yatsukhnenko@gmail.com (@yatsukhnenko(https://twitter.com/yatsukhnenko)), or n.favrefelix@gmail.com (@yowgi(https://twitter.com/yowgi)). + + +## API Documentation(https://phpredis.github.io/phpredis) +These are a work in progress, but will eventually replace our **ONE README TO RULE THEM ALL** docs. + +## Supporting the project +PhpRedis will always be free and open source software, but if you or your company has found it useful please consider supporting the project. Developing a large, complex, and performant library like PhpRedis takes a great deal of time and effort, and support would be appreciated! :heart: + +The best way to support the project is through GitHub sponsors(https://github.com/sponsors/michael-grunder). Many of the reward tiers grant access to our slack channel(https://phpredis.slack.com) where myself(https://github.com/michael-grunder) and Pavlo(https://github.com/yatsukhnenko) are regularly available to answer questions. Additionally this will allow you to provide feedback on which fixes and new features to prioritize. + +You can also make a one-time contribution with !PayPal(https://img.shields.io/badge/Donate-PayPal-green.svg)(https://www.paypal.me/michaelgrunder/5) + +## Sponsors +<a href="https://audiomack.com"><img src="https://styleguide.audiomack.com/assets/dl/inline-orange-large.png" align="center" alt="Audiomack.com" width="150"></a> +<a href="https://bluehost.com"><img src="https://upload.wikimedia.org/wikipedia/commons/2/22/Bluehost-logo.png" align="center" alt="Bluehost.com" width="150"></a> +<a href="https://objectcache.pro"><img src="https://objectcache.pro/assets/wordmark-padded.png" align="center" alt="Object Cache Pro" width="150"></a> +<a href="https://openlms.net"><img src="https://help.openlms.net/wp-content/uploads/2020/05/cropped-open-lms.png" align="center" alt="OpenLMS.net" width="150"></a> + +# Table of contents +----- +1. Installing/Configuring(#installingconfiguring) + * Installation(#installation) + * PHP Session handler(#php-session-handler) + * Distributed Redis Array(./arrays.md#readme) + * Redis Cluster support(./cluster.md#readme) + * Redis Sentinel support(./sentinel.md#readme) + * Running the unit tests(#running-the-unit-tests) +1. Classes and methods(#classes-and-methods) + * Usage(#usage) + * Connection(#connection) + * Retry and backoff(#retry-and-backoff) + * Server(#server) + * Keys and strings(#keys-and-strings) + * Hashes(#hashes) + * Lists(#lists) + * Sets(#sets) + * Sorted sets(#sorted-sets) + * HyperLogLogs(#hyperloglogs) + * Geocoding(#geocoding) + * Streams(#streams) + * Pub/sub(#pubsub) + * Transactions(#transactions) + * Scripting(#scripting) + * Introspection(#introspection) + +----- + +# Installing/Configuring +----- + +## Installation + +For everything you should need to install PhpRedis on your system, +see the INSTALL.md(./INSTALL.md) page. + +## PHP Session handler + +phpredis can be used to store PHP sessions. To do this, configure `session.save_handler` and `session.save_path` in your php.ini to tell phpredis where to store the sessions. + +`session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the parameters. The following parameters are available: + +* weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, *host1* stores 20% of all the sessions (1/(1+2+2)) while *host2* and *host3* each store 40% (2/(1+2+2)). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1. +* timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds). +* persistent (integer, should be 1 or 0): defines if a persistent connection should be used. +* prefix (string, defaults to "PHPREDIS_SESSION:"): used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID. +* auth (string, or an array with one or two elements): used to authenticate with the server prior to sending commands. +* database (integer): selects a different database. + +Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with `ini_set()`(http://php.net/ini_set). +The session handler requires a version of Redis supporting `EX` and `NX` options of `SET` command (at least 2.6.12). +phpredis can also connect to a unix domain socket: `session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0"`. + +### Examples + +Multiple Redis servers: +~~~ +session.save_handler = redis +session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5" +~~~ + +Login to Redis using username and password: +~~~ +session.save_handler = redis +session.save_path = "tcp://127.0.0.1:6379?auth=user&auth=password" +~~~ + +Login to Redis using username, password, and set prefix: +~~~ +session.save_handler = redis +session.save_path = "tcp://127.0.0.1:6379?auth=user&auth=password&prefix=user_PHPREDIS_SESSION:" +~~~ + +### Session locking + +**Support**: Locking feature is currently only supported for Redis setup with single master instance (e.g. classic master/slave Sentinel environment). +So locking may not work properly in RedisArray or RedisCluster environments. + +Following INI variables can be used to configure session locking: +~~~ +; Should the locking be enabled? Defaults to: 0. +redis.session.locking_enabled = 1 +; How long should the lock live (in seconds)? Defaults to: value of max_execution_time. +redis.session.lock_expire = 60 +; How long to wait between attempts to acquire lock, in microseconds (µs)?. Defaults to: 20000 +redis.session.lock_wait_time = 50000 +; Maximum number of times to retry (-1 means infinite). Defaults to: 100 +redis.session.lock_retries = 2000 +~~~ + +### Session compression + +Following INI variables can be used to configure session compression: +~~~ +; Should session compression be enabled? Possible values are zstd, lzf, lz4, none. Defaults to: none +redis.session.compression = zstd +; What compression level should be used? Compression level depends on used library. For most deployments range 1-9 should be fine. Defaults to: 3 +redis.session.compression_level = 3 +~~~ + +## Running the unit tests + +phpredis uses a small custom unit test suite for testing functionality of the various classes. To run tests, simply do the following: + +~~~ +# Run tests for Redis class (note this is the default) +php tests/TestRedis.php --class Redis + +# Run tests for RedisArray class +tests/mkring.sh start +php tests/TestRedis.php --class RedisArray +tests/mkring.sh stop + +# Run tests for the RedisCluster class +tests/make-cluster.sh start +php tests/TestRedis.php --class RedisCluster +tests/make-cluster.sh stop + +# Run tests for RedisSentinel class +php tests/TestRedis.php --class RedisSentinel +~~~ + +Note that it is possible to run only tests which match a substring of the test itself by passing the additional argument '--test <str>' when invoking. + +~~~ +# Just run the 'echo' test +php tests/TestRedis.php --class Redis --test echo +~~~ + +# Classes and methods +----- + +## Usage + +1. Class Redis(#class-redis) +1. Class RedisException(#class-redisexception) +1. Predefined constants(#predefined-constants) + +### Class Redis +----- +_**Description**_: Creates a Redis client + +##### *Example* + +~~~php +$redis = new Redis(); +~~~ + +Starting from version 6.0.0 it's possible to specify configuration options. +This allows to connect lazily to the server without explicitly invoking `connect` command. + +##### *Example* + +~~~php +$redis = new Redis( + 'host' => '127.0.0.1', + 'port' => 6379, + 'connectTimeout' => 2.5, + 'auth' => 'phpredis', 'phpredis', + 'ssl' => 'verify_peer' => false, + 'backoff' => + 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, + 'base' => 500, + 'cap' => 750, + , +); +~~~ + +##### *Parameters*
View file
redis-6.2.0.tgz/redis-6.2.0/arrays.md
Added
@@ -0,0 +1,185 @@ +Redis Arrays +============ + +A Redis array is an isolated namespace in which keys are related in some manner. Keys are distributed across a number of Redis instances, using consistent hashing. A hash function is used to spread the keys across the array in order to keep a uniform distribution. **This feature was added as the result of a generous sponsorship by A+E Networks(http://www.aetn.com/).** + +An array is composed of the following: + +* A list of Redis hosts. +* A key extraction function, used to hash part of the key in order to distribute related keys on the same node (optional). This is set by the "function" option. +* A list of nodes previously in the ring, only present after a node has been added or removed. When a read command is sent to the array (e.g. GET, LRANGE...), the key is first queryied in the main ring, and then in the secondary ring if it was not found in the main one. Optionally, the keys can be migrated automatically when this happens. Write commands will always go to the main ring. This is set by the "previous" option. +* An optional index in the form of a Redis set per node, used to migrate keys when nodes are added or removed; set by the "index" option. +* An option to rehash the array automatically as nodes are added or removed, set by the "autorehash" option. + +## Creating an array + +There are several ways of creating Redis arrays; they can be pre-defined in redis.ini using `new RedisArray(string $name);`, or created dynamically using `new RedisArray(array $hosts, array $options);` + +#### Declaring a new array with a list of nodes +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380")); +</pre> + + +#### Declaring a new array with a list of nodes and a function to extract a part of the key +<pre> +function extract_key_part($k) { + return substr($k, 0, 3); // hash only on first 3 characters. +} +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("function" => "extract_key_part")); +</pre> + +#### Defining a "previous" array when nodes are added or removed. +When a new node is added to an array, phpredis needs to know about it. The old list of nodes becomes the “previous” array, and the new list of nodes is used as a main ring. Right after a node has been added, some read commands will point to the wrong nodes and will need to look up the keys in the previous ring. + +<pre> +// adding host3 to a ring containing host1 and host2. Read commands will look in the previous ring if the data is not found in the main ring. +$ra = new RedisArray(array("host1", "host2", "host3"), array("previous" => array("host1", "host2"))); +</pre> + +#### Specifying the "retry_interval" parameter +The retry_interval is used to specify a delay in milliseconds between reconnection attempts in case the client loses connection with a server +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("retry_interval" => 100)); +</pre> + +#### Specifying the "lazy_connect" parameter +This option is useful when a cluster has many shards but not of them are necessarily used at one time. +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("lazy_connect" => true)); +</pre> + +#### Specifying the "connect_timeout" parameter +The connect_timeout value is a double and is used to specify a timeout in number of seconds when creating redis socket connections used in the RedisArray. +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("connect_timeout" => 0.5)); +</pre> + +#### Specifying the "read_timeout" parameter +The read_timeout value is a double and is used to specify a timeout in number of seconds when waiting response from the server. +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("read_timeout" => 0.5)); +</pre> + +#### Specifying the "algorithm" parameter +The algorithm value is a string and is used to specify the name of key hashing algorithm. The list of possible values may be found using PHP function `hash_algos`. +If algorithm is not supported by PHP `hash` function default algorithm will be used (CRC32 with 0xffffffff initial value). +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("algorithm" => "md5")); +</pre> + +#### Specifying the "consistent" parameter +The value is boolean. When enabled RedisArray uses "ketama" distribution algorithm (currently without ability to set weight to each server). +This option applies to main and previous ring if specified. +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("consistent" => true)); +</pre> + +#### Specifying the "auth" parameter +The value is string and used to specify the password for authenticate with the server prior to sending commands +<pre> +$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("auth" => "mysecretpassword")); +</pre> + +#### Defining arrays in Redis.ini + +Because php.ini parameters must be pre-defined, Redis Arrays must all share the same .ini settings. + +<pre> +// list available Redis Arrays +ini_set('redis.array.names', 'users,friends'); + +// set host names for each array. +ini_set('redis.arrays.hosts', 'users=localhost:6379&users=localhost:6380&users=localhost:6381&users=localhost:6382&friends=localhost'); + +// set functions +ini_set('redis.arrays.functions', 'users=user_hash'); + +// use index only for users +ini_set('redis.arrays.index', 'users=1,friends=0'); + +// use password for authentication +ini_set('redis.arrays.auth', 'users=mysecretpassword') +</pre> + +## Usage + +Redis arrays can be used just as Redis objects: +<pre> +$ra = new RedisArray("users"); +$ra->set("user1:name", "Joe"); +$ra->set("user2:name", "Mike"); +</pre> + + +## Key hashing +By default and in order to be compatible with other libraries, phpredis will try to find a substring enclosed in curly braces within the key name, and use it to distribute the data. + +For instance, the keys “{user:1}:name” and “{user:1}:email” will be stored on the same server as only “user:1” will be hashed. You can provide a custom function name in your redis array with the "function" option; this function will be called every time a key needs to be hashed. It should take a string and return a string. + + +## Custom key distribution function +In order to control the distribution of keys by hand, you can provide a custom function or closure that returns the server number, which is the index in the array of servers that you created the RedisArray object with. + +For instance, instantiate a RedisArray object with `new RedisArray("us-host", "uk-host", "de-host", "distributor" => "dist");` and write a function called "dist" that will return `2` for all the keys that should end up on the "de-host" server. + +### Example +<pre> +$ra = new RedisArray(array("host1", "host2", "host3", "host4", "host5", "host6", "host7", "host8"), array("distributor" => array(2, 2))); +</pre> + +This declares that we started with 2 shards and moved to 4 then 8 shards. The number of initial shards is 2 and the resharding level (or number of iterations) is 2. + +## Migrating keys + +When a node is added or removed from a ring, RedisArray instances must be instantiated with a “previous” list of nodes. A single call to `$ra->_rehash()` causes all the keys to be redistributed according to the new list of nodes. Passing a callback function to `_rehash()` makes it possible to track the progress of that operation: the function is called with a node name and a number of keys that will be examined, e.g. `_rehash(function ($host, $count){ ... });`. + +It is possible to automate this process, by setting `'autorehash' => TRUE` in the constructor options. This will cause keys to be migrated when they need to be read from the previous array. + +In order to migrate keys, they must all be examined and rehashed. If the "index" option was set, a single key per node lists all keys present there. Otherwise, the `KEYS` command is used to list them. +If a “previous” list of servers is provided, it will be used as a backup ring when keys can not be found in the current ring. Writes will always go to the new ring, whilst reads will go to the new ring first, and to the second ring as a backup. + +Adding and/or removing several instances is supported. + +### Example +<pre> +$ra = new RedisArray("users"); // load up a new config from redis.ini, using the “.previous” listing. +$ra->_rehash(); +</pre> + +Running this code will: + +* Create a new ring with the updated list of nodes. +* Server by server, look up all the keys in the previous list of nodes. +* Rehash each key and possibly move it to another server. +* Update the array object with the new list of nodes. + +## Multi/exec +Multi/exec is still available, but must be run on a single node: +<pre> +$host = $ra->_target("{users}:user1:name"); // find host first +$ra->multi($host) // then run transaction on that host. + ->del("{users}:user1:name") + ->srem("{users}:index", "user1") + ->exec(); +</pre> + +## Limitations +Key arrays offer no guarantee when using Redis commands that span multiple keys. Except for the use of MGET, MSET, and DEL, a single connection will be used and all the keys read or written there. Running KEYS() on a RedisArray object will execute the command on each node and return an associative array of keys, indexed by host name. + +## Array info +RedisArray objects provide several methods to help understand the state of the cluster. These methods start with an underscore. + +* `$ra->_hosts()` → returns a list of hosts for the selected array. +* `$ra->_function()` → returns the name of the function used to extract key parts during consistent hashing. +* `$ra->_target($key)` → returns the host to be used for a certain key. +* `$ra->_instance($host)` → returns a redis instance connected to a specific node; use with `_target` to get a single Redis object. +* `$ra->_continuum()` → returns a list of points on continuum; may be useful with custom distributor function. + +## Running the unit tests +<pre> +$ cd tests +$ ./mkring.sh start +$ php array-tests.php +</pre> +
View file
redis-6.2.0.tgz/redis-6.2.0/backoff.c
Added
@@ -0,0 +1,84 @@ +#include "common.h" + +#if PHP_VERSION_ID < 80400 +#include <ext/standard/php_rand.h> +#else +#include <ext/random/php_random.h> +#endif + +#include "backoff.h" + +static zend_ulong random_range(zend_ulong min, zend_ulong max) { + if (max < min) { + return php_mt_rand_range(max, min); + } + + return php_mt_rand_range(min, max); +} + +static zend_ulong redis_default_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong backoff = retry_index ? self->base : random_range(0, self->base); + return MIN(self->cap, backoff); +} + +static zend_ulong redis_constant_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong backoff = self->base; + return MIN(self->cap, backoff); +} + +static zend_ulong redis_uniform_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong backoff = random_range(0, self->base); + return MIN(self->cap, backoff); +} + +static zend_ulong redis_exponential_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong pow = MIN(retry_index, 10); + zend_ulong backoff = self->base * (1 << pow); + return MIN(self->cap, backoff); +} + +static zend_ulong redis_full_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong pow = MIN(retry_index, 10); + zend_ulong backoff = self->base * (1 << pow); + zend_ulong cap = MIN(self->cap, backoff); + return random_range(0, cap); +} + +static zend_ulong redis_equal_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { + zend_ulong pow = MIN(retry_index, 10); + zend_ulong backoff = self->base * (1 << pow); + zend_ulong temp = MIN(self->cap, backoff); + return temp / 2 + random_range(0, temp) / 2; +} + +static zend_ulong redis_decorrelated_jitter_backoff(struct RedisBackoff *self, unsigned int retry_index) { + self->previous_backoff = random_range(self->base, self->previous_backoff * 3); + return MIN(self->cap, self->previous_backoff); +} + +typedef zend_ulong (*redis_backoff_algorithm)(struct RedisBackoff *self, unsigned int retry_index); + +static redis_backoff_algorithm redis_backoff_algorithmsREDIS_BACKOFF_ALGORITHMS = { + redis_default_backoff, + redis_decorrelated_jitter_backoff, + redis_full_jitter_backoff, + redis_equal_jitter_backoff, + redis_exponential_backoff, + redis_uniform_backoff, + redis_constant_backoff, +}; + +void redis_initialize_backoff(struct RedisBackoff *self, unsigned long retry_interval) { + self->algorithm = 0; // default backoff + self->base = retry_interval; + self->cap = retry_interval; + self->previous_backoff = 0; +} + +void redis_backoff_reset(struct RedisBackoff *self) { + self->previous_backoff = 0; +} + +zend_ulong redis_backoff_compute(struct RedisBackoff *self, unsigned int retry_index) { + return redis_backoff_algorithmsself->algorithm(self, retry_index); +}
View file
redis-6.2.0.tgz/redis-6.2.0/backoff.h
Changed
(renamed from redis-5.3.7/backoff.h)
View file
redis-6.2.0.tgz/redis-6.2.0/cluster.md
Added
@@ -0,0 +1,220 @@ +Redis Cluster +============= + +Redis introduces cluster support as of version 3.0.0, and to communicate with a cluster using phpredis one needs to use the RedisCluster class. For the majority of operations the RedisCluster class can act as a drop-in replacement for the Redis class without needing to modify how it's called. **This feature was added as the result of a generous sponsorship by Tradesy(https://www.tradesy.com/)** + +## Creating and connecting to a cluster + +To maintain consistency with the RedisArray class, one can create and connect to a cluster either by passing it one or more 'seed' nodes, or by defining these in redis.ini as a 'named' cluster. + +#### Declaring a cluster with an array of seeds +```php +// Create a cluster setting three nodes as seeds +$obj_cluster = new RedisCluster(NULL, 'host:7000', 'host:7001', 'host:7003'); + +// Connect and specify timeout and read_timeout +$obj_cluster = new RedisCluster(NULL, "host:7000", "host:7001", 1.5, 1.5); + +// Connect with read/write timeout as well as specify that phpredis should use +// persistent connections to each node. +$obj_cluster = new RedisCluster(NULL, "host:7000", "host:7001", 1.5, 1.5, true); + +// Connect with cluster using password. +$obj_cluster = new RedisCluster(NULL, "host:7000", "host:7001", 1.5, 1.5, true, "password"); + +// Connect with cluster using TLS +// last argument is an optional array with SSL context options(https://www.php.net/manual/en/context.ssl.php) (TLS options) +// If value is array (even empty), it will connect via TLS. If not, it will connect without TLS. +// Note: If the seeds start with "ssl:// or tls://", it will connect to the seeds via TLS, but the subsequent connections will connect without TLS if this value is null. So, if your nodes require TLS, this value must be an array, even if empty. +$obj_cluster = new RedisCluster(NULL, "host:7000", "host:7001", 1.5, 1.5, true, NULL, "verify_peer" => false); +``` + +#### Loading a cluster configuration by name +In order to load a named array, one must first define the seed nodes in redis.ini. The following lines would define the cluster 'mycluster', and be loaded automatically by phpredis. + +```ini +# In redis.ini +redis.clusters.seeds = "mycluster=localhost:7000&test=localhost:7001" +redis.clusters.timeout = "mycluster=5" +redis.clusters.read_timeout = "mycluster=10" +redis.clusters.auth = "mycluster=password" +``` + +Then, this cluster can be loaded by doing the following + +```php +$obj_cluster = new RedisCluster('mycluster'); +``` + +## Connection process + +On construction, the RedisCluster class will iterate over the provided seed nodes until it can attain a connection to the cluster and run CLUSTER SLOTS to map every node in the cluster locally. Once the keyspace is mapped, RedisCluster will only connect to nodes when it needs to (e.g. you're getting a key that we believe is on that node.) + +## Slot caching +Each time the `RedisCluster` class is constructed from scratch, phpredis needs to execute a `CLUSTER SLOTS` command to map the keyspace. Although this isn't an expensive command, it does require a round trip for each newly created object, which is inefficient. Starting from PhpRedis 5.0.0 these slots can be cached by setting `redis.clusters.cache_slots = 1` in `php.ini`. + +## Timeouts +Because Redis cluster is intended to provide high availability, timeouts do not work in the same way they do in normal socket communication. It's fully possible to have a timeout or even exception on a given socket (say in the case that a master node has failed), and continue to serve the request if and when a slave can be promoted as the new master. + +The way RedisCluster handles user specified timeout values is that every time a command is sent to the cluster, we record the time at the start of the request and then again every time we have to re-issue the command to a different node (either because Redis cluster responded with MOVED/ASK or because we failed to communicate with a given node). Once we detect having been in the command loop for longer than our specified timeout, an error is raised. + +## Keyspace map +As previously described, RedisCluster makes an initial mapping of every master (and any slaves) on construction, which it uses to determine which nodes to direct a given command. However, one of the core functionalities of Redis cluster is that this keyspace can change while the cluster is running. + +Because of this, the RedisCluster class will update its keyspace mapping whenever it receives a MOVED error when requesting data. In the case that we receive ASK redirection, it follows the Redis specification and requests the key from the ASK node, prefixed with an ASKING command. + +## Automatic slave failover / distribution +By default, RedisCluster will only ever send commands to master nodes, but can be configured differently for readonly commands if requested. + +```php +// The default option, only send commands to master nodes +$obj_cluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_NONE); + +// In the event we can't reach a master, and it has slaves, failover for read commands +$obj_cluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_ERROR); + +// Always distribute readonly commands between masters and slaves, at random +$obj_cluster->setOption( + RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE +); + +// Always distribute readonly commands to the slaves, at random +$obj_cluster->setOption( + RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES +); +``` + +## Main command loop +With the exception of commands that are directed to a specific node, each command executed via RedisCluster is processed through a command loop, where we make the request, handle any MOVED or ASK redirection, and repeat if necessary. This continues until one of the following conditions is met: + +1. We fail to communicate with *any* node that we are aware of, in which case a `RedisClusterException` is raised. +2. We have been bounced around longer than the timeout which was set on construction. +3. Redis cluster returns to us a `CLUSTERDOWN` error, in which case a `RedisClusterException` is raised. +4. We receive a valid response, in which case the data is returned to the caller. + +## Transactions +The RedisCluster class fully supports MULTI ... EXEC transactions, including commands such as MGET and MSET which operate on multiple keys. There are considerations that must be taken into account here however. + +When you call `RedisCluster->multi()`, the cluster is put into a MULTI state, but the MULTI command is not delivered to any nodes until a key is requested on that node. In addition, calls to EXEC will always return an array (even in the event that a transaction to a given node failed), as the commands can be going to any number of nodes depending on what is called. + +Consider the following example: + +```php +// Cluster is put into MULTI state locally +$obj_cluster->multi(); + +// The cluster will issue MULTI on this node first (and only once) +$obj_cluster->get("mykey"); +$obj_cluster->set("mykey", "new_value"); + +// If 'myotherkey' maps to a different node, MULTI will be issued there +// before requesting the key +$obj_cluster->get("myotherkey"); + +// This will always return an array, even in the event of a failed transaction +// on one of the nodes, in which case that element will be FALSE +print_r($obj_cluster->exec()); +``` + +## Pipelining +The RedisCluster class does not support pipelining as there is no way to detect whether the keys still live where our map indicates that they do and would therefore be inherently unsafe. It would be possible to implement this support as an option if there is demand for such a feature. + +## Multiple key commands +Redis cluster does allow commands that operate on multiple keys, but only if all of those keys hash to the same slot. Note that it is not enough that the keys are all on the same node, but must actually hash to the exact same hash slot. + +For all of these multiple key commands (with the exception of MGET and MSET), the RedisCluster class will verify each key maps to the same hash slot and raise a "CROSSSLOT" warning, returning false if they don't. + +### MGET, MSET, DEL, and UNLINK +RedisCluster has specialized processing for MGET, MSET, DEL, and UNLINK which allows you to send any number of keys (hashing to whichever slots) without having to consider where they live. The way this works, is that the RedisCluster class will split the command as it iterates through keys, delivering a subset of commands per each key's slot. + +*Note: If you send keys that hash to more than one slot, these commands are no longer atomic.* + +```php +// This will send two `MGET` commands. One for `{hash1}` keys, and one for `otherkey` +$obj_cluster->mget("{hash1}key1","{hash1}key2","{hash1}key3","otherkey"); +``` + +This operation can also be done in MULTI mode transparently. + +## Directed node commands +There are a variety of commands which have to be directed at a specific node. In the case of these commands, the caller can either pass a key (which will be hashed and used to direct our command), or an array with host:port. + +```php +// This will be directed at the slot/node which would store "mykey" +$obj_cluster->echo("mykey","Hello World!"); + +// Here we're iterating all of our known masters, and delivering the command there +foreach ($obj_cluster->_masters() as $arr_master) { + $obj_cluster->echo($arr_master, "Hello: " . implode(':', $arr_master)); +} +``` + +In the case of all commands which need to be directed at a node, the calling convention is identical to the Redis call, except that they require an additional (first) argument in order to deliver the command. Following is a list of each of these commands: + +1. ACL +1. BGREWRITEAOF +1. BGSAVE +1. CLIENT +1. CLUSTER +1. CONFIG +1. DBSIZE +1. ECHO +1. FLUSHALL +1. FLUSHDB +1. INFO +1. LASTSAVE +1. PING +1. PUBSUB +1. RANDOMKEY +1. RAWCOMMAND +1. ROLE +1. SAVE +1. SCAN +1. SCRIPT +1. SLOWLOG +1. TIME + +## Session Handler +You can use the cluster functionality of phpredis to store PHP session information in a Redis cluster as you can with a non cluster-enabled Redis instance. + +To do this, you must configure your `session.save_handler` and `session.save_path` INI variables to give phpredis enough information to communicate with the cluster. + +```ini +session.save_handler = rediscluster +session.save_path = "seed=host1:port1&seed=host2:port2&seed=hostN:portN&timeout=2&read_timeout=2&failover=error&persistent=1&auth=password&streamverify_peer=0" +``` + +### session.session_handler +Set this variable to "rediscluster" to inform phpredis that this is a cluster instance. + +### session.save_path +The save path for cluster based session storage takes the form of a PHP GET request, and requires that you specify at least one `seed` node. Other options you can specify are as follows: + +* _timeout (double)_: The amount of time phpredis will wait when connecting or writing to the cluster. +* _read\_timeout (double)_: The amount of time phpredis will wait for a result from the cluster. +* _persistent_: Tells phpredis whether persistent connections should be used. +* _failover (string)_: How phpredis should distribute session reads between master and slave nodes. + * _none_ : phpredis will only communicate with master nodes + * _error_: phpredis will communicate with master nodes unless one fails, in which case an attempt will be made to read session information from a slave. + * _distribute_: phpredis will randomly distribute session reads between masters and any attached slaves (load balancing).
View file
redis-6.2.0.tgz/redis-6.2.0/cluster_library.c
Added
@@ -0,0 +1,3137 @@ +#include "php_redis.h" +#include "common.h" +#include "library.h" +#include "redis_commands.h" +#include "cluster_library.h" +#include "crc16.h" +#include <zend_exceptions.h> + +extern zend_class_entry *redis_cluster_exception_ce; +int le_cluster_slot_cache; + +/* Debugging methods/ +static void cluster_dump_nodes(redisCluster *c) { + redisClusterNode *p; + + ZEND_HASH_FOREACH_PTR(c->nodes, p) { + if (p == NULL) { + continue; + } + + const char *slave = (p->slave) ? "slave" : "master"; + php_printf("%d %s %d %d", p->sock->port, slave,p->sock->prefix_len, + p->slot); + + php_printf("\n"); + } ZEND_HASH_FOREACH_END(); +} + +static void cluster_log(char *fmt, ...) +{ + va_list args; + char buffer1024; + + va_start(args, fmt); + vsnprintf(buffer,sizeof(buffer),fmt,args); + va_end(args); + + fprintf(stderr, "%s\n", buffer); +} + +// Debug function to dump a clusterReply structure recursively +static void dump_reply(clusterReply *reply, int indent) { + smart_string buf = {0}; + int i; + + switch(reply->type) { + case TYPE_ERR: + smart_string_appendl(&buf, "(error) ", sizeof("(error) ")-1); + smart_string_appendl(&buf, reply->str, reply->len); + break; + case TYPE_LINE: + smart_string_appendl(&buf, reply->str, reply->len); + break; + case TYPE_INT: + smart_string_appendl(&buf, "(integer) ", sizeof("(integer) ")-1); + smart_string_append_long(&buf, reply->integer); + break; + case TYPE_BULK: + smart_string_appendl(&buf,"\"", 1); + smart_string_appendl(&buf, reply->str, reply->len); + smart_string_appendl(&buf, "\"", 1); + break; + case TYPE_MULTIBULK: + if (reply->elements < 0) { + smart_string_appendl(&buf, "(nil)", sizeof("(nil)")-1); + } else { + for (i = 0; i < reply->elements; i++) { + dump_reply(reply->elementi, indent+2); + } + } + break; + default: + break; + } + + if (buf.len > 0) { + for (i = 0; i < indent; i++) { + php_printf(" "); + } + + smart_string_0(&buf); + php_printf("%s", buf.c); + php_printf("\n"); + + efree(buf.c); + } +} +*/ + + +/* Recursively free our reply object. If free_data is non-zero we'll also free + * the payload data (strings) themselves. If not, we just free the structs */ +void cluster_free_reply(clusterReply *reply, int free_data) { + long long i; + + switch(reply->type) { + case TYPE_ERR: + case TYPE_LINE: + case TYPE_BULK: + if (free_data && reply->str) + efree(reply->str); + break; + case TYPE_MULTIBULK: + if (reply->element) { + if (reply->elements > 0) { + for (i = 0; i < reply->elements && reply->elementi; i++) { + cluster_free_reply(reply->elementi, free_data); + } + } + efree(reply->element); + } + break; + default: + break; + } + efree(reply); +} + +static int +cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements, + clusterReply **element, int status_strings) +{ + int i; + size_t sz; + clusterReply *r; + long len; + char buf1024; + + for (i = 0; i < elements; i++) { + r = elementi = ecalloc(1, sizeof(clusterReply)); + + // Bomb out, flag error condition on a communication failure + if (redis_read_reply_type(sock, &r->type, &len) < 0) { + return FAILURE; + } + + /* Set our reply len */ + r->len = len; + + switch(r->type) { + case TYPE_ERR: + case TYPE_LINE: + if (redis_sock_gets(sock,buf,sizeof(buf),&sz) < 0) { + return FAILURE; + } + r->len = (long long)sz; + if (status_strings) r->str = estrndup(buf, r->len); + break; + case TYPE_INT: + r->integer = len; + break; + case TYPE_BULK: + if (r->len >= 0) { + r->str = redis_sock_read_bulk_reply(sock,r->len); + if (!r->str) { + return FAILURE; + } + } + break; + case TYPE_MULTIBULK: + r->elements = r->len; + if (r->elements > 0) { + r->element = ecalloc(r->len, sizeof(*r->element)); + if (cluster_multibulk_resp_recursive(sock, r->elements, r->element, status_strings) < 0) { + return FAILURE; + } + } + break; + default: + return FAILURE; + } + } + return SUCCESS; +} + +/* Return the socket for a slot and slave index */ +static RedisSock *cluster_slot_sock(redisCluster *c, unsigned short slot, + zend_ulong slaveidx) +{ + redisClusterNode *node; + + /* Return the master if we're not looking for a slave */ + if (slaveidx == 0) { + return SLOT_SOCK(c, slot); + } + + /* Abort if we can't find this slave */ + if (!SLOT_SLAVES(c, slot) || + (node = zend_hash_index_find_ptr(SLOT_SLAVES(c,slot), slaveidx)) == NULL + ) { + return NULL; + } + + /* Success, return the slave */ + return node->sock; +} + +/* Read the response from a cluster */ +clusterReply *cluster_read_resp(redisCluster *c, int status_strings) {
View file
redis-6.2.0.tgz/redis-6.2.0/cluster_library.h
Added
@@ -0,0 +1,537 @@ +#ifndef _PHPREDIS_CLUSTER_LIBRARY_H +#define _PHPREDIS_CLUSTER_LIBRARY_H + +#include "common.h" + +#ifdef ZTS +#include "TSRM.h" +#endif + +/* Redis cluster hash slots and N-1 which we'll use to find it */ +#define REDIS_CLUSTER_SLOTS 16384 +#define REDIS_CLUSTER_MOD (REDIS_CLUSTER_SLOTS-1) + +/* Complete representation for various commands in RESP */ +#define RESP_UNWATCH_CMD "*1\r\n$7\r\nUNWATCH\r\n" +#define RESP_CLUSTER_SLOTS_CMD "*2\r\n$7\r\nCLUSTER\r\n$5\r\nSLOTS\r\n" +#define RESP_ASKING_CMD "*1\r\n$6\r\nASKING\r\n" +#define RESP_READONLY_CMD "*1\r\n$8\r\nREADONLY\r\n" +#define RESP_READWRITE_CMD "*1\r\n$9\r\nREADWRITE\r\n" + +#define RESP_READONLY_CMD_LEN (sizeof(RESP_READONLY_CMD)-1) + +/* MOVED/ASK comparison macros */ +#define IS_MOVED(p) (p0=='M' && p1=='O' && p2=='V' && p3=='E' && \ + p4=='D' && p5==' ') +#define IS_ASK(p) (p0=='A' && p1=='S' && p2=='K' && p3==' ') + +/* MOVED/ASK lengths */ +#define MOVED_LEN (sizeof("MOVED ")-1) +#define ASK_LEN (sizeof("ASK ")-1) + +/* Initial allocation size for key distribution container */ +#define CLUSTER_KEYDIST_ALLOC 8 + +/* Macros to access nodes, sockets, and streams for a given slot */ +#define SLOT(c,s) (c->masters) +#define SLOT_SOCK(c,s) (SLOT(c,s)->sock) +#define SLOT_STREAM(c,s) (SLOT_SOCK(c,s)->stream) +#define SLOT_SLAVES(c,s) (c->masters->slaves) + +/* Compare redirection slot information with the passed node */ +#define CLUSTER_REDIR_CMP(c, sock) \ + (sock->port != c->redir_port || \ + ZSTR_LEN(sock->host) != c->redir_host_len || \ + memcmp(ZSTR_VAL(sock->host),c->redir_host,c->redir_host_len)) + +/* Clear out our "last error" */ +#define CLUSTER_CLEAR_ERROR(c) do { \ + if (c->err) { \ + zend_string_release(c->err); \ + c->err = NULL; \ + } \ + c->clusterdown = 0; \ +} while (0) + +/* Protected sending of data down the wire to a RedisSock->stream */ +#define CLUSTER_SEND_PAYLOAD(sock, buf, len) \ + (sock && !redis_sock_server_open(sock) && sock->stream && !redis_check_eof(sock, 0, 1) && \ + redis_sock_write_raw(sock, buf, len) == len) + +/* Macro to read our reply type character */ +#define CLUSTER_VALIDATE_REPLY_TYPE(sock, type) \ + (redis_check_eof(sock, 1, 1) == 0 && redis_sock_getc(sock) == type) + +/* Reset our last single line reply buffer and length */ +#define CLUSTER_CLEAR_REPLY(c) \ + *c->line_reply = '\0'; c->reply_len = 0; + +/* Helper to determine if we're in MULTI mode */ +#define CLUSTER_IS_ATOMIC(c) (c->flags->mode != MULTI) + +/* Helper that either returns false or adds false in multi mode */ +#define CLUSTER_RETURN_FALSE(c) \ + if(CLUSTER_IS_ATOMIC(c)) { \ + RETURN_FALSE; \ + } else { \ + add_next_index_bool(&c->multi_resp, 0); \ + return; \ + } + +/* Helper to either return a bool value or add it to MULTI response */ +#define CLUSTER_RETURN_BOOL(c, b) \ + if(CLUSTER_IS_ATOMIC(c)) { \ + RETURN_BOOL(b); \ + } else { \ + add_next_index_bool(&c->multi_resp, b); \ + } + +/* Helper to respond with a double or add it to our MULTI response */ +#define CLUSTER_RETURN_DOUBLE(c, d) \ + if(CLUSTER_IS_ATOMIC(c)) { \ + RETURN_DOUBLE(d); \ + } else { \ + add_next_index_double(&c->multi_resp, d); \ + } + +/* Helper to return a string value */ +#define CLUSTER_RETURN_STRING(c, str, len) \ + if(CLUSTER_IS_ATOMIC(c)) { \ + RETVAL_STRINGL(str, len); \ + } else { \ + add_next_index_stringl(&c->multi_resp, str, len); \ + } \ + +/* Return a LONG value */ +#define CLUSTER_RETURN_LONG(c, val) \ + if(CLUSTER_IS_ATOMIC(c)) { \ + RETURN_LONG(val); \ + } else { \ + add_next_index_long(&c->multi_resp, val); \ + } + +/* Macro to clear out a clusterMultiCmd structure */ +#define CLUSTER_MULTI_CLEAR(mc) \ + mc->cmd.len = 0; \ + mc->args.len = 0; \ + mc->argc = 0; \ + +/* Initialize a clusterMultiCmd with a keyword and length */ +#define CLUSTER_MULTI_INIT(mc, keyword, keyword_len) \ + mc.kw = keyword; \ + mc.kw_len = keyword_len; \ + +#define CLUSTER_CACHING_ENABLED() (INI_INT("redis.clusters.cache_slots") == 1) + +/* Cluster redirection enum */ +typedef enum CLUSTER_REDIR_TYPE { + REDIR_NONE, + REDIR_MOVED, + REDIR_ASK +} CLUSTER_REDIR_TYPE; + +/* MULTI BULK response callback typedef */ +typedef int (*mbulk_cb)(RedisSock*,zval*,long long, void*); + +/* A list of covered slot ranges */ +typedef struct redisSlotRange { + unsigned short low; + unsigned short high; +} redisSlotRange; + +/* Simple host/port information for our cache */ +typedef struct redisCachedHost { + zend_string *addr; + unsigned short port; +} redisCachedHost; + +/* Storage for a cached master node */ +typedef struct redisCachedMaster { + redisCachedHost host; + + redisSlotRange *slot; /* Slots and count */ + size_t slots; + + redisCachedHost *slave; /* Slaves and their count */ + size_t slaves; +} redisCachedMaster; + +typedef struct redisCachedCluster { + // int rsrc_id; /* Zend resource ID */ + zend_string *hash; /* What we're cached by */ + redisCachedMaster *master; /* Array of masters */ + size_t count; /* Number of masters */ +} redisCachedCluster; + +/* A Redis Cluster master node */ +typedef struct redisClusterNode { + RedisSock *sock; /* Our Redis socket in question */ + short slot; /* One slot we believe this node serves */ + zend_llist slots; /* List of all slots we believe this node serves */ + unsigned short slave; /* Are we a slave */ + HashTable *slaves; /* Hash table of slaves */ +} redisClusterNode; + +/* Forward declarations */ +typedef struct clusterFoldItem clusterFoldItem; + +/* RedisCluster implementation structure */ +typedef struct redisCluster { + + /* One RedisSock struct for serialization and prefix information */ + RedisSock *flags; + + /* How long in milliseconds should we wait when being bounced around */ + long waitms; + + /* Are we flagged as being in readonly mode, meaning we could fall back to + * a given master's slave */ + short readonly; + + /* RedisCluster failover options (never, on error, to load balance) */ + short failover; + + /* Hash table of seed host/ports */ + HashTable *seeds; + + /* RedisCluster masters, by direct slot */ + redisClusterNode *masterREDIS_CLUSTER_SLOTS; +
View file
redis-6.2.0.tgz/redis-6.2.0/common.h
Added
@@ -0,0 +1,362 @@ +#include "php.h" +#include "php_ini.h" + +#ifndef REDIS_COMMON_H +#define REDIS_COMMON_H + +#define PHPREDIS_CTX_PTR ((char *)0xDEADC0DE) +#define PHPREDIS_NOTUSED(v) ((void)v) + +#include "zend_llist.h" +#include <ext/standard/php_var.h> +#include <ext/standard/php_math.h> +#include <zend_smart_str.h> +#include <ext/standard/php_smart_string.h> + +#define PHPREDIS_GET_OBJECT(class_entry, o) (class_entry *)((char *)o - XtOffsetOf(class_entry, std)) +#define PHPREDIS_ZVAL_GET_OBJECT(class_entry, z) PHPREDIS_GET_OBJECT(class_entry, Z_OBJ_P(z)) + +/* We'll fallthrough if we want to */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#if __has_attribute(__fallthrough__) +#define REDIS_FALLTHROUGH __attribute__((__fallthrough__)) +#else +#define REDIS_FALLTHROUGH do { } while (0) +#endif + +/* NULL check so Eclipse doesn't go crazy */ +#ifndef NULL +#define NULL ((void *) 0) +#endif + +#include "backoff.h" + +typedef enum { + REDIS_SOCK_STATUS_FAILED = -1, + REDIS_SOCK_STATUS_DISCONNECTED, + REDIS_SOCK_STATUS_CONNECTED, + REDIS_SOCK_STATUS_AUTHENTICATED, + REDIS_SOCK_STATUS_READY +} redis_sock_status; + +#define _NL "\r\n" + +/* properties */ +#define REDIS_NOT_FOUND 0 +#define REDIS_STRING 1 +#define REDIS_SET 2 +#define REDIS_LIST 3 +#define REDIS_ZSET 4 +#define REDIS_HASH 5 +#define REDIS_STREAM 6 + +#ifdef PHP_WIN32 +#define PHP_REDIS_API __declspec(dllexport) +#define phpredis_atoi64(p) _atoi64((p)) +#else +#define PHP_REDIS_API +#define phpredis_atoi64(p) atoll((p)) +#endif + +/* reply types */ +typedef enum _REDIS_REPLY_TYPE { + TYPE_EOF = -1, + TYPE_LINE = '+', + TYPE_INT = ':', + TYPE_ERR = '-', + TYPE_BULK = '$', + TYPE_MULTIBULK = '*' +} REDIS_REPLY_TYPE; + +/* SCAN variants */ +typedef enum _REDIS_SCAN_TYPE { + TYPE_SCAN, + TYPE_SSCAN, + TYPE_HSCAN, + TYPE_ZSCAN +} REDIS_SCAN_TYPE; + +/* PUBSUB subcommands */ +typedef enum _PUBSUB_TYPE { + PUBSUB_CHANNELS, + PUBSUB_NUMSUB, + PUBSUB_NUMPAT +} PUBSUB_TYPE; + +#define REDIS_SUBSCRIBE_IDX 0 +#define REDIS_PSUBSCRIBE_IDX 1 +#define REDIS_SSUBSCRIBE_IDX 2 +#define REDIS_SUBS_BUCKETS 3 + +/* options */ +#define REDIS_OPT_SERIALIZER 1 +#define REDIS_OPT_PREFIX 2 +#define REDIS_OPT_READ_TIMEOUT 3 +#define REDIS_OPT_SCAN 4 +#define REDIS_OPT_FAILOVER 5 +#define REDIS_OPT_TCP_KEEPALIVE 6 +#define REDIS_OPT_COMPRESSION 7 +#define REDIS_OPT_REPLY_LITERAL 8 +#define REDIS_OPT_COMPRESSION_LEVEL 9 +#define REDIS_OPT_NULL_MBULK_AS_NULL 10 +#define REDIS_OPT_MAX_RETRIES 11 +#define REDIS_OPT_BACKOFF_ALGORITHM 12 +#define REDIS_OPT_BACKOFF_BASE 13 +#define REDIS_OPT_BACKOFF_CAP 14 +#define REDIS_OPT_PACK_IGNORE_NUMBERS 15 + +/* cluster options */ +#define REDIS_FAILOVER_NONE 0 +#define REDIS_FAILOVER_ERROR 1 +#define REDIS_FAILOVER_DISTRIBUTE 2 +#define REDIS_FAILOVER_DISTRIBUTE_SLAVES 3 +/* serializers */ +typedef enum { + REDIS_SERIALIZER_NONE, + REDIS_SERIALIZER_PHP, + REDIS_SERIALIZER_IGBINARY, + REDIS_SERIALIZER_MSGPACK, + REDIS_SERIALIZER_JSON +} redis_serializer; +/* compression */ +#define REDIS_COMPRESSION_NONE 0 +#define REDIS_COMPRESSION_LZF 1 +#define REDIS_COMPRESSION_ZSTD 2 +#define REDIS_COMPRESSION_LZ4 3 + +/* SCAN options */ +#define REDIS_SCAN_NORETRY 0 +#define REDIS_SCAN_RETRY 1 +#define REDIS_SCAN_PREFIX 2 +#define REDIS_SCAN_NOPREFIX 3 + +/* BACKOFF_ALGORITHM options */ +#define REDIS_BACKOFF_ALGORITHMS 7 +#define REDIS_BACKOFF_ALGORITHM_DEFAULT 0 +#define REDIS_BACKOFF_ALGORITHM_DECORRELATED_JITTER 1 +#define REDIS_BACKOFF_ALGORITHM_FULL_JITTER 2 +#define REDIS_BACKOFF_ALGORITHM_EQUAL_JITTER 3 +#define REDIS_BACKOFF_ALGORITHM_EXPONENTIAL 4 +#define REDIS_BACKOFF_ALGORITHM_UNIFORM 5 +#define REDIS_BACKOFF_ALGORITHM_CONSTANT 6 + +/* GETBIT/SETBIT offset range limits */ +#define BITOP_MIN_OFFSET 0 +#define BITOP_MAX_OFFSET 4294967295U + +/* Transaction modes */ +#define ATOMIC 0 +#define MULTI 1 +#define PIPELINE 2 + +#define PHPREDIS_DEBUG_LOGGING 0 +#define PHPREDIS_WITH_METADATA 1 + +#if PHP_VERSION_ID < 80000 +#define Z_PARAM_ARRAY_HT_OR_NULL(dest) \ + Z_PARAM_ARRAY_HT_EX(dest, 1, 0) +#define Z_PARAM_STR_OR_NULL(dest) \ + Z_PARAM_STR_EX(dest, 1, 0) +#define Z_PARAM_ZVAL_OR_NULL(dest) \ + Z_PARAM_ZVAL_EX(dest, 1, 0) +#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \ + Z_PARAM_BOOL_EX(dest, is_null, 1, 0) +#endif + +#if PHPREDIS_DEBUG_LOGGING == 1 +#define redisDbgFmt(fmt, ...) \ + php_printf("%s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, __VA_ARGS__) +#define redisDbgStr(str) phpredisDebugFmt("%s", str) +#else +#define redisDbgFmt(fmt, ...) ((void)0) +#define redisDbgStr(str) ((void)0) +#endif + +#define IS_ATOMIC(redis_sock) (redis_sock->mode == ATOMIC) +#define IS_MULTI(redis_sock) (redis_sock->mode & MULTI) +#define IS_PIPELINE(redis_sock) (redis_sock->mode & PIPELINE) + +#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) do { \ + smart_string_appendl(&redis_sock->pipeline_cmd, cmd, cmd_len); \ +} while (0) + +#define REDIS_SAVE_CALLBACK(callback, closure_context) do { \ + fold_item *fi = redis_add_reply_callback(redis_sock); \ + fi->fun = callback; \ + fi->flags = redis_sock->flags; \ + fi->ctx = closure_context; \ +} while (0) + +#define REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len) \ + if (IS_PIPELINE(redis_sock)) { \ + PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len); \ + } else if (redis_sock_write(redis_sock, cmd, cmd_len) < 0) { \ + efree(cmd); \ + RETURN_FALSE; \ + } \ + efree(cmd);
View file
redis-6.2.0.tgz/redis-6.2.0/config.m4
Added
@@ -0,0 +1,329 @@ +dnl $Id$ +dnl config.m4 for extension redis + +PHP_ARG_ENABLE(redis, whether to enable redis support, +dnl Make sure that the comment is aligned: + --enable-redis Enable redis support) + +PHP_ARG_ENABLE(redis-session, whether to enable sessions, + --disable-redis-session Disable session support, yes, no) + +PHP_ARG_ENABLE(redis-json, whether to enable json serializer support, + --disable-redis-json Disable json serializer support, yes, no) + +PHP_ARG_ENABLE(redis-igbinary, whether to enable igbinary serializer support, + --enable-redis-igbinary Enable igbinary serializer support, no, no) + +PHP_ARG_ENABLE(redis-msgpack, whether to enable msgpack serializer support, + --enable-redis-msgpack Enable msgpack serializer support, no, no) + +PHP_ARG_ENABLE(redis-lzf, whether to enable lzf compression, + --enable-redis-lzf Enable lzf compression support, no, no) + +PHP_ARG_WITH(liblzf, use system liblzf, + --with-liblzf=DIR Use system liblzf, no, no) + +PHP_ARG_ENABLE(redis-zstd, whether to enable Zstd compression, + --enable-redis-zstd Enable Zstd compression support, no, no) + +PHP_ARG_WITH(libzstd, use system libzstd, + --with-libzstd=DIR Use system libzstd, yes, no) + +PHP_ARG_ENABLE(redis-lz4, whether to enable lz4 compression, + --enable-redis-lz4 Enable lz4 compression support, no, no) + +PHP_ARG_WITH(liblz4, use system liblz4, + --with-liblz4=DIR Use system liblz4, no, no) + +if test "$PHP_REDIS" != "no"; then + + if test "$PHP_REDIS_SESSION" != "no"; then + AC_DEFINE(PHP_SESSION,1,redis sessions) + fi + + AC_MSG_CHECKING(for hash includes) + hash_inc_path="" + if test -f "$abs_srcdir/include/php/ext/hash/php_hash.h"; then + hash_inc_path="$abs_srcdir/include/php" + elif test -f "$abs_srcdir/ext/hash/php_hash.h"; then + hash_inc_path="$abs_srcdir" + elif test -f "$phpincludedir/ext/hash/php_hash.h"; then + hash_inc_path="$phpincludedir" + else + for i in php php7; do + if test -f "$prefix/include/$i/ext/hash/php_hash.h"; then + hash_inc_path="$prefix/include/$i" + fi + done + fi + + if test "$hash_inc_path" = ""; then + AC_MSG_ERROR(Cannot find php_hash.h) + else + AC_MSG_RESULT($hash_inc_path) + fi + + if test "$PHP_REDIS_JSON" != "no"; then + AC_MSG_CHECKING(for json includes) + json_inc_path="" + if test -f "$abs_srcdir/include/php/ext/json/php_json.h"; then + json_inc_path="$abs_srcdir/include/php" + elif test -f "$abs_srcdir/ext/json/php_json.h"; then + json_inc_path="$abs_srcdir" + elif test -f "$phpincludedir/ext/json/php_json.h"; then + json_inc_path="$phpincludedir" + else + for i in php php7; do + if test -f "$prefix/include/$i/ext/json/php_json.h"; then + json_inc_path="$prefix/include/$i" + fi + done + fi + + if test "$json_inc_path" = ""; then + AC_MSG_ERROR(Cannot find php_json.h) + else + AC_MSG_RESULT($json_inc_path) + fi + fi + + AC_MSG_CHECKING(for redis json support) + if test "$PHP_REDIS_JSON" != "no"; then + AC_MSG_RESULT(enabled) + AC_DEFINE(HAVE_REDIS_JSON,1,Whether redis json serializer is enabled) + JSON_INCLUDES="-I$json_inc_path" + JSON_EXT_DIR="$json_inc_path/ext" + ifdef(PHP_ADD_EXTENSION_DEP, + + PHP_ADD_EXTENSION_DEP(redis, json) + ) + PHP_ADD_INCLUDE($JSON_EXT_DIR) + else + JSON_INCLUDES="" + AC_MSG_RESULT(disabled) + fi + + if test "$PHP_REDIS_IGBINARY" != "no"; then + AC_MSG_CHECKING(for igbinary includes) + igbinary_inc_path="" + + if test -f "$abs_srcdir/include/php/ext/igbinary/igbinary.h"; then + igbinary_inc_path="$abs_srcdir/include/php" + elif test -f "$abs_srcdir/ext/igbinary/igbinary.h"; then + igbinary_inc_path="$abs_srcdir" + elif test -f "$phpincludedir/ext/igbinary/igbinary.h"; then + igbinary_inc_path="$phpincludedir" + else + for i in php php7; do + if test -f "$prefix/include/$i/ext/igbinary/igbinary.h"; then + igbinary_inc_path="$prefix/include/$i" + fi + done + fi + + if test "$igbinary_inc_path" = ""; then + AC_MSG_ERROR(Cannot find igbinary.h) + else + AC_MSG_RESULT($igbinary_inc_path) + fi + fi + + AC_MSG_CHECKING(for redis igbinary support) + if test "$PHP_REDIS_IGBINARY" != "no"; then + AC_MSG_RESULT(enabled) + AC_DEFINE(HAVE_REDIS_IGBINARY,1,Whether redis igbinary serializer is enabled) + IGBINARY_INCLUDES="-I$igbinary_inc_path" + IGBINARY_EXT_DIR="$igbinary_inc_path/ext" + ifdef(PHP_ADD_EXTENSION_DEP, + + PHP_ADD_EXTENSION_DEP(redis, igbinary) + ) + PHP_ADD_INCLUDE($IGBINARY_EXT_DIR) + else + IGBINARY_INCLUDES="" + AC_MSG_RESULT(disabled) + fi + + if test "$PHP_REDIS_MSGPACK" != "no"; then + AC_MSG_CHECKING(for msgpack includes) + msgpack_inc_path="" + + if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then + msgpack_inc_path="$abs_srcdir/include/php" + elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then + msgpack_inc_path="$abs_srcdir" + elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then + msgpack_inc_path="$phpincludedir" + else + for i in php php7; do + if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then + msgpack_inc_path="$prefix/include/$i" + fi + done + fi + + if test "$msgpack_inc_path" = ""; then + AC_MSG_ERROR(Cannot find php_msgpack.h) + else + AC_MSG_RESULT($msgpack_inc_path) + fi + fi + + if test "$PHP_REDIS_MSGPACK" != "no"; then + AC_MSG_CHECKING(for php msgpack version >= 2.0.3) + MSGPACK_VERSION=`$EGREP "define PHP_MSGPACK_VERSION" $msgpack_inc_path/ext/msgpack/php_msgpack.h | $SED -e 's/^0-9\.//g'` + if test `echo $MSGPACK_VERSION | $SED -e 's/^0-9/ /g' | $AWK '{print $1*1000 + $2*100 + $3*10 + $4}'` -lt 2030; then + AC_MSG_ERROR(version >= 2.0.3 required) + else + AC_MSG_RESULT(yes) + fi + + AC_DEFINE(HAVE_REDIS_MSGPACK,1,Whether redis msgpack serializer is enabled) + MSGPACK_INCLUDES="-I$msgpack_inc_path" + MSGPACK_EXT_DIR="$msgpack_inc_path/ext" + ifdef(PHP_ADD_EXTENSION_DEP, + + PHP_ADD_EXTENSION_DEP(redis, msgpack) + ) + PHP_ADD_INCLUDE($MSGPACK_EXT_DIR) + else + MSGPACK_INCLUDES="" + fi + + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + + if test "$PHP_REDIS_LZF" != "no"; then + AC_DEFINE(HAVE_REDIS_LZF, 1, ) + + if test "$PHP_LIBLZF" = "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists liblzf; then + AC_MSG_CHECKING(for liblzf using pkg-config)
View file
redis-6.2.0.tgz/redis-6.2.0/config.w32
Changed
(renamed from redis-5.3.7/config.w32)
View file
redis-6.2.0.tgz/redis-6.2.0/crc16.h
Changed
(renamed from redis-5.3.7/crc16.h)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/LICENSE
Changed
(renamed from redis-5.3.7/liblzf/LICENSE)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/README
Changed
(renamed from redis-5.3.7/liblzf/README)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/lzf.h
Changed
(renamed from redis-5.3.7/liblzf/lzf.h)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/lzfP.h
Changed
(renamed from redis-5.3.7/liblzf/lzfP.h)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/lzf_c.c
Changed
(renamed from redis-5.3.7/liblzf/lzf_c.c)
View file
redis-6.2.0.tgz/redis-6.2.0/liblzf/lzf_d.c
Changed
(renamed from redis-5.3.7/liblzf/lzf_d.c)
View file
redis-6.2.0.tgz/redis-6.2.0/library.c
Added
@@ -0,0 +1,4680 @@ +#include "php_redis.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common.h" +#include "php_network.h" +#include <sys/types.h> + +#ifdef HAVE_REDIS_IGBINARY +#include "igbinary/igbinary.h" +#endif +#ifdef HAVE_REDIS_MSGPACK +#include "msgpack/php_msgpack.h" +#endif + +#ifdef HAVE_REDIS_LZF +#include <lzf.h> + + #ifndef LZF_MARGIN + #define LZF_MARGIN 128 + #endif +#endif + +#ifdef HAVE_REDIS_ZSTD +#include <zstd.h> +#endif + +#ifdef HAVE_REDIS_LZ4 +#include <lz4.h> +#include <lz4hc.h> + +/* uint8_t crf + int length */ +#define REDIS_LZ4_HDR_SIZE (sizeof(uint8_t) + sizeof(int)) +#if defined(LZ4HC_CLEVEL_MAX) +/* version >= 1.7.5 */ +#define REDIS_LZ4_MAX_CLEVEL LZ4HC_CLEVEL_MAX + +#elif defined (LZ4HC_MAX_CLEVEL) +/* version >= 1.7.3 */ +#define REDIS_LZ4_MAX_CLEVEL LZ4HC_MAX_CLEVEL + +#else +/* older versions */ +#define REDIS_LZ4_MAX_CLEVEL 12 +#endif +#endif + +#include <zend_exceptions.h> +#include "php_redis.h" +#include "library.h" +#include "redis_commands.h" + +#ifdef HAVE_REDIS_JSON +#include <ext/json/php_json.h> +#endif + +#include <ext/hash/php_hash.h> + +#if PHP_VERSION_ID < 80400 +#include <ext/standard/php_rand.h> +#else +#include <ext/random/php_random.h> +#endif + +#define UNSERIALIZE_NONE 0 +#define UNSERIALIZE_KEYS 1 +#define UNSERIALIZE_VALS 2 +#define UNSERIALIZE_ALL 3 + +#define SCORE_DECODE_NONE 0 +#define SCORE_DECODE_INT 1 +#define SCORE_DECODE_DOUBLE 2 + +#define REDIS_CALLBACKS_INIT_SIZE 8 +#define REDIS_CALLBACKS_MAX_DOUBLE 32768 +#define REDIS_CALLBACKS_ADD_SIZE 4096 + +/* PhpRedis often returns either FALSE or NULL depending on whether we have + * an option set, so this macro just wraps that often repeated logic */ +#define REDIS_ZVAL_NULL(sock_, zv_) \ + do { \ + if ((sock_)->null_mbulk_as_null) { \ + ZVAL_NULL((zv_)); \ + } else { \ + ZVAL_FALSE((zv_)); \ + } \ + } while (0) + +#ifndef PHP_WIN32 + #include <netinet/tcp.h> /* TCP_NODELAY */ + #include <sys/socket.h> /* SO_KEEPALIVE */ +#else + #include <winsock.h> +#endif + +extern zend_class_entry *redis_ce; +extern zend_class_entry *redis_exception_ce; + +extern int le_redis_pconnect; + +static int redis_mbulk_reply_zipped_raw_variant(RedisSock *redis_sock, zval *zret, int count); + +/* Register a persistent resource in a a way that works for every PHP 7 version. */ +void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id) { + zend_register_persistent_resource(ZSTR_VAL(id), ZSTR_LEN(id), ptr, le_id); +} + +/* Do not allocate empty string or string with one character */ +static zend_always_inline void redis_add_next_index_stringl(zval *arg, const char *str, size_t length) { + zval tmp; + ZVAL_STRINGL_FAST(&tmp, str, length); + zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp); +} + +static ConnectionPool * +redis_sock_get_connection_pool(RedisSock *redis_sock) +{ + ConnectionPool *pool; + zend_resource *le; + zend_string *persistent_id; + + /* Generate our unique pool id depending on configuration */ + persistent_id = redis_pool_spprintf(redis_sock, INI_STR("redis.pconnect.pool_pattern")); + + /* Return early if we can find the pool */ + if ((le = zend_hash_find_ptr(&EG(persistent_list), persistent_id))) { + zend_string_release(persistent_id); + return le->ptr; + } + + /* Create the pool and store it in our persistent list */ + pool = pecalloc(1, sizeof(*pool), 1); + zend_llist_init(&pool->list, sizeof(php_stream *), NULL, 1); + redis_register_persistent_resource(persistent_id, pool, le_redis_pconnect); + + zend_string_release(persistent_id); + return pool; +} + +/* Helper to reselect the proper DB number when we reconnect */ +static int reselect_db(RedisSock *redis_sock) { + char *cmd, *response; + int cmd_len, response_len; + + cmd_len = redis_spprintf(redis_sock, NULL, &cmd, "SELECT", "d", + redis_sock->dbNumber); + + if (redis_sock_write(redis_sock, cmd, cmd_len) < 0) { + efree(cmd); + return -1; + } + + efree(cmd); + + if ((response = redis_sock_read(redis_sock, &response_len)) == NULL) { + return -1; + } + + if (redis_strncmp(response, ZEND_STRL("+OK"))) { + efree(response); + return -1; + } + + efree(response); + return 0; +} + +/* Append an AUTH command to a smart string if necessary. This will either + * append the new style AUTH <user> <password>, old style AUTH <password>, or + * append no command at all. Function returns 1 if we appended a command + * and 0 otherwise. */ +static int redis_sock_append_auth(RedisSock *redis_sock, smart_string *str) { + /* We need a password at least */ + if (redis_sock->pass == NULL) + return 0; + + REDIS_CMD_INIT_SSTR_STATIC(str, !!redis_sock->user + !!redis_sock->pass, "AUTH"); + + if (redis_sock->user) + redis_cmd_append_sstr_zstr(str, redis_sock->user); + + redis_cmd_append_sstr_zstr(str, redis_sock->pass); + + /* We appended a command */ + return 1; +} + +PHP_REDIS_API void +redis_sock_set_auth(RedisSock *redis_sock, zend_string *user, zend_string *pass) +{ + /* Release existing user/pass */ + redis_sock_free_auth(redis_sock); + + /* Set new user/pass */ + redis_sock->user = user ? zend_string_copy(user) : NULL; + redis_sock->pass = pass ? zend_string_copy(pass) : NULL; +}
View file
redis-6.2.0.tgz/redis-6.2.0/library.h
Added
@@ -0,0 +1,297 @@ +#ifndef REDIS_LIBRARY_H +#define REDIS_LIBRARY_H + +/* Non cluster command helper */ +#define REDIS_SPPRINTF(ret, kw, fmt, ...) \ + redis_spprintf(redis_sock, NULL, ret, kw, fmt, ##__VA_ARGS__) + +#define REDIS_CMD_APPEND_SSTR_STATIC(sstr, str) \ + redis_cmd_append_sstr(sstr, str, sizeof(str)-1); + +#define REDIS_CMD_APPEND_SSTR_OPT_STATIC(sstr, opt, str) \ + if (opt) REDIS_CMD_APPEND_SSTR_STATIC(sstr, str); + +#define REDIS_CMD_INIT_SSTR_STATIC(sstr, argc, keyword) \ + redis_cmd_init_sstr(sstr, argc, keyword, sizeof(keyword)-1); + +#define REDIS_THROW_EXCEPTION(msg, code) \ + zend_throw_exception(redis_exception_ce, (msg), code) + +#define CLUSTER_THROW_EXCEPTION(msg, code) \ + zend_throw_exception(redis_cluster_exception_ce, (msg), code) + +#define redis_sock_write_sstr(redis_sock, sstr) \ + redis_sock_write(redis_sock, (sstr)->c, (sstr)->len) + +#if PHP_VERSION_ID < 80000 + #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(ZSTR_VAL((zstr)), ZSTR_LEN((zstr))) + + /* use RedisException when ValueError not available */ + #define REDIS_VALUE_EXCEPTION(m) REDIS_THROW_EXCEPTION(m, 0) + #define RETURN_THROWS() RETURN_FALSE + /* ZVAL_STRINGL_FAST and RETVAL_STRINGL_FAST macros are supported since PHP 8 */ + #define ZVAL_STRINGL_FAST(z, s, l) ZVAL_STRINGL(z, s, l) + #define RETVAL_STRINGL_FAST(s, l) RETVAL_STRINGL(s, l) +#else + #define redis_hash_fetch_ops(zstr) php_hash_fetch_ops(zstr) + + #define REDIS_VALUE_EXCEPTION(m) zend_value_error(m) +#endif + + +void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id); +fold_item* redis_add_reply_callback(RedisSock *redis_sock); +void redis_free_reply_callbacks(RedisSock *redis_sock); + +PHP_REDIS_API int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass); +PHP_REDIS_API void redis_with_metadata(zval *zdst, zval *zsrc, zend_long length); + +int redis_cmd_init_sstr(smart_string *str, int num_args, char *keyword, int keyword_len); +int redis_cmd_append_sstr(smart_string *str, char *append, int append_len); +int redis_cmd_append_sstr_int(smart_string *str, int append); +int redis_cmd_append_sstr_long(smart_string *str, long append); +int redis_cmd_append_sstr_i64(smart_string *str, int64_t append); +int redis_cmd_append_sstr_u64(smart_string *str, uint64_t append); +int redis_cmd_append_sstr_dbl(smart_string *str, double value); +int redis_cmd_append_sstr_zstr(smart_string *str, zend_string *zstr); +int redis_cmd_append_sstr_zval(smart_string *str, zval *z, RedisSock *redis_sock); +int redis_cmd_append_sstr_key(smart_string *str, char *key, size_t len, RedisSock *redis_sock, short *slot); +int redis_cmd_append_sstr_key_zstr(smart_string *str, zend_string *key, RedisSock *redis_sock, short *slot); +int redis_cmd_append_sstr_key_zval(smart_string *dst, zval *zv, RedisSock *redis_sock, short *slot); +int redis_cmd_append_sstr_key_long(smart_string *dst, zend_long lval, RedisSock *redis_sock, short *slot); +int redis_cmd_append_sstr_arrkey(smart_string *cmd, zend_string *kstr, zend_ulong idx); + +PHP_REDIS_API int redis_spprintf(RedisSock *redis_sock, short *slot, char **ret, char *kw, char *fmt, ...); +PHP_REDIS_API zend_string *redis_pool_spprintf(RedisSock *redis_sock, char *fmt, ...); + +PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len); +PHP_REDIS_API int redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size, size_t* line_len); +PHP_REDIS_API int redis_1_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval* z_tab, void *ctx); +typedef void (*SuccessCallback)(RedisSock *redis_sock); +PHP_REDIS_API int redis_boolean_response_impl(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx, SuccessCallback success_callback); +PHP_REDIS_API int redis_boolean_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_config_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_zrange_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API void redis_parse_info_response(char *response, zval *z_ret); +PHP_REDIS_API void redis_parse_client_list_response(char *response, zval *z_ret); +PHP_REDIS_API int redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API RedisSock* redis_sock_create(char *host, int host_len, int port, double timeout, double read_timeout, int persistent, char *persistent_id, long retry_interval); +PHP_REDIS_API int redis_sock_configure(RedisSock *redis_sock, HashTable *opts); +PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock); +PHP_REDIS_API int redis_sock_server_open(RedisSock *redis_sock); +PHP_REDIS_API int redis_sock_auth(RedisSock *redis_sock); +PHP_REDIS_API char *redis_sock_auth_cmd(RedisSock *redis_sock, int *cmdlen); +PHP_REDIS_API void redis_sock_set_auth(RedisSock *redis_sock, zend_string *user, zend_string *pass); +PHP_REDIS_API void redis_sock_set_auth_zval(RedisSock *redis_sock, zval *zv); +PHP_REDIS_API void redis_sock_free_auth(RedisSock *redis_sock); +PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock, int force, int is_reset_mode); +PHP_REDIS_API zval *redis_sock_read_multibulk_reply_zval(RedisSock *redis_sock, zval *z_tab); +PHP_REDIS_API int redis_sock_read_single_line(RedisSock *redis_sock, char *buffer, + size_t buflen, size_t *linelen, int set_err); +PHP_REDIS_API char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes); +PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *_z_tab, void *ctx); +PHP_REDIS_API void redis_mbulk_reply_loop(RedisSock *redis_sock, zval *z_tab, int count, int unserialize); + + +PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_zipped_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_zipped_vals(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_zipped_keys_int(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_zipped_keys_dbl(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_mbulk_reply_double(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); + +void redisSetScanCursor(zval *zv, uint64_t cursor); +uint64_t redisGetScanCursor(zval *zv, zend_bool *was_zero); + +PHP_REDIS_API int redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, REDIS_SCAN_TYPE type, uint64_t *cursor); + +PHP_REDIS_API int redis_xrange_reply(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_xread_reply(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); + +PHP_REDIS_API int redis_xclaim_reply(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_xclaim_reply( + RedisSock *redis_sock, int count, int is_xautoclaim, zval *rv); + +PHP_REDIS_API int redis_xinfo_reply(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); + +PHP_REDIS_API int redis_pubsub_response(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_unsubscribe_response(INTERNAL_FUNCTION_PARAMETERS, + RedisSock *redis_sock, zval *z_tab, void *ctx); + +PHP_REDIS_API int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz); +PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, zend_bool no_retry, zend_bool no_throw); +PHP_REDIS_API RedisSock *redis_sock_get(zval *id, int nothrow); +PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock); +PHP_REDIS_API void redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len); +PHP_REDIS_API int redis_sock_set_stream_context(RedisSock *redis_sock, zval *options); +PHP_REDIS_API int redis_sock_set_backoff(RedisSock *redis_sock, zval *options); + +PHP_REDIS_API int +redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len); +PHP_REDIS_API int +redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len); +PHP_REDIS_API zend_string* +redis_key_prefix_zval(RedisSock *redis_sock, zval *zv); +PHP_REDIS_API zend_string * +redis_key_prefix_zstr(RedisSock *redis_sock, zend_string *key); + +PHP_REDIS_API int +redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret); + +PHP_REDIS_API int +redis_compress(RedisSock *redis_sock, char **dst, size_t *dstlen, char *buf, size_t len); +PHP_REDIS_API int +redis_uncompress(RedisSock *redis_sock, char **dst, size_t *dstlen, const char *src, size_t len); + +PHP_REDIS_API int redis_pack(RedisSock *redis_sock, zval *z, char **val, size_t *val_len); +PHP_REDIS_API int redis_unpack(RedisSock *redis_sock, const char *val, int val_len, zval *z_ret); + +PHP_REDIS_API int +redis_read_stream_messages(RedisSock *redis_sock, int count, zval *z_ret); +PHP_REDIS_API int +redis_read_stream_messages_multi(RedisSock *redis_sock, int count, zval *z_ret); +PHP_REDIS_API int +redis_read_xinfo_response(RedisSock *redis_sock, zval *z_ret, int elements); + +PHP_REDIS_API int +redis_mpop_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + zval *z_tab, void *ctx); + +PHP_REDIS_API int +redis_read_mpop_response(RedisSock *redis_sock, zval *zdst, int elements, void *ctx); + +/* Specialized ACL reply handlers */ +PHP_REDIS_API int redis_acl_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_acl_getuser_reply(RedisSock *redis_sock, zval *zret, long len); +PHP_REDIS_API int redis_acl_getuser_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_acl_log_reply(RedisSock *redis_sock, zval *zret, long count); +PHP_REDIS_API int redis_acl_log_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); + +/* +* Variant Read methods, mostly to implement eval +*/ + +PHP_REDIS_API int redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type, long *reply_info); +PHP_REDIS_API int redis_read_variant_bulk(RedisSock *redis_sock, int size, zval *z_ret); +PHP_REDIS_API int redis_read_multibulk_recursive(RedisSock *redis_sock, long long elements, int status_strings, zval *z_ret); +PHP_REDIS_API int redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_raw_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_variant_reply_strings(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); + +PHP_REDIS_API int redis_zadd_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_zrandmember_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_zdiff_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_set_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx); +PHP_REDIS_API int redis_read_geosearch_response(zval *zdst, RedisSock *redis_sock, long long elements, int with_aux_data);
View file
redis-6.2.0.tgz/redis-6.2.0/php_redis.h
Added
@@ -0,0 +1,69 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | + | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | + +----------------------------------------------------------------------+ +*/ + +#include "common.h" + +#ifndef PHP_REDIS_H +#define PHP_REDIS_H + +/* phpredis version */ +#define PHP_REDIS_VERSION "6.2.0" + +/* For convenience we store the salt as a printable hex string which requires 2 + * characters per byte + 1 for the NULL terminator */ +#define REDIS_SALT_BYTES 32 +#define REDIS_SALT_SIZE ((2 * REDIS_SALT_BYTES) + 1) + +ZEND_BEGIN_MODULE_GLOBALS(redis) + char saltREDIS_SALT_SIZE; +ZEND_END_MODULE_GLOBALS(redis) + +ZEND_EXTERN_MODULE_GLOBALS(redis) +#define REDIS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(redis, v) + +#ifdef ZTS +#include "TSRM.h" +#endif + +PHP_MINIT_FUNCTION(redis); +PHP_MSHUTDOWN_FUNCTION(redis); +PHP_MINFO_FUNCTION(redis); + +PHP_REDIS_API int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent); + +PHP_REDIS_API int redis_response_enqueued(RedisSock *redis_sock); + +PHP_REDIS_API int redis_sock_read_multibulk_multi_reply_loop( + INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab); + +extern zend_module_entry redis_module_entry; + +#define redis_module_ptr &redis_module_entry +#define phpext_redis_ptr redis_module_ptr + +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */
View file
redis-6.2.0.tgz/redis-6.2.0/redis.c
Added
@@ -0,0 +1,3053 @@ +/* -*- Mode: C; tab-width: 4 -*- */ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | + | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php_redis.h" +#include "redis_array.h" +#include "redis_cluster.h" +#include "redis_commands.h" +#include "redis_sentinel.h" +#include <ext/spl/spl_exceptions.h> +#include <zend_exceptions.h> +#include <ext/standard/info.h> +#include <ext/hash/php_hash.h> + +#if PHP_VERSION_ID < 80400 +#include <ext/standard/php_random.h> +#else +#include <ext/random/php_random.h> +#endif + +#ifdef PHP_SESSION +#include <ext/session/php_session.h> +#endif + +#include "library.h" + +#ifdef HAVE_REDIS_ZSTD +#include <zstd.h> +#endif + +#ifdef HAVE_REDIS_LZ4 +#include <lz4.h> +#endif + +#ifdef PHP_SESSION +extern ps_module ps_mod_redis; +extern ps_module ps_mod_redis_cluster; +#endif + +zend_class_entry *redis_ce; +zend_class_entry *redis_exception_ce; + +#if PHP_VERSION_ID < 80000 +#include "redis_legacy_arginfo.h" +#else +#include "zend_attributes.h" +#include "redis_arginfo.h" +#endif + +extern const zend_function_entry *redis_get_methods(void) +{ + return class_Redis_methods; +} + +extern int le_cluster_slot_cache; +int le_redis_pconnect; + +PHP_INI_BEGIN() + /* redis arrays */ + PHP_INI_ENTRY("redis.arrays.algorithm", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.auth", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.autorehash", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.connecttimeout", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.distributor", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.functions", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.hosts", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.index", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.lazyconnect", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.names", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.pconnect", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.previous", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.readtimeout", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.retryinterval", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.arrays.consistent", "0", PHP_INI_ALL, NULL) + + /* redis cluster */ + PHP_INI_ENTRY("redis.clusters.cache_slots", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.clusters.auth", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.clusters.persistent", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.clusters.read_timeout", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.clusters.seeds", "", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.clusters.timeout", "0", PHP_INI_ALL, NULL) + + /* redis pconnect */ + PHP_INI_ENTRY("redis.pconnect.pooling_enabled", "1", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.pconnect.connection_limit", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.pconnect.echo_check_liveness", "1", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.pconnect.pool_detect_dirty", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.pconnect.pool_poll_timeout", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.pconnect.pool_pattern", "", PHP_INI_ALL, NULL) + + /* redis session */ + PHP_INI_ENTRY("redis.session.locking_enabled", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.lock_expire", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.lock_retries", "100", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.lock_wait_time", "20000", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.early_refresh", "0", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.compression", "none", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("redis.session.compression_level", "3", PHP_INI_ALL, NULL) +PHP_INI_END() + +static const zend_module_dep redis_deps = { +#ifdef HAVE_REDIS_IGBINARY + ZEND_MOD_REQUIRED("igbinary") +#endif +#ifdef HAVE_REDIS_MSGPACK + ZEND_MOD_REQUIRED("msgpack") +#endif +#ifdef HAVE_REDIS_JSON + ZEND_MOD_REQUIRED("json") +#endif +#ifdef PHP_SESSION + ZEND_MOD_REQUIRED("session") +#endif + ZEND_MOD_END +}; + +ZEND_DECLARE_MODULE_GLOBALS(redis) + +zend_module_entry redis_module_entry = { + STANDARD_MODULE_HEADER_EX, + NULL, + redis_deps, + "redis", + NULL, + PHP_MINIT(redis), + NULL, + NULL, + NULL, + PHP_MINFO(redis), + PHP_REDIS_VERSION, + PHP_MODULE_GLOBALS(redis), + NULL, + NULL, + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_REDIS +ZEND_GET_MODULE(redis) +#endif + +zend_object_handlers redis_object_handlers; + +/* Send a static DISCARD in case we're in MULTI mode. */ +static int +redis_send_discard(RedisSock *redis_sock) +{ + char *resp; + int resp_len, result = FAILURE; + + /* send our DISCARD command */ + if (redis_sock_write(redis_sock, ZEND_STRL(RESP_DISCARD_CMD)) >= 0 && + (resp = redis_sock_read(redis_sock,&resp_len)) != NULL) + { + /* success if we get OK */ + result = (resp_len == 3 && redis_strncmp(resp, ZEND_STRL("+OK")) == 0) ? SUCCESS:FAILURE; + + /* free our response */ + efree(resp); + } + + /* return success/failure */ + return result; +} + +/* Passthru for destroying cluster cache */ +static void cluster_cache_dtor(zend_resource *rsrc) { + if (rsrc->ptr) { + cluster_cache_free(rsrc->ptr); + } +} + +void +free_redis_object(zend_object *object) +{ + redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object); + + zend_object_std_dtor(&redis->std);
View file
redis-6.2.0.tgz/redis-6.2.0/redis.stub.php
Added
@@ -0,0 +1,4730 @@ +<?php + +/** + * @generate-function-entries + * @generate-legacy-arginfo + * @generate-class-entries + */ + +class Redis { + /** + * + * @var int + * @cvalue REDIS_NOT_FOUND + * + */ + public const REDIS_NOT_FOUND = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_STRING + * + */ + public const REDIS_STRING = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_SET + * + */ + public const REDIS_SET = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_LIST + * + */ + public const REDIS_LIST = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_ZSET + * + */ + public const REDIS_ZSET = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_HASH + * + */ + public const REDIS_HASH = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_STREAM + * + */ + public const REDIS_STREAM = UNKNOWN; + + /** + * + * @var int + * @cvalue ATOMIC + * + */ + public const ATOMIC = UNKNOWN; + + /** + * + * @var int + * @cvalue MULTI + * + */ + public const MULTI = UNKNOWN; + + /** + * + * @var int + * @cvalue PIPELINE + * + */ + public const PIPELINE = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_SERIALIZER + * + */ + public const OPT_SERIALIZER = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_PREFIX + * + */ + public const OPT_PREFIX = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_READ_TIMEOUT + * + */ + public const OPT_READ_TIMEOUT = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_TCP_KEEPALIVE + * + */ + public const OPT_TCP_KEEPALIVE = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_COMPRESSION + * + */ + public const OPT_COMPRESSION = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_REPLY_LITERAL + * + */ + public const OPT_REPLY_LITERAL = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_COMPRESSION_LEVEL + * + */ + public const OPT_COMPRESSION_LEVEL = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_OPT_NULL_MBULK_AS_NULL + * + */ + public const OPT_NULL_MULTIBULK_AS_NULL = UNKNOWN; + + /** + * @var int + * @cvalue REDIS_OPT_PACK_IGNORE_NUMBERS + * + * When enabled, this option tells PhpRedis to ignore purely numeric values + * when packing and unpacking data. This does not include numeric strings. + * If you want numeric strings to be ignored, typecast them to an int or float. + * + * The primary purpose of this option is to make it more ergonomic when + * setting keys that will later be incremented or decremented. + * + * Note: This option incurs a small performance penalty when reading data + * because we have to see if the data is a string representation of an int + * or float. + * + * @example + * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); + * $redis->setOption(Redis::OPT_PACK_IGNORE_NUMBERS, true); + * + * $redis->set('answer', 32); + * + * var_dump($redis->incrBy('answer', 10)); // int(42) + * var_dump($redis->get('answer')); // int(42) + */ + public const OPT_PACK_IGNORE_NUMBERS = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_SERIALIZER_NONE + * + */ + public const SERIALIZER_NONE = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_SERIALIZER_PHP + * + */ + public const SERIALIZER_PHP = UNKNOWN; + +#ifdef HAVE_REDIS_IGBINARY + /** + * + * @var int
View file
redis-6.2.0.tgz/redis-6.2.0/redis_arginfo.h
Added
@@ -0,0 +1,2089 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 805a66c17b7c9972c73a979bdd67f98f7c1f6c74 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___destruct, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis__compress, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis__uncompress arginfo_class_Redis__compress + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis__prefix, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis__serialize, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis__unserialize, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis__pack arginfo_class_Redis__serialize + +#define arginfo_class_Redis__unpack arginfo_class_Redis__unserialize + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_acl, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, subcmd, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_append, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_auth, 0, 1, Redis, MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, credentials, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bgSave, 0, 0, Redis, MAY_BE_BOOL) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_bgrewriteaof arginfo_class_Redis_bgSave + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_waitaof, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, numlocal, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, numreplicas, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bitcount, 0, 1, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, bybit, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bitop, 0, 3, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, operation, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, deskey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, srckey, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, other_keys, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bitpos, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, bit, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, bybit, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_blPop, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key_or_keys, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_MASK(0, timeout_or_key, MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_LONG, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_brPop arginfo_class_Redis_blPop + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_brpoplpush, 0, 3, Redis, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, src, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, dst, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, timeout, MAY_BE_LONG|MAY_BE_DOUBLE, NULL) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bzPopMax, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_MASK(0, timeout_or_key, MAY_BE_STRING|MAY_BE_LONG, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_bzPopMin arginfo_class_Redis_bzPopMax + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bzmpop, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, keys, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_zmpop, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, keys, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_blmpop arginfo_class_Redis_bzmpop + +#define arginfo_class_Redis_lmpop arginfo_class_Redis_zmpop + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_clearLastError, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_client, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, opt, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_close arginfo_class_Redis_clearLastError + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_command, 0, 0, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, opt, IS_STRING, 1, "null") + ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_config, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, operation, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, key_or_settings, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_connect, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 0, "6379") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent_id, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retry_interval, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, read_timeout, IS_DOUBLE, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, context, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_copy, 0, 2, Redis, MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, src, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, dst, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_dbSize, 0, 0, Redis, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_debug, 0, 1, Redis, MAY_BE_STRING) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_decr, 0, 1, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, by, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_decrBy, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_del, 0, 1, Redis, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, other_keys, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_delete arginfo_class_Redis_del + +#define arginfo_class_Redis_discard arginfo_class_Redis_bgSave + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_dump, 0, 1, Redis, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_echo, 0, 1, Redis, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_eval, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, script, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, args, IS_ARRAY, 0, "") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_keys, IS_LONG, 0, "0") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_eval_ro, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, script_sha, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, args, IS_ARRAY, 0, "") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_keys, IS_LONG, 0, "0")
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array.c
Added
@@ -0,0 +1,1295 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common.h" +#include "library.h" +#include "redis_array.h" +#include "redis_array_impl.h" + +#include <ext/standard/info.h> +#include <zend_exceptions.h> + +/* Simple macro to detect failure in a RedisArray call */ +#define RA_CALL_FAILED(rv, cmd) ( \ + (Z_TYPE_P(rv) == IS_FALSE) || \ + (Z_TYPE_P(rv) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(rv)) == 0) || \ + (Z_TYPE_P(rv) == IS_LONG && Z_LVAL_P(rv) == 0 && !strcasecmp(cmd, "TYPE")) \ +) + +extern zend_class_entry *redis_ce; +zend_class_entry *redis_array_ce; + +#if PHP_VERSION_ID < 80000 +#include "redis_array_legacy_arginfo.h" +#else +#include "zend_attributes.h" +#include "redis_array_arginfo.h" +#endif + +PHP_MINIT_FUNCTION(redis_array) +{ + /* RedisSentinel class */ + redis_array_ce = register_class_RedisArray(); + redis_array_ce->create_object = create_redis_array_object; + + return SUCCESS; +} + +static void +redis_array_free(RedisArray *ra) +{ + int i; + + /* continuum */ + if (ra->continuum) { + efree(ra->continuum->points); + efree(ra->continuum); + } + + /* Redis objects */ + for(i = 0; i< ra->count; i++) { + zval_dtor(&ra->redisi); + zend_string_release(ra->hostsi); + } + efree(ra->redis); + efree(ra->hosts); + + /* delete hash function */ + zval_dtor(&ra->z_fun); + + /* Distributor */ + zval_dtor(&ra->z_dist); + + /* Hashing algorithm */ + if (ra->algorithm) zend_string_release(ra->algorithm); + + /* Delete pur commands */ + zend_hash_destroy(ra->pure_cmds); + FREE_HASHTABLE(ra->pure_cmds); + + /* Free structure itself */ + efree(ra); +} + +typedef struct { + RedisArray *ra; + zend_object std; +} redis_array_object; + +zend_object_handlers redis_array_object_handlers; + +void +free_redis_array_object(zend_object *object) +{ + redis_array_object *obj = PHPREDIS_GET_OBJECT(redis_array_object, object); + + if (obj->ra) { + if (obj->ra->prev) redis_array_free(obj->ra->prev); + redis_array_free(obj->ra); + } + zend_object_std_dtor(&obj->std); +} + +zend_object * +create_redis_array_object(zend_class_entry *ce) +{ + redis_array_object *obj = ecalloc(1, sizeof(redis_array_object) + zend_object_properties_size(ce)); + + obj->ra = NULL; + + zend_object_std_init(&obj->std, ce); + object_properties_init(&obj->std, ce); + + memcpy(&redis_array_object_handlers, zend_get_std_object_handlers(), sizeof(redis_array_object_handlers)); + redis_array_object_handlers.offset = XtOffsetOf(redis_array_object, std); + redis_array_object_handlers.free_obj = free_redis_array_object; + obj->std.handlers = &redis_array_object_handlers; + + return &obj->std; +} + +/** + * redis_array_get + */ +PHP_REDIS_API RedisArray * +redis_array_get(zval *id) +{ + redis_array_object *obj; + + if (Z_TYPE_P(id) == IS_OBJECT) { + obj = PHPREDIS_ZVAL_GET_OBJECT(redis_array_object, id); + return obj->ra; + } + return NULL; +} + +/* {{{ proto RedisArray RedisArray::__construct() + Public constructor */ +PHP_METHOD(RedisArray, __construct) +{ + zval *z0, z_fun, z_dist, *zpData, *z_opts = NULL; + RedisArray *ra = NULL; + zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0, consistent = 0; + HashTable *hPrev = NULL, *hOpts = NULL; + zend_long l_retry_interval = 0; + zend_bool b_lazy_connect = 0; + double d_connect_timeout = 0, read_timeout = 0.0; + zend_string *algorithm = NULL, *user = NULL, *pass = NULL; + redis_array_object *obj; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a", &z0, &z_opts) == FAILURE) { + RETURN_FALSE; + } + + /* Bail if z0 isn't a string or an array. + * Note: WRONG_PARAM_COUNT seems wrong but this is what we have been doing + * for ages so we can't really change it until the next major version. + */ + if (Z_TYPE_P(z0) != IS_ARRAY && Z_TYPE_P(z0) != IS_STRING) { +#if PHP_VERSION_ID < 80000 + WRONG_PARAM_COUNT; +#else + zend_argument_type_error(1, "must be of type string|array, %s given", zend_zval_type_name(z0)); + RETURN_THROWS(); +#endif + } + + /* If it's a string we want to load the array from ini information */ + if (Z_TYPE_P(z0) == IS_STRING) { + ra = ra_load_array(Z_STRVAL_P(z0)); + goto finish; + } + + ZVAL_NULL(&z_fun); + ZVAL_NULL(&z_dist); + + /* extract options */ + if(z_opts) { + hOpts = Z_ARRVAL_P(z_opts); + + /* extract previous ring. */ + zpData = REDIS_HASH_STR_FIND_STATIC(hOpts, "previous"); + if (zpData && Z_TYPE_P(zpData) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zpData)) > 0) { + hPrev = Z_ARRVAL_P(zpData); + } + + + REDIS_CONF_AUTH_STATIC(hOpts, "auth", &user, &pass); + REDIS_CONF_ZVAL_STATIC(hOpts, "function", &z_fun, 1, 0); + REDIS_CONF_ZVAL_STATIC(hOpts, "distributor", &z_dist, 1, 0); + REDIS_CONF_STRING_STATIC(hOpts, "algorithm", &algorithm); + REDIS_CONF_ZEND_BOOL_STATIC(hOpts, "index", &b_index);
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array.h
Added
@@ -0,0 +1,43 @@ +#ifndef REDIS_ARRAY_H +#define REDIS_ARRAY_H + +#if (defined(_MSC_VER) && _MSC_VER <= 1920) +#include "win32/php_stdint.h" +#else +#include <stdint.h> +#endif +#include "common.h" + +typedef struct { + uint32_t value; + int index; +} ContinuumPoint; + +typedef struct { + size_t nb_points; + ContinuumPoint *points; +} Continuum; + +typedef struct RedisArray_ { + int count; + zend_string **hosts; /* array of host:port strings */ + zval *redis; /* array of Redis instances */ + zval *z_multi_exec; /* Redis instance to be used in multi-exec */ + zend_bool index; /* use per-node index */ + zend_bool auto_rehash; /* migrate keys on read operations */ + zend_bool pconnect; /* should we use pconnect */ + zval z_fun; /* key extractor, callable */ + zval z_dist; /* key distributor, callable */ + zend_string *algorithm; /* key hashing algorithm name */ + HashTable *pure_cmds; /* hash table */ + double connect_timeout; /* socket connect timeout */ + double read_timeout; /* socket read timeout */ + Continuum *continuum; + struct RedisArray_ *prev; +} RedisArray; + +extern zend_class_entry *redis_array_ce; +extern PHP_MINIT_FUNCTION(redis_array); +extern zend_object *create_redis_array_object(zend_class_entry *ce); + +#endif
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array.stub.php
Added
@@ -0,0 +1,72 @@ +<?php + +/** + * @generate-function-entries + * @generate-legacy-arginfo + * @generate-class-entries + */ + +class RedisArray { + + public function __call(string $function_name, array $arguments): mixed; + + public function __construct(string|array $name_or_hosts, ?array $options = null); + + public function _continuum(): bool|array; + + public function _distributor(): bool|callable; + + public function _function(): bool|callable; + + public function _hosts(): bool|array; + + public function _instance(string $host): bool|null|Redis; + + public function _rehash(?callable $fn = null): bool|null; + + public function _target(string $key): bool|string|null; + + public function bgsave(): array; + + public function del(string|array $key, string ...$otherkeys): bool|int; + + public function discard(): bool|null; + + public function exec(): bool|null|array; + + public function flushall(): bool|array; + + public function flushdb(): bool|array; + + public function getOption(int $opt): bool|array; + + public function hscan(string $key, null|int|string &$iterator, ?string $pattern = null, int $count = 0): bool|array; + + public function info(): bool|array; + + public function keys(string $pattern): bool|array; + + public function mget(array $keys): bool|array; + + public function mset(array $pairs): bool; + + public function multi(string $host, ?int $mode = null): bool|RedisArray; + + public function ping(): bool|array; + + public function save(): bool|array; + + public function scan(null|int|string &$iterator, string $node, ?string $pattern = null, int $count = 0): bool|array; + + public function select(int $index): bool|array; + + public function setOption(int $opt, string $value): bool|array; + + public function sscan(string $key, null|int|string &$iterator, ?string $pattern = null, int $count = 0): bool|array; + + public function unlink(string|array $key, string ...$otherkeys): bool|int; + + public function unwatch(): bool|null; + + public function zscan(string $key, null|int|string &$iterator, ?string $pattern = null, int $count = 0): bool|array; +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array_arginfo.h
Added
@@ -0,0 +1,189 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: ddb92422452cb767a7d6694aa8ac60d883db6672 */ + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray___call, 0, 2, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, arguments, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___construct, 0, 0, 1) + ZEND_ARG_TYPE_MASK(0, name_or_hosts, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray__continuum, 0, 0, MAY_BE_BOOL|MAY_BE_ARRAY) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray__distributor, 0, 0, MAY_BE_BOOL|MAY_BE_CALLABLE) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray__function arginfo_class_RedisArray__distributor + +#define arginfo_class_RedisArray__hosts arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisArray__instance, 0, 1, Redis, MAY_BE_BOOL|MAY_BE_NULL) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray__rehash, 0, 0, _IS_BOOL, 1) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fn, IS_CALLABLE, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray__target, 0, 1, MAY_BE_BOOL|MAY_BE_STRING|MAY_BE_NULL) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray_bgsave, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_del, 0, 1, MAY_BE_BOOL|MAY_BE_LONG) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, otherkeys, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray_discard, 0, 0, _IS_BOOL, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_exec, 0, 0, MAY_BE_BOOL|MAY_BE_NULL|MAY_BE_ARRAY) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_flushall arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_flushdb arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_getOption, 0, 1, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, opt, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_hscan, 0, 2, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(1, iterator, MAY_BE_NULL|MAY_BE_LONG|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0") +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_info arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_keys, 0, 1, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_mget, 0, 1, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, keys, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray_mset, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, pairs, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisArray_multi, 0, 1, RedisArray, MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 1, "null") +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_ping arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_save arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_scan, 0, 2, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_MASK(1, iterator, MAY_BE_NULL|MAY_BE_LONG|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO(0, node, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_select, 0, 1, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_setOption, 0, 2, MAY_BE_BOOL|MAY_BE_ARRAY) + ZEND_ARG_TYPE_INFO(0, opt, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_sscan arginfo_class_RedisArray_hscan + +#define arginfo_class_RedisArray_unlink arginfo_class_RedisArray_del + +#define arginfo_class_RedisArray_unwatch arginfo_class_RedisArray_discard + +#define arginfo_class_RedisArray_zscan arginfo_class_RedisArray_hscan + + +ZEND_METHOD(RedisArray, __call); +ZEND_METHOD(RedisArray, __construct); +ZEND_METHOD(RedisArray, _continuum); +ZEND_METHOD(RedisArray, _distributor); +ZEND_METHOD(RedisArray, _function); +ZEND_METHOD(RedisArray, _hosts); +ZEND_METHOD(RedisArray, _instance); +ZEND_METHOD(RedisArray, _rehash); +ZEND_METHOD(RedisArray, _target); +ZEND_METHOD(RedisArray, bgsave); +ZEND_METHOD(RedisArray, del); +ZEND_METHOD(RedisArray, discard); +ZEND_METHOD(RedisArray, exec); +ZEND_METHOD(RedisArray, flushall); +ZEND_METHOD(RedisArray, flushdb); +ZEND_METHOD(RedisArray, getOption); +ZEND_METHOD(RedisArray, hscan); +ZEND_METHOD(RedisArray, info); +ZEND_METHOD(RedisArray, keys); +ZEND_METHOD(RedisArray, mget); +ZEND_METHOD(RedisArray, mset); +ZEND_METHOD(RedisArray, multi); +ZEND_METHOD(RedisArray, ping); +ZEND_METHOD(RedisArray, save); +ZEND_METHOD(RedisArray, scan); +ZEND_METHOD(RedisArray, select); +ZEND_METHOD(RedisArray, setOption); +ZEND_METHOD(RedisArray, sscan); +ZEND_METHOD(RedisArray, unlink); +ZEND_METHOD(RedisArray, unwatch); +ZEND_METHOD(RedisArray, zscan); + + +static const zend_function_entry class_RedisArray_methods = { + ZEND_ME(RedisArray, __call, arginfo_class_RedisArray___call, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, __construct, arginfo_class_RedisArray___construct, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _continuum, arginfo_class_RedisArray__continuum, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _distributor, arginfo_class_RedisArray__distributor, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _function, arginfo_class_RedisArray__function, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _hosts, arginfo_class_RedisArray__hosts, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _instance, arginfo_class_RedisArray__instance, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _rehash, arginfo_class_RedisArray__rehash, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _target, arginfo_class_RedisArray__target, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, bgsave, arginfo_class_RedisArray_bgsave, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, del, arginfo_class_RedisArray_del, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, discard, arginfo_class_RedisArray_discard, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, exec, arginfo_class_RedisArray_exec, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, flushall, arginfo_class_RedisArray_flushall, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, flushdb, arginfo_class_RedisArray_flushdb, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, getOption, arginfo_class_RedisArray_getOption, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, hscan, arginfo_class_RedisArray_hscan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, info, arginfo_class_RedisArray_info, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, keys, arginfo_class_RedisArray_keys, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, mget, arginfo_class_RedisArray_mget, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, mset, arginfo_class_RedisArray_mset, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, multi, arginfo_class_RedisArray_multi, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, ping, arginfo_class_RedisArray_ping, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, save, arginfo_class_RedisArray_save, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, scan, arginfo_class_RedisArray_scan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, select, arginfo_class_RedisArray_select, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, setOption, arginfo_class_RedisArray_setOption, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, sscan, arginfo_class_RedisArray_sscan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, unlink, arginfo_class_RedisArray_unlink, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, unwatch, arginfo_class_RedisArray_unwatch, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, zscan, arginfo_class_RedisArray_zscan, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +static zend_class_entry *register_class_RedisArray(void) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "RedisArray", class_RedisArray_methods); + class_entry = zend_register_internal_class_ex(&ce, NULL); + + return class_entry; +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array_impl.c
Added
@@ -0,0 +1,1221 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + +----------------------------------------------------------------------+ +*/ +#include "redis_array_impl.h" +#include "php_redis.h" +#include "library.h" + +#include "php_variables.h" +#include "SAPI.h" +#include "ext/standard/url.h" +#include "ext/standard/crc32.h" +#include "ext/standard/md5.h" + +#include "ext/hash/php_hash.h" + +#define PHPREDIS_INDEX_NAME "__phpredis_array_index__" + +extern zend_class_entry *redis_ce; + +static RedisArray * +ra_load_hosts(RedisArray *ra, HashTable *hosts, zend_string *user, + zend_string *pass, long retry_interval, zend_bool b_lazy_connect) +{ + int i = 0, host_len; + char *host, *p; + short port; + zval *zpData; + redis_object *redis; + + /* init connections */ + ZEND_HASH_FOREACH_VAL(hosts, zpData) { + if (Z_TYPE_P(zpData) != IS_STRING) { + return NULL; + } + + /* default values */ + host = Z_STRVAL_P(zpData); + host_len = Z_STRLEN_P(zpData); + ra->hostsi = zend_string_init(host, host_len, 0); + port = 6379; + + if((p = strrchr(host, ':'))) { /* found port */ + host_len = p - host; + port = (short)atoi(p+1); + } else if(strchr(host,'/') != NULL) { /* unix socket */ + port = -1; + } + + /* create Redis object */ + object_init_ex(&ra->redisi, redis_ce); + redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, &ra->redisi); + + /* create socket */ + redis->sock = redis_sock_create(host, host_len, port, ra->connect_timeout, + ra->read_timeout, ra->pconnect, NULL, + retry_interval); + + redis_sock_set_auth(redis->sock, user, pass); + + if (!b_lazy_connect) { + if (redis_sock_server_open(redis->sock) < 0) { + ra->count = ++i; + return NULL; + } + } + + ra->count = ++i; + } ZEND_HASH_FOREACH_END(); + + return ra; +} + +/* List pure functions */ +void +ra_init_function_table(RedisArray *ra) +{ + ALLOC_HASHTABLE(ra->pure_cmds); + zend_hash_init(ra->pure_cmds, 0, NULL, NULL, 0); + + #define ra_add_pure_cmd(cmd) \ + zend_hash_str_update_ptr(ra->pure_cmds, cmd, sizeof(cmd) - 1, NULL); + + ra_add_pure_cmd("EXISTS"); + ra_add_pure_cmd("GET"); + ra_add_pure_cmd("GETBIT"); + ra_add_pure_cmd("GETRANGE"); + ra_add_pure_cmd("HEXISTS"); + ra_add_pure_cmd("HGET"); + ra_add_pure_cmd("HGETALL"); + ra_add_pure_cmd("HKEYS"); + ra_add_pure_cmd("HLEN"); + ra_add_pure_cmd("HMGET"); + ra_add_pure_cmd("HVALS"); + ra_add_pure_cmd("LINDEX"); + ra_add_pure_cmd("LLEN"); + ra_add_pure_cmd("LRANGE"); + ra_add_pure_cmd("OBJECT"); + ra_add_pure_cmd("SCARD"); + ra_add_pure_cmd("SDIFF"); + ra_add_pure_cmd("SINTER"); + ra_add_pure_cmd("SISMEMBER"); + ra_add_pure_cmd("SMEMBERS"); + ra_add_pure_cmd("SRANDMEMBER"); + ra_add_pure_cmd("STRLEN"); + ra_add_pure_cmd("SUNION"); + ra_add_pure_cmd("TYPE"); + ra_add_pure_cmd("ZCARD"); + ra_add_pure_cmd("ZCOUNT"); + ra_add_pure_cmd("ZRANGE"); + ra_add_pure_cmd("ZRANK"); + ra_add_pure_cmd("ZREVRANGE"); + ra_add_pure_cmd("ZREVRANGEBYSCORE"); + ra_add_pure_cmd("ZREVRANK"); + ra_add_pure_cmd("ZSCORE"); + + #undef ra_add_pure_cmd +} + +static int +ra_find_name(const char *name) { + + const char *ini_names, *p, *next; + /* php_printf("Loading redis array with name=%s\n", name); */ + + ini_names = INI_STR("redis.arrays.names"); + for(p = ini_names; p;) { + next = strchr(p, ','); + if(next) { + if(redis_strncmp(p, name, next - p) == 0) { + return 1; + } + } else { + if(strcmp(p, name) == 0) { + return 1; + } + break; + } + p = next + 1; + } + + return 0; +} + +/* load array from INI settings */ +RedisArray *ra_load_array(const char *name) { + zval *z_data, z_tmp, z_fun, z_dist; + zval z_params_hosts; + zval z_params_prev; + RedisArray *ra = NULL; + + zend_string *algorithm = NULL, *user = NULL, *pass = NULL; + zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0, consistent = 0; + zend_long l_retry_interval = 0; + zend_bool b_lazy_connect = 0; + double d_connect_timeout = 0, read_timeout = 0.0; + HashTable *hHosts = NULL, *hPrev = NULL; + size_t name_len = strlen(name); + char *iptr; + + /* find entry */ + if(!ra_find_name(name)) + return ra; + + ZVAL_NULL(&z_fun); + ZVAL_NULL(&z_dist); + + /* find hosts */ + array_init(&z_params_hosts); + if ((iptr = INI_STR("redis.arrays.hosts")) != NULL) { + sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_hosts); + if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_hosts), name, name_len)) != NULL) { + hHosts = Z_ARRVAL_P(z_data); + } + } + + /* find previous hosts */ + array_init(&z_params_prev); + if ((iptr = INI_STR("redis.arrays.previous")) != NULL) { + sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_prev); + if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_prev), name, name_len)) != NULL) { + if (Z_TYPE_P(z_data) == IS_ARRAY) { + hPrev = Z_ARRVAL_P(z_data); + } + } + } +
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array_impl.h
Changed
(renamed from redis-5.3.7/redis_array_impl.h)
View file
redis-6.2.0.tgz/redis-6.2.0/redis_array_legacy_arginfo.h
Added
@@ -0,0 +1,185 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: ddb92422452cb767a7d6694aa8ac60d883db6672 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___call, 0, 0, 2) + ZEND_ARG_INFO(0, function_name) + ZEND_ARG_INFO(0, arguments) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___construct, 0, 0, 1) + ZEND_ARG_INFO(0, name_or_hosts) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray__continuum, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray__distributor arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray__function arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray__hosts arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray__instance, 0, 0, 1) + ZEND_ARG_INFO(0, host) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray__rehash, 0, 0, 0) + ZEND_ARG_INFO(0, fn) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray__target, 0, 0, 1) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_bgsave arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_del, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_VARIADIC_INFO(0, otherkeys) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_discard arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_exec arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_flushall arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_flushdb arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_getOption, 0, 0, 1) + ZEND_ARG_INFO(0, opt) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_hscan, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(1, iterator) + ZEND_ARG_INFO(0, pattern) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_info arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_keys, 0, 0, 1) + ZEND_ARG_INFO(0, pattern) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_mget, 0, 0, 1) + ZEND_ARG_INFO(0, keys) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_mset, 0, 0, 1) + ZEND_ARG_INFO(0, pairs) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_multi, 0, 0, 1) + ZEND_ARG_INFO(0, host) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_ping arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_save arginfo_class_RedisArray__continuum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_scan, 0, 0, 2) + ZEND_ARG_INFO(1, iterator) + ZEND_ARG_INFO(0, node) + ZEND_ARG_INFO(0, pattern) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_select, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray_setOption, 0, 0, 2) + ZEND_ARG_INFO(0, opt) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisArray_sscan arginfo_class_RedisArray_hscan + +#define arginfo_class_RedisArray_unlink arginfo_class_RedisArray_del + +#define arginfo_class_RedisArray_unwatch arginfo_class_RedisArray__continuum + +#define arginfo_class_RedisArray_zscan arginfo_class_RedisArray_hscan + + +ZEND_METHOD(RedisArray, __call); +ZEND_METHOD(RedisArray, __construct); +ZEND_METHOD(RedisArray, _continuum); +ZEND_METHOD(RedisArray, _distributor); +ZEND_METHOD(RedisArray, _function); +ZEND_METHOD(RedisArray, _hosts); +ZEND_METHOD(RedisArray, _instance); +ZEND_METHOD(RedisArray, _rehash); +ZEND_METHOD(RedisArray, _target); +ZEND_METHOD(RedisArray, bgsave); +ZEND_METHOD(RedisArray, del); +ZEND_METHOD(RedisArray, discard); +ZEND_METHOD(RedisArray, exec); +ZEND_METHOD(RedisArray, flushall); +ZEND_METHOD(RedisArray, flushdb); +ZEND_METHOD(RedisArray, getOption); +ZEND_METHOD(RedisArray, hscan); +ZEND_METHOD(RedisArray, info); +ZEND_METHOD(RedisArray, keys); +ZEND_METHOD(RedisArray, mget); +ZEND_METHOD(RedisArray, mset); +ZEND_METHOD(RedisArray, multi); +ZEND_METHOD(RedisArray, ping); +ZEND_METHOD(RedisArray, save); +ZEND_METHOD(RedisArray, scan); +ZEND_METHOD(RedisArray, select); +ZEND_METHOD(RedisArray, setOption); +ZEND_METHOD(RedisArray, sscan); +ZEND_METHOD(RedisArray, unlink); +ZEND_METHOD(RedisArray, unwatch); +ZEND_METHOD(RedisArray, zscan); + + +static const zend_function_entry class_RedisArray_methods = { + ZEND_ME(RedisArray, __call, arginfo_class_RedisArray___call, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, __construct, arginfo_class_RedisArray___construct, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _continuum, arginfo_class_RedisArray__continuum, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _distributor, arginfo_class_RedisArray__distributor, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _function, arginfo_class_RedisArray__function, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _hosts, arginfo_class_RedisArray__hosts, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _instance, arginfo_class_RedisArray__instance, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _rehash, arginfo_class_RedisArray__rehash, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, _target, arginfo_class_RedisArray__target, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, bgsave, arginfo_class_RedisArray_bgsave, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, del, arginfo_class_RedisArray_del, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, discard, arginfo_class_RedisArray_discard, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, exec, arginfo_class_RedisArray_exec, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, flushall, arginfo_class_RedisArray_flushall, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, flushdb, arginfo_class_RedisArray_flushdb, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, getOption, arginfo_class_RedisArray_getOption, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, hscan, arginfo_class_RedisArray_hscan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, info, arginfo_class_RedisArray_info, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, keys, arginfo_class_RedisArray_keys, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, mget, arginfo_class_RedisArray_mget, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, mset, arginfo_class_RedisArray_mset, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, multi, arginfo_class_RedisArray_multi, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, ping, arginfo_class_RedisArray_ping, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, save, arginfo_class_RedisArray_save, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, scan, arginfo_class_RedisArray_scan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, select, arginfo_class_RedisArray_select, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, setOption, arginfo_class_RedisArray_setOption, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, sscan, arginfo_class_RedisArray_sscan, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, unlink, arginfo_class_RedisArray_unlink, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, unwatch, arginfo_class_RedisArray_unwatch, ZEND_ACC_PUBLIC) + ZEND_ME(RedisArray, zscan, arginfo_class_RedisArray_zscan, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +static zend_class_entry *register_class_RedisArray(void) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "RedisArray", class_RedisArray_methods); + class_entry = zend_register_internal_class_ex(&ce, NULL); + + return class_entry; +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_cluster.c
Added
@@ -0,0 +1,3198 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Michael Grunder <michael.grunder@gmail.com> | + | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "common.h" +#include "php_redis.h" +#include "ext/standard/info.h" +#include "crc16.h" +#include "redis_cluster.h" +#include "redis_commands.h" +#include <ext/spl/spl_exceptions.h> +#include <zend_exceptions.h> +#include "library.h" +#include <php_variables.h> +#include <SAPI.h> + +zend_class_entry *redis_cluster_ce; + +/* Exception handler */ +zend_class_entry *redis_cluster_exception_ce; + +#if PHP_VERSION_ID < 80000 +#include "redis_cluster_legacy_arginfo.h" +#else +#include "zend_attributes.h" +#include "redis_cluster_arginfo.h" +#endif + +PHP_MINIT_FUNCTION(redis_cluster) +{ + redis_cluster_ce = register_class_RedisCluster(); + redis_cluster_ce->create_object = create_cluster_context; + + redis_cluster_exception_ce = register_class_RedisClusterException(spl_ce_RuntimeException); + + return SUCCESS; +} + +/* Handlers for RedisCluster */ +zend_object_handlers RedisCluster_handlers; + +/* Our context seeds will be a hash table with RedisSock* pointers */ +static void ht_free_seed(zval *data) { + RedisSock *redis_sock = *(RedisSock**)data; + if (redis_sock) redis_free_socket(redis_sock); +} + +/* Free redisClusterNode objects we've stored */ +static void ht_free_node(zval *data) { + redisClusterNode *node = *(redisClusterNode**)data; + cluster_free_node(node); +} + +/* Create redisCluster context */ +zend_object * create_cluster_context(zend_class_entry *class_type) { + redisCluster *cluster; + + // Allocate our actual struct + cluster = ecalloc(1, sizeof(redisCluster) + zend_object_properties_size(class_type)); + + // We're not currently subscribed anywhere + cluster->subscribed_slot = -1; + + // Allocate our RedisSock we'll use to store prefix/serialization flags + cluster->flags = ecalloc(1, sizeof(RedisSock)); + + // Allocate our hash table for seeds + ALLOC_HASHTABLE(cluster->seeds); + zend_hash_init(cluster->seeds, 0, NULL, ht_free_seed, 0); + + // Allocate our hash table for connected Redis objects + ALLOC_HASHTABLE(cluster->nodes); + zend_hash_init(cluster->nodes, 0, NULL, ht_free_node, 0); + + // Initialize it + zend_object_std_init(&cluster->std, class_type); + + object_properties_init(&cluster->std, class_type); + memcpy(&RedisCluster_handlers, zend_get_std_object_handlers(), sizeof(RedisCluster_handlers)); + RedisCluster_handlers.offset = XtOffsetOf(redisCluster, std); + RedisCluster_handlers.free_obj = free_cluster_context; + + cluster->std.handlers = &RedisCluster_handlers; + + return &cluster->std; +} + +/* Free redisCluster context */ +void free_cluster_context(zend_object *object) { + redisCluster *cluster = PHPREDIS_GET_OBJECT(redisCluster, object); + + cluster_free(cluster, 0); + zend_object_std_dtor(&cluster->std); +} + +/* Take user provided seeds and return unique and valid ones */ +/* Attempt to connect to a Redis cluster provided seeds and timeout options */ +static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout, + double read_timeout, int persistent, zend_string *user, + zend_string *pass, zval *context) +{ + zend_string *hash = NULL, **seeds; + redisCachedCluster *cc; + uint32_t nseeds; + char *err; + + /* Validate our arguments and get a sanitized seed array */ + seeds = cluster_validate_args(timeout, read_timeout, ht_seeds, &nseeds, &err); + if (seeds == NULL) { + CLUSTER_THROW_EXCEPTION(err, 0); + return; + } + + if (user && ZSTR_LEN(user)) + c->flags->user = zend_string_copy(user); + if (pass && ZSTR_LEN(pass)) + c->flags->pass = zend_string_copy(pass); + if (context) { + redis_sock_set_stream_context(c->flags, context); + } + + c->flags->timeout = timeout; + c->flags->read_timeout = read_timeout; + c->flags->persistent = persistent; + c->waitms = (long)(1000 * (timeout + read_timeout)); + + /* Attempt to load slots from cache if caching is enabled */ + if (CLUSTER_CACHING_ENABLED()) { + /* Exit early if we can load from cache */ + hash = cluster_hash_seeds(seeds, nseeds); + if ((cc = cluster_cache_load(hash))) { + cluster_init_cache(c, cc); + goto cleanup; + } + } + + /* Initialize seeds and attempt to map keyspace */ + cluster_init_seeds(c, seeds, nseeds); + if (cluster_map_keyspace(c) == SUCCESS && hash) + cluster_cache_store(hash, c->nodes); + +cleanup: + if (hash) zend_string_release(hash); + free_seed_array(seeds, nseeds); +} + + +/* Attempt to load a named cluster configured in php.ini */ +void redis_cluster_load(redisCluster *c, char *name, int name_len) { + zval z_seeds, z_tmp, *z_value; + zend_string *user = NULL, *pass = NULL; + double timeout = 0, read_timeout = 0; + int persistent = 0; + char *iptr; + HashTable *ht_seeds = NULL; + + /* Seeds */ + array_init(&z_seeds); + if ((iptr = INI_STR("redis.clusters.seeds")) != NULL) { + sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_seeds); + } + if ((z_value = zend_hash_str_find(Z_ARRVAL(z_seeds), name, name_len)) != NULL) { + ht_seeds = Z_ARRVAL_P(z_value); + } else { + zval_dtor(&z_seeds); + CLUSTER_THROW_EXCEPTION("Couldn't find seeds for cluster", 0); + return; + } + + /* Connection timeout */ + if ((iptr = INI_STR("redis.clusters.timeout")) != NULL) { + array_init(&z_tmp); + sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp); + redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &timeout); + zval_dtor(&z_tmp); + } + + /* Read timeout */ + if ((iptr = INI_STR("redis.clusters.read_timeout")) != NULL) { + array_init(&z_tmp); + sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp); + redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &read_timeout);
View file
redis-6.2.0.tgz/redis-6.2.0/redis_cluster.h
Added
@@ -0,0 +1,101 @@ +#ifndef REDIS_CLUSTER_H +#define REDIS_CLUSTER_H + +#include "cluster_library.h" +#include <php.h> +#include <stddef.h> + +/* Get attached object context */ +#define GET_CONTEXT() PHPREDIS_ZVAL_GET_OBJECT(redisCluster, getThis()) + +/* Command building/processing is identical for every command */ +#define CLUSTER_BUILD_CMD(name, c, cmd, cmd_len, slot) \ + redis_##name##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &cmd, \ + &cmd_len, &slot) + +/* Append information required to handle MULTI commands to the tail of our MULTI + * linked list. */ +#define CLUSTER_ENQUEUE_RESPONSE(c, slot, cb, ctx) \ + clusterFoldItem *_item; \ + _item = emalloc(sizeof(clusterFoldItem)); \ + _item->callback = cb; \ + _item->slot = slot; \ + _item->ctx = ctx; \ + _item->next = NULL; \ + _item->flags = c->flags->flags; \ + if(c->multi_head == NULL) { \ + c->multi_head = _item; \ + c->multi_curr = _item; \ + } else { \ + c->multi_curr->next = _item; \ + c->multi_curr = _item; \ + } \ + +/* Simple macro to free our enqueued callbacks after we EXEC */ +#define CLUSTER_FREE_QUEUE(c) \ + clusterFoldItem *_item = c->multi_head, *_tmp; \ + while(_item) { \ + _tmp = _item->next; \ + efree(_item); \ + _item = _tmp; \ + } \ + c->multi_head = c->multi_curr = NULL; \ + +/* Reset anything flagged as MULTI */ +#define CLUSTER_RESET_MULTI(c) \ + redisClusterNode *_node; \ + ZEND_HASH_FOREACH_PTR(c->nodes, _node) { \ + if (_node == NULL) break; \ + _node->sock->watching = 0; \ + _node->sock->mode = ATOMIC; \ + } ZEND_HASH_FOREACH_END(); \ + c->flags->watching = 0; \ + c->flags->mode = ATOMIC; \ + +/* Simple 1-1 command -> response macro */ +#define CLUSTER_PROCESS_CMD(cmdname, resp_func, readcmd) \ + redisCluster *c = GET_CONTEXT(); \ + c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \ + char *cmd; int cmd_len; short slot; void *ctx=NULL; \ + if(redis_##cmdname##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,c->flags, &cmd, \ + &cmd_len, &slot, &ctx)==FAILURE) { \ + RETURN_FALSE; \ + } \ + if(cluster_send_command(c,slot,cmd,cmd_len)<0 || c->err!=NULL) {\ + efree(cmd); \ + RETURN_FALSE; \ + } \ + efree(cmd); \ + if(c->flags->mode == MULTI) { \ + CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_func, ctx); \ + RETURN_ZVAL(getThis(), 1, 0); \ + } \ + resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx); + +/* More generic processing, where only the keyword differs */ +#define CLUSTER_PROCESS_KW_CMD(kw, cmdfunc, resp_func, readcmd) \ + redisCluster *c = GET_CONTEXT(); \ + c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \ + char *cmd; int cmd_len; short slot; void *ctx=NULL; \ + if(cmdfunc(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,\ + &slot,&ctx)==FAILURE) { \ + RETURN_FALSE; \ + } \ + if(cluster_send_command(c,slot,cmd,cmd_len)<0 || c->err!=NULL) { \ + efree(cmd); \ + RETURN_FALSE; \ + } \ + efree(cmd); \ + if(c->flags->mode == MULTI) { \ + CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_func, ctx); \ + RETURN_ZVAL(getThis(), 1, 0); \ + } \ + resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx); + +extern zend_class_entry *redis_cluster_ce; +extern zend_class_entry *redis_cluster_exception_ce; +extern PHP_MINIT_FUNCTION(redis_cluster); +extern zend_object * create_cluster_context(zend_class_entry *class_type); +extern void free_cluster_context(zend_object *object); + +#endif
View file
redis-6.2.0.tgz/redis-6.2.0/redis_cluster.stub.php
Added
@@ -0,0 +1,1220 @@ +<?php + +/** + * @generate-function-entries + * @generate-legacy-arginfo + * @generate-class-entries + */ + +class RedisCluster { + /** + * + * @var int + * @cvalue REDIS_OPT_FAILOVER + * + */ + public const OPT_SLAVE_FAILOVER = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_FAILOVER_NONE + * + */ + public const FAILOVER_NONE = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_FAILOVER_ERROR + * + */ + public const FAILOVER_ERROR = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_FAILOVER_DISTRIBUTE + * + */ + public const FAILOVER_DISTRIBUTE = UNKNOWN; + + /** + * + * @var int + * @cvalue REDIS_FAILOVER_DISTRIBUTE_SLAVES + * + */ + public const FAILOVER_DISTRIBUTE_SLAVES = UNKNOWN; + + public function __construct(string|null $name, ?array $seeds = null, int|float $timeout = 0, int|float $read_timeout = 0, bool $persistent = false, #\SensitiveParameter mixed $auth = null, ?array $context = null); + + /** + * @see Redis::_compress() + */ + public function _compress(string $value): string; + + /** + * @see Redis::_uncompress() + */ + public function _uncompress(string $value): string; + + /** + * @see Redis::_serialize() + */ + public function _serialize(mixed $value): bool|string; + + /** + * @see Redis::_unserialize() + */ + public function _unserialize(string $value): mixed; + + /** + * @see Redis::_pack() + */ + public function _pack(mixed $value): string; + + /** + * @see Redis::_unpack() + */ + public function _unpack(string $value): mixed; + + /** + * @see Redis::_prefix() + */ + public function _prefix(string $key): bool|string; + + public function _masters(): array; + + public function _redir(): string|null; + + /** + * @see Redis::acl + */ + public function acl(string|array $key_or_address, string $subcmd, string ...$args): mixed; + + /** + * @see Redis::append() + */ + public function append(string $key, mixed $value): RedisCluster|bool|int; + + /** + * @see Redis::bgrewriteaof + */ + public function bgrewriteaof(string|array $key_or_address): RedisCluster|bool; + + public function waitaof(string|array $key_or_address, int $numlocal, + int $numreplicas, int $timeout): RedisCluster|array|false; + + /** + * @see Redis::bgsave + */ + public function bgsave(string|array $key_or_address): RedisCluster|bool; + + /** + * @see Redis::bitcount + */ + public function bitcount(string $key, int $start = 0, int $end = -1, bool $bybit = false): RedisCluster|bool|int; + + /** + * @see Redis::bitop + */ + public function bitop(string $operation, string $deskey, string $srckey, string ...$otherkeys): RedisCluster|bool|int; + + /** + * Return the position of the first bit set to 0 or 1 in a string. + * + * @see https://https://redis.io/commands/bitpos/ + * + * @param string $key The key to check (must be a string) + * @param bool $bit Whether to look for an unset (0) or set (1) bit. + * @param int $start Where in the string to start looking. + * @param int $end Where in the string to stop looking. + * @param bool $bybit If true, Redis will treat $start and $end as BIT values and not bytes, so if start + * was 0 and end was 2, Redis would only search the first two bits. + */ + public function bitpos(string $key, bool $bit, int $start = 0, int $end = -1, bool $bybit = false): RedisCluster|int|false; + + /** + * See Redis::blpop() + */ + public function blpop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args): RedisCluster|array|null|false; + + /** + * See Redis::brpop() + */ + public function brpop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args): RedisCluster|array|null|false; + + /** + * See Redis::brpoplpush() + */ + public function brpoplpush(string $srckey, string $deskey, int $timeout): mixed; + + /** + * Move an element from one list into another. + * + * @see Redis::lmove + */ + public function lmove(string $src, string $dst, string $wherefrom, string $whereto): Redis|string|false; + + /** + * Move an element from one list to another, blocking up to a timeout until an element is available. + * + * @see Redis::blmove + * + */ + public function blmove(string $src, string $dst, string $wherefrom, string $whereto, float $timeout): Redis|string|false; + + /** + * @see Redis::bzpopmax + */ + public function bzpopmax(string|array $key, string|int $timeout_or_key, mixed ...$extra_args): array; + + /** + * @see Redis::bzpopmin + */ + public function bzpopmin(string|array $key, string|int $timeout_or_key, mixed ...$extra_args): array; + + /** + * @see Redis::bzmpop + */ + public function bzmpop(float $timeout, array $keys, string $from, int $count = 1): RedisCluster|array|null|false; + + /** + * @see Redis::zmpop + */ + public function zmpop(array $keys, string $from, int $count = 1): RedisCluster|array|null|false; + + /** + * @see Redis::blmpop() + */ + public function blmpop(float $timeout, array $keys, string $from, int $count = 1): RedisCluster|array|null|false; + + /** + * @see Redis::lmpop() + */ + public function lmpop(array $keys, string $from, int $count = 1): RedisCluster|array|null|false; + + /** + * @see Redis::clearlasterror()
View file
redis-6.2.0.tgz/redis-6.2.0/redis_cluster_arginfo.h
Added
@@ -0,0 +1,1588 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 43a43fa735ced4b48a361078ac8a10fb62cb1244 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, seeds, IS_ARRAY, 1, "null") + ZEND_ARG_TYPE_MASK(0, timeout, MAY_BE_LONG|MAY_BE_DOUBLE, "0") + ZEND_ARG_TYPE_MASK(0, read_timeout, MAY_BE_LONG|MAY_BE_DOUBLE, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent, _IS_BOOL, 0, "false") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, auth, IS_MIXED, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, context, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster__compress, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster__uncompress arginfo_class_RedisCluster__compress + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster__serialize, 0, 1, MAY_BE_BOOL|MAY_BE_STRING) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster__unserialize, 0, 1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster__pack, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster__unpack arginfo_class_RedisCluster__unserialize + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster__prefix, 0, 1, MAY_BE_BOOL|MAY_BE_STRING) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster__masters, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster__redir, 0, 0, IS_STRING, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_acl, 0, 2, IS_MIXED, 0) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO(0, subcmd, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_append, 0, 2, RedisCluster, MAY_BE_BOOL|MAY_BE_LONG) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bgrewriteaof, 0, 1, RedisCluster, MAY_BE_BOOL) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_waitaof, 0, 4, RedisCluster, MAY_BE_ARRAY|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO(0, numlocal, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, numreplicas, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_bgsave arginfo_class_RedisCluster_bgrewriteaof + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bitcount, 0, 1, RedisCluster, MAY_BE_BOOL|MAY_BE_LONG) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, bybit, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bitop, 0, 3, RedisCluster, MAY_BE_BOOL|MAY_BE_LONG) + ZEND_ARG_TYPE_INFO(0, operation, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, deskey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, srckey, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, otherkeys, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bitpos, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, bit, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, bybit, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_blpop, 0, 2, RedisCluster, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_MASK(0, timeout_or_key, MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_LONG, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_brpop arginfo_class_RedisCluster_blpop + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_brpoplpush, 0, 3, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, srckey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, deskey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_lmove, 0, 4, Redis, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, src, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, dst, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, wherefrom, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, whereto, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_blmove, 0, 5, Redis, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, src, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, dst, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, wherefrom, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, whereto, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_bzpopmax, 0, 2, IS_ARRAY, 0) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_MASK(0, timeout_or_key, MAY_BE_STRING|MAY_BE_LONG, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_bzpopmin arginfo_class_RedisCluster_bzpopmax + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bzmpop, 0, 3, RedisCluster, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, keys, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_zmpop, 0, 2, RedisCluster, MAY_BE_ARRAY|MAY_BE_NULL|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, keys, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_blmpop arginfo_class_RedisCluster_bzmpop + +#define arginfo_class_RedisCluster_lmpop arginfo_class_RedisCluster_zmpop + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_clearlasterror, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster_client, 0, 2, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_BOOL) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO(0, subcommand, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg, IS_STRING, 1, "null") +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_close arginfo_class_RedisCluster_clearlasterror + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_cluster, 0, 2, IS_MIXED, 0) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_command, 0, 0, IS_MIXED, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_config, 0, 2, IS_MIXED, 0) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) + ZEND_ARG_TYPE_INFO(0, subcommand, IS_STRING, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, extra_args, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_dbsize, 0, 1, RedisCluster, MAY_BE_LONG) + ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_copy, 0, 2, RedisCluster, MAY_BE_BOOL) + ZEND_ARG_TYPE_INFO(0, src, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, dst, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_decr, 0, 1, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, by, IS_LONG, 0, "1") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_decrby, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_decrbyfloat, 0, 2, IS_DOUBLE, 0) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_DOUBLE, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_del, 0, 1, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_TYPE_MASK(0, key, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_VARIADIC_TYPE_INFO(0, other_keys, IS_STRING, 0) +ZEND_END_ARG_INFO()
View file
redis-6.2.0.tgz/redis-6.2.0/redis_cluster_legacy_arginfo.h
Added
@@ -0,0 +1,1423 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 43a43fa735ced4b48a361078ac8a10fb62cb1244 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, seeds) + ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, read_timeout) + ZEND_ARG_INFO(0, persistent) + ZEND_ARG_INFO(0, auth) + ZEND_ARG_INFO(0, context) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster__compress, 0, 0, 1) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster__uncompress arginfo_class_RedisCluster__compress + +#define arginfo_class_RedisCluster__serialize arginfo_class_RedisCluster__compress + +#define arginfo_class_RedisCluster__unserialize arginfo_class_RedisCluster__compress + +#define arginfo_class_RedisCluster__pack arginfo_class_RedisCluster__compress + +#define arginfo_class_RedisCluster__unpack arginfo_class_RedisCluster__compress + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster__prefix, 0, 0, 1) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster__masters, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster__redir arginfo_class_RedisCluster__masters + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_acl, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, subcmd) + ZEND_ARG_VARIADIC_INFO(0, args) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_append, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bgrewriteaof, 0, 0, 1) + ZEND_ARG_INFO(0, key_or_address) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_waitaof, 0, 0, 4) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, numlocal) + ZEND_ARG_INFO(0, numreplicas) + ZEND_ARG_INFO(0, timeout) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_bgsave arginfo_class_RedisCluster_bgrewriteaof + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bitcount, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, start) + ZEND_ARG_INFO(0, end) + ZEND_ARG_INFO(0, bybit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bitop, 0, 0, 3) + ZEND_ARG_INFO(0, operation) + ZEND_ARG_INFO(0, deskey) + ZEND_ARG_INFO(0, srckey) + ZEND_ARG_VARIADIC_INFO(0, otherkeys) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bitpos, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, bit) + ZEND_ARG_INFO(0, start) + ZEND_ARG_INFO(0, end) + ZEND_ARG_INFO(0, bybit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_blpop, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, timeout_or_key) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_brpop arginfo_class_RedisCluster_blpop + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_brpoplpush, 0, 0, 3) + ZEND_ARG_INFO(0, srckey) + ZEND_ARG_INFO(0, deskey) + ZEND_ARG_INFO(0, timeout) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_lmove, 0, 0, 4) + ZEND_ARG_INFO(0, src) + ZEND_ARG_INFO(0, dst) + ZEND_ARG_INFO(0, wherefrom) + ZEND_ARG_INFO(0, whereto) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_blmove, 0, 0, 5) + ZEND_ARG_INFO(0, src) + ZEND_ARG_INFO(0, dst) + ZEND_ARG_INFO(0, wherefrom) + ZEND_ARG_INFO(0, whereto) + ZEND_ARG_INFO(0, timeout) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_bzpopmax arginfo_class_RedisCluster_blpop + +#define arginfo_class_RedisCluster_bzpopmin arginfo_class_RedisCluster_blpop + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bzmpop, 0, 0, 3) + ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, keys) + ZEND_ARG_INFO(0, from) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_zmpop, 0, 0, 2) + ZEND_ARG_INFO(0, keys) + ZEND_ARG_INFO(0, from) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_blmpop arginfo_class_RedisCluster_bzmpop + +#define arginfo_class_RedisCluster_lmpop arginfo_class_RedisCluster_zmpop + +#define arginfo_class_RedisCluster_clearlasterror arginfo_class_RedisCluster__masters + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_client, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, subcommand) + ZEND_ARG_INFO(0, arg) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_close arginfo_class_RedisCluster__masters + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_cluster, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, command) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_command, 0, 0, 0) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_config, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, subcommand) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_dbsize arginfo_class_RedisCluster_bgrewriteaof + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_copy, 0, 0, 2) + ZEND_ARG_INFO(0, src) + ZEND_ARG_INFO(0, dst) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_decr, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, by) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_decrby arginfo_class_RedisCluster_append + +#define arginfo_class_RedisCluster_decrbyfloat arginfo_class_RedisCluster_append + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_del, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_VARIADIC_INFO(0, other_keys) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_discard arginfo_class_RedisCluster__masters + +#define arginfo_class_RedisCluster_dump arginfo_class_RedisCluster__prefix + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_echo, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_address) + ZEND_ARG_INFO(0, msg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_eval, 0, 0, 1) + ZEND_ARG_INFO(0, script) + ZEND_ARG_INFO(0, args) + ZEND_ARG_INFO(0, num_keys) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisCluster_eval_ro arginfo_class_RedisCluster_eval + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_evalsha, 0, 0, 1) + ZEND_ARG_INFO(0, script_sha)
View file
redis-6.2.0.tgz/redis-6.2.0/redis_commands.c
Added
@@ -0,0 +1,6472 @@ +/* -*- Mode: C; tab-width: 4 -*- */ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Original Author: Michael Grunder <michael.grunder@gmail.com | + | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "redis_commands.h" + +#include "php_network.h" + +#ifndef PHP_WIN32 +#include <netinet/tcp.h> /* TCP_KEEPALIVE */ +#else +#include <winsock.h> +#endif + +#include <zend_exceptions.h> + +/* Georadius sort type */ +typedef enum geoSortType { + SORT_NONE, + SORT_ASC, + SORT_DESC +} geoSortType; + +/* Georadius store type */ +typedef enum geoStoreType { + STORE_NONE, + STORE_COORD, + STORE_DIST +} geoStoreType; + +/* Georadius options structure */ +typedef struct geoOptions { + int withcoord; + int withdist; + int withhash; + long count; + zend_bool any; + geoSortType sort; + geoStoreType store; + zend_string *key; +} geoOptions; + +typedef struct redisLcsOptions { + zend_bool len; + zend_bool idx; + zend_long minmatchlen; + zend_bool withmatchlen; +} redisLcsOptions; + +typedef struct redisRestoreOptions { + zend_bool replace; + zend_bool absttl; + zend_long idletime; + zend_long freq; +} redisRestoreOptions; + +#define REDIS_ZCMD_HAS_DST_KEY (1 << 0) +#define REDIS_ZCMD_HAS_WITHSCORES (1 << 1) +#define REDIS_ZCMD_HAS_BY_LEX_SCORE (1 << 2) +#define REDIS_ZCMD_HAS_REV (1 << 3) +#define REDIS_ZCMD_HAS_LIMIT (1 << 4) +#define REDIS_ZCMD_INT_RANGE (1 << 5) +#define REDIS_ZCMD_HAS_AGGREGATE (1 << 6) + +/* ZRANGE, ZRANGEBYSCORE, ZRANGESTORE options */ +typedef struct redisZcmdOptions { + zend_bool withscores; + zend_bool byscore; + zend_bool bylex; + zend_bool rev; + zend_string *aggregate; + struct { + zend_bool enabled; + zend_long offset; + zend_long count; + } limit; +} redisZcmdOptions; + +/* Local passthrough macro for command construction. Given that these methods + * are generic (so they work whether the caller is Redis or RedisCluster) we + * will always have redis_sock, slot*, and */ +#define REDIS_CMD_SPPRINTF(ret, kw, fmt, ...) \ + redis_spprintf(redis_sock, slot, ret, kw, fmt, ##__VA_ARGS__) + +/* Generic commands based on method signature and what kind of things we're + * processing. Lots of Redis commands take something like key, value, or + * key, value long. Each unique signature like this is written only once */ + +/* A command that takes no arguments */ +int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, + void **ctx) +{ + *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, ""); + return SUCCESS; +} + +/* Helper to construct a raw command. Given that the cluster and non cluster + * versions are different (RedisCluster needs an additional argument to direct + * the command) we take the start of our array and count */ +int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len) +{ + smart_string cmdstr = {0}; + int i; + + /* Make sure our first argument is a string */ + if (Z_TYPE(z_args0) != IS_STRING) { + php_error_docref(NULL, E_WARNING, + "When sending a 'raw' command, the first argument must be a string!"); + return FAILURE; + } + + /* Initialize our command string */ + redis_cmd_init_sstr(&cmdstr, argc-1, Z_STRVAL(z_args0), Z_STRLEN(z_args0)); + + for (i = 1; i < argc; i++) { + switch (Z_TYPE(z_argsi)) { + case IS_STRING: + redis_cmd_append_sstr(&cmdstr, Z_STRVAL(z_argsi), + Z_STRLEN(z_argsi)); + break; + case IS_LONG: + redis_cmd_append_sstr_long(&cmdstr,Z_LVAL(z_argsi)); + break; + case IS_DOUBLE: + redis_cmd_append_sstr_dbl(&cmdstr,Z_DVAL(z_argsi)); + break; + default: + php_error_docref(NULL, E_WARNING, + "Raw command arguments must be scalar values!"); + efree(cmdstr.c); + return FAILURE; + } + } + + /* Push command and length to caller */ + *cmd = cmdstr.c; + *cmd_len = cmdstr.len; + + return SUCCESS; +} + +smart_string * +redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args) +{ + int i; + zend_string *zstr; + + if (Z_TYPE(z_args0) != IS_STRING) { + return NULL; + } + // Branch based on the directive + if (zend_string_equals_literal_ci(Z_STR(z_args0), "kill")) { + // Simple SCRIPT_KILL command + REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); + redis_cmd_append_sstr(cmd, ZEND_STRL("KILL")); + } else if (zend_string_equals_literal_ci(Z_STR(z_args0), "flush")) { + // Simple SCRIPT FLUSH ASYNC | SYNC + if (argc > 1 && ( + Z_TYPE(z_args1) != IS_STRING || ( + !zend_string_equals_literal_ci(Z_STR(z_args1), "sync") && + !zend_string_equals_literal_ci(Z_STR(z_args1), "async") + ) + )) { + return NULL; + } + REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); + redis_cmd_append_sstr(cmd, ZEND_STRL("FLUSH")); + if (argc > 1) { + redis_cmd_append_sstr(cmd, Z_STRVAL(z_args1), Z_STRLEN(z_args1)); + } + } else if (zend_string_equals_literal_ci(Z_STR(z_args0), "load")) { + // Make sure we have a second argument, and it's not empty. If it is + // empty, we can just return an empty array (which is what Redis does) + if (argc < 2 || Z_TYPE(z_args1) != IS_STRING || Z_STRLEN(z_args1) < 1) { + return NULL; + } + // Format our SCRIPT LOAD command + REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT"); + redis_cmd_append_sstr(cmd, ZEND_STRL("LOAD")); + redis_cmd_append_sstr(cmd, Z_STRVAL(z_args1), Z_STRLEN(z_args1));
View file
redis-6.2.0.tgz/redis-6.2.0/redis_commands.h
Added
@@ -0,0 +1,408 @@ +#ifndef REDIS_COMMANDS_H +#define REDIS_COMMANDS_H + +#include "common.h" +#include "library.h" +#include "cluster_library.h" + +/* Pick a random slot, any slot (for stuff like publish/subscribe) */ +#define CMD_RAND_SLOT(slot) \ + if(slot) *slot = rand() % REDIS_CLUSTER_MOD + +/* Macro for setting the slot if we've been asked to */ +#define CMD_SET_SLOT(slot,key,key_len) \ + if (slot) *slot = cluster_hash_key(key,key_len); + +/* Simple container so we can push subscribe context out */ +typedef struct { + zend_fcall_info fci; + zend_fcall_info_cache fci_cache; +} subscribeCallback; + +typedef struct subscribeContext { + char *kw; + int argc; + subscribeCallback cb; +} subscribeContext; + +/* Construct a raw command */ +int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len); + +/* Construct a script command */ +smart_string *redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args); + +/* Redis command generics. Many commands share common prototypes meaning that + * we can write one function to handle all of them. For example, there are + * many COMMAND key value commands, or COMMAND key commands. */ + +int redis_replicaof_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, + void **ctx); + +int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_opt_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_long_val_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_long_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_str_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_dbl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_varval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_val_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_key_str_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_pop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_blocking_pop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +/* Construct SCAN and similar commands, as well as check iterator */ +int redis_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + REDIS_SCAN_TYPE type, char **cmd, int *cmd_len); + +/* ZRANGE, ZREVRANGE, ZRANGEBYSCORE, and ZREVRANGEBYSCORE callback type */ +typedef int (*zrange_cb)(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *,char**,int*,int*,short*,void**); + +int redis_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_config_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_function_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zrandmember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zdiff_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zinterunion_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zdiffstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zinterunionstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_intercard_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, + void **ctx); + +int redis_slowlog_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_lcs_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_mpop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_restore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_pubsub_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_fcall_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_failover_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_georadiusbymember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_geosearch_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_geosearchstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +/* Commands which need a unique construction mechanism. This is either because + * they don't share a signature with any other command, or because there is + * specific processing we do (e.g. verifying subarguments) that make them + * unique */ + +int redis_waitaof_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); + +int redis_info_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char **cmd, int *cmd_len, short *slot, void **ctx); +
View file
redis-6.2.0.tgz/redis-6.2.0/redis_legacy_arginfo.h
Added
@@ -0,0 +1,1920 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 805a66c17b7c9972c73a979bdd67f98f7c1f6c74 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___destruct, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis__compress, 0, 0, 1) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis__uncompress arginfo_class_Redis__compress + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis__prefix, 0, 0, 1) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis__serialize arginfo_class_Redis__compress + +#define arginfo_class_Redis__unserialize arginfo_class_Redis__compress + +#define arginfo_class_Redis__pack arginfo_class_Redis__compress + +#define arginfo_class_Redis__unpack arginfo_class_Redis__compress + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_acl, 0, 0, 1) + ZEND_ARG_INFO(0, subcmd) + ZEND_ARG_VARIADIC_INFO(0, args) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_append, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_auth, 0, 0, 1) + ZEND_ARG_INFO(0, credentials) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_bgSave arginfo_class_Redis___destruct + +#define arginfo_class_Redis_bgrewriteaof arginfo_class_Redis___destruct + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_waitaof, 0, 0, 3) + ZEND_ARG_INFO(0, numlocal) + ZEND_ARG_INFO(0, numreplicas) + ZEND_ARG_INFO(0, timeout) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bitcount, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, start) + ZEND_ARG_INFO(0, end) + ZEND_ARG_INFO(0, bybit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bitop, 0, 0, 3) + ZEND_ARG_INFO(0, operation) + ZEND_ARG_INFO(0, deskey) + ZEND_ARG_INFO(0, srckey) + ZEND_ARG_VARIADIC_INFO(0, other_keys) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bitpos, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, bit) + ZEND_ARG_INFO(0, start) + ZEND_ARG_INFO(0, end) + ZEND_ARG_INFO(0, bybit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_blPop, 0, 0, 2) + ZEND_ARG_INFO(0, key_or_keys) + ZEND_ARG_INFO(0, timeout_or_key) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_brPop arginfo_class_Redis_blPop + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_brpoplpush, 0, 0, 3) + ZEND_ARG_INFO(0, src) + ZEND_ARG_INFO(0, dst) + ZEND_ARG_INFO(0, timeout) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bzPopMax, 0, 0, 2) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, timeout_or_key) + ZEND_ARG_VARIADIC_INFO(0, extra_args) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_bzPopMin arginfo_class_Redis_bzPopMax + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bzmpop, 0, 0, 3) + ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, keys) + ZEND_ARG_INFO(0, from) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_zmpop, 0, 0, 2) + ZEND_ARG_INFO(0, keys) + ZEND_ARG_INFO(0, from) + ZEND_ARG_INFO(0, count) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_blmpop arginfo_class_Redis_bzmpop + +#define arginfo_class_Redis_lmpop arginfo_class_Redis_zmpop + +#define arginfo_class_Redis_clearLastError arginfo_class_Redis___destruct + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_client, 0, 0, 1) + ZEND_ARG_INFO(0, opt) + ZEND_ARG_VARIADIC_INFO(0, args) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_close arginfo_class_Redis___destruct + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_command, 0, 0, 0) + ZEND_ARG_INFO(0, opt) + ZEND_ARG_VARIADIC_INFO(0, args) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_config, 0, 0, 1) + ZEND_ARG_INFO(0, operation) + ZEND_ARG_INFO(0, key_or_settings) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_connect, 0, 0, 1) + ZEND_ARG_INFO(0, host) + ZEND_ARG_INFO(0, port) + ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, persistent_id) + ZEND_ARG_INFO(0, retry_interval) + ZEND_ARG_INFO(0, read_timeout) + ZEND_ARG_INFO(0, context) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_copy, 0, 0, 2) + ZEND_ARG_INFO(0, src) + ZEND_ARG_INFO(0, dst) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_dbSize arginfo_class_Redis___destruct + +#define arginfo_class_Redis_debug arginfo_class_Redis__prefix + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_decr, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, by) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_decrBy arginfo_class_Redis_append + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_del, 0, 0, 1) + ZEND_ARG_INFO(0, key) + ZEND_ARG_VARIADIC_INFO(0, other_keys) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_delete arginfo_class_Redis_del + +#define arginfo_class_Redis_discard arginfo_class_Redis___destruct + +#define arginfo_class_Redis_dump arginfo_class_Redis__prefix + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_echo, 0, 0, 1) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_eval, 0, 0, 1) + ZEND_ARG_INFO(0, script) + ZEND_ARG_INFO(0, args) + ZEND_ARG_INFO(0, num_keys) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_eval_ro, 0, 0, 1) + ZEND_ARG_INFO(0, script_sha) + ZEND_ARG_INFO(0, args) + ZEND_ARG_INFO(0, num_keys) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_evalsha, 0, 0, 1) + ZEND_ARG_INFO(0, sha1) + ZEND_ARG_INFO(0, args) + ZEND_ARG_INFO(0, num_keys) +ZEND_END_ARG_INFO() + +#define arginfo_class_Redis_evalsha_ro arginfo_class_Redis_evalsha + +#define arginfo_class_Redis_exec arginfo_class_Redis___destruct + +#define arginfo_class_Redis_exists arginfo_class_Redis_del +
View file
redis-6.2.0.tgz/redis-6.2.0/redis_sentinel.c
Added
@@ -0,0 +1,113 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Pavlo Yatsukhnenko <yatsukhnenko@gmail.com> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + +----------------------------------------------------------------------+ +*/ + +#include "php_redis.h" +#include "redis_commands.h" +#include "redis_sentinel.h" +#include <zend_exceptions.h> + +zend_class_entry *redis_sentinel_ce; +extern zend_class_entry *redis_exception_ce; + +#if PHP_VERSION_ID < 80000 +#include "redis_sentinel_legacy_arginfo.h" +#else +#include "zend_attributes.h" +#include "redis_sentinel_arginfo.h" +#endif + +PHP_MINIT_FUNCTION(redis_sentinel) +{ + /* RedisSentinel class */ + redis_sentinel_ce = register_class_RedisSentinel(); + redis_sentinel_ce->create_object = create_sentinel_object; + + return SUCCESS; +} + +PHP_METHOD(RedisSentinel, __construct) +{ + HashTable *opts = NULL; + redis_sentinel_object *sentinel; + + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_NULL(opts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_THROWS()); + + sentinel = PHPREDIS_ZVAL_GET_OBJECT(redis_sentinel_object, getThis()); + sentinel->sock = redis_sock_create(ZEND_STRL("127.0.0.1"), 26379, 0, 0, 0, NULL, 0); + if (opts != NULL && redis_sock_configure(sentinel->sock, opts) != SUCCESS) { + RETURN_THROWS(); + } + sentinel->sock->sentinel = 1; +} + +PHP_METHOD(RedisSentinel, ckquorum) +{ + REDIS_PROCESS_KW_CMD("ckquorum", redis_sentinel_str_cmd, redis_boolean_response); +} + +PHP_METHOD(RedisSentinel, failover) +{ + REDIS_PROCESS_KW_CMD("failover", redis_sentinel_str_cmd, redis_boolean_response); +} + +PHP_METHOD(RedisSentinel, flushconfig) +{ + REDIS_PROCESS_KW_CMD("flushconfig", redis_sentinel_cmd, redis_boolean_response); +} + +PHP_METHOD(RedisSentinel, getMasterAddrByName) +{ + REDIS_PROCESS_KW_CMD("get-master-addr-by-name", redis_sentinel_str_cmd, redis_mbulk_reply_raw); +} + +PHP_METHOD(RedisSentinel, master) +{ + REDIS_PROCESS_KW_CMD("master", redis_sentinel_str_cmd, redis_mbulk_reply_zipped_raw); +} + +PHP_METHOD(RedisSentinel, masters) +{ + REDIS_PROCESS_KW_CMD("masters", redis_sentinel_cmd, sentinel_mbulk_reply_zipped_assoc); +} + +PHP_METHOD(RedisSentinel, myid) +{ + REDIS_PROCESS_KW_CMD("myid", redis_sentinel_cmd, redis_string_response); +} + +PHP_METHOD(RedisSentinel, ping) +{ + REDIS_PROCESS_KW_CMD("ping", redis_empty_cmd, redis_boolean_response); +} + +PHP_METHOD(RedisSentinel, reset) +{ + REDIS_PROCESS_KW_CMD("reset", redis_sentinel_str_cmd, redis_long_response); +} + +PHP_METHOD(RedisSentinel, sentinels) +{ + REDIS_PROCESS_KW_CMD("sentinels", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); +} + +PHP_METHOD(RedisSentinel, slaves) +{ + REDIS_PROCESS_KW_CMD("slaves", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_sentinel.h
Added
@@ -0,0 +1,11 @@ +#ifndef REDIS_SENTINEL_H +#define REDIS_SENTINEL_H + +#include "sentinel_library.h" + +#define PHP_REDIS_SENTINEL_VERSION "1.0" + +extern zend_class_entry *redis_sentinel_ce; +extern PHP_MINIT_FUNCTION(redis_sentinel); + +#endif /* REDIS_SENTINEL_H */
View file
redis-6.2.0.tgz/redis-6.2.0/redis_sentinel.stub.php
Added
@@ -0,0 +1,44 @@ +<?php + +/** + * @generate-function-entries + * @generate-legacy-arginfo + * @generate-class-entries + */ + +class RedisSentinel { + + public function __construct(?array $options = null); + + /** @return bool|RedisSentinel */ + public function ckquorum(string $master); + + /** @return bool|RedisSentinel */ + public function failover(string $master); + + /** @return bool|RedisSentinel */ + public function flushconfig(); + + /** @return array|bool|RedisSentinel */ + public function getMasterAddrByName(string $master); + + /** @return array|bool|RedisSentinel */ + public function master(string $master); + + /** @return array|bool|RedisSentinel */ + public function masters(); + + public function myid(): string; + + /** @return bool|RedisSentinel */ + public function ping(); + + /** @return int|RedisSentinel */ + public function reset(string $pattern); + + /** @return array|bool|RedisSentinel */ + public function sentinels(string $master); + + /** @return array|bool|RedisSentinel */ + public function slaves(string $master); +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_sentinel_arginfo.h
Added
@@ -0,0 +1,75 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: ca40579af888c5bb0661cd0201d840297474479a */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel___construct, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_ckquorum, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, master, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_failover arginfo_class_RedisSentinel_ckquorum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_flushconfig, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_getMasterAddrByName arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_master arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_masters arginfo_class_RedisSentinel_flushconfig + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisSentinel_myid, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_ping arginfo_class_RedisSentinel_flushconfig + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_reset, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_sentinels arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_slaves arginfo_class_RedisSentinel_ckquorum + + +ZEND_METHOD(RedisSentinel, __construct); +ZEND_METHOD(RedisSentinel, ckquorum); +ZEND_METHOD(RedisSentinel, failover); +ZEND_METHOD(RedisSentinel, flushconfig); +ZEND_METHOD(RedisSentinel, getMasterAddrByName); +ZEND_METHOD(RedisSentinel, master); +ZEND_METHOD(RedisSentinel, masters); +ZEND_METHOD(RedisSentinel, myid); +ZEND_METHOD(RedisSentinel, ping); +ZEND_METHOD(RedisSentinel, reset); +ZEND_METHOD(RedisSentinel, sentinels); +ZEND_METHOD(RedisSentinel, slaves); + + +static const zend_function_entry class_RedisSentinel_methods = { + ZEND_ME(RedisSentinel, __construct, arginfo_class_RedisSentinel___construct, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, ckquorum, arginfo_class_RedisSentinel_ckquorum, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, failover, arginfo_class_RedisSentinel_failover, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, flushconfig, arginfo_class_RedisSentinel_flushconfig, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, getMasterAddrByName, arginfo_class_RedisSentinel_getMasterAddrByName, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, master, arginfo_class_RedisSentinel_master, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, masters, arginfo_class_RedisSentinel_masters, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, myid, arginfo_class_RedisSentinel_myid, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, ping, arginfo_class_RedisSentinel_ping, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, reset, arginfo_class_RedisSentinel_reset, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, sentinels, arginfo_class_RedisSentinel_sentinels, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, slaves, arginfo_class_RedisSentinel_slaves, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +static zend_class_entry *register_class_RedisSentinel(void) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "RedisSentinel", class_RedisSentinel_methods); + class_entry = zend_register_internal_class_ex(&ce, NULL); + + return class_entry; +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_sentinel_legacy_arginfo.h
Added
@@ -0,0 +1,74 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: ca40579af888c5bb0661cd0201d840297474479a */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel___construct, 0, 0, 0) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_ckquorum, 0, 0, 1) + ZEND_ARG_INFO(0, master) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_failover arginfo_class_RedisSentinel_ckquorum + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_flushconfig, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_getMasterAddrByName arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_master arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_masters arginfo_class_RedisSentinel_flushconfig + +#define arginfo_class_RedisSentinel_myid arginfo_class_RedisSentinel_flushconfig + +#define arginfo_class_RedisSentinel_ping arginfo_class_RedisSentinel_flushconfig + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel_reset, 0, 0, 1) + ZEND_ARG_INFO(0, pattern) +ZEND_END_ARG_INFO() + +#define arginfo_class_RedisSentinel_sentinels arginfo_class_RedisSentinel_ckquorum + +#define arginfo_class_RedisSentinel_slaves arginfo_class_RedisSentinel_ckquorum + + +ZEND_METHOD(RedisSentinel, __construct); +ZEND_METHOD(RedisSentinel, ckquorum); +ZEND_METHOD(RedisSentinel, failover); +ZEND_METHOD(RedisSentinel, flushconfig); +ZEND_METHOD(RedisSentinel, getMasterAddrByName); +ZEND_METHOD(RedisSentinel, master); +ZEND_METHOD(RedisSentinel, masters); +ZEND_METHOD(RedisSentinel, myid); +ZEND_METHOD(RedisSentinel, ping); +ZEND_METHOD(RedisSentinel, reset); +ZEND_METHOD(RedisSentinel, sentinels); +ZEND_METHOD(RedisSentinel, slaves); + + +static const zend_function_entry class_RedisSentinel_methods = { + ZEND_ME(RedisSentinel, __construct, arginfo_class_RedisSentinel___construct, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, ckquorum, arginfo_class_RedisSentinel_ckquorum, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, failover, arginfo_class_RedisSentinel_failover, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, flushconfig, arginfo_class_RedisSentinel_flushconfig, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, getMasterAddrByName, arginfo_class_RedisSentinel_getMasterAddrByName, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, master, arginfo_class_RedisSentinel_master, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, masters, arginfo_class_RedisSentinel_masters, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, myid, arginfo_class_RedisSentinel_myid, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, ping, arginfo_class_RedisSentinel_ping, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, reset, arginfo_class_RedisSentinel_reset, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, sentinels, arginfo_class_RedisSentinel_sentinels, ZEND_ACC_PUBLIC) + ZEND_ME(RedisSentinel, slaves, arginfo_class_RedisSentinel_slaves, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +static zend_class_entry *register_class_RedisSentinel(void) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "RedisSentinel", class_RedisSentinel_methods); + class_entry = zend_register_internal_class_ex(&ce, NULL); + + return class_entry; +}
View file
redis-6.2.0.tgz/redis-6.2.0/redis_session.c
Added
@@ -0,0 +1,1383 @@ +/* -*- Mode: C; tab-width: 4 -*- */ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2009 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Original author: Alfonso Jimenez <yo@alfonsojimenez.com> | + | Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> | + | Maintainer: Nasreddine Bouafif <n.bouafif@owlient.eu> | + | Maintainer: Michael Grunder <michael.grunder@gmail.com> | + +----------------------------------------------------------------------+ +*/ + +#include "common.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef PHP_SESSION +#include "ext/standard/info.h" +#include "php_redis.h" +#include "redis_session.h" +#include <zend_exceptions.h> + +#include "library.h" +#include "cluster_library.h" + +#include "php.h" +#include "php_ini.h" +#include "php_variables.h" +#include "SAPI.h" +#include "ext/standard/url.h" + +#define REDIS_SESSION_PREFIX "PHPREDIS_SESSION:" +#define CLUSTER_SESSION_PREFIX "PHPREDIS_CLUSTER_SESSION:" + +/* Session lock LUA as well as its SHA1 hash */ +#define LOCK_RELEASE_LUA_STR "if redis.call(\"get\",KEYS1) == ARGV1 then return redis.call(\"del\",KEYS1) else return 0 end" +#define LOCK_RELEASE_LUA_LEN (sizeof(LOCK_RELEASE_LUA_STR) - 1) +#define LOCK_RELEASE_SHA_STR "b70c2384248f88e6b75b9f89241a180f856ad852" +#define LOCK_RELEASE_SHA_LEN (sizeof(LOCK_RELEASE_SHA_STR) - 1) + +/* Check if a response is the Redis +OK status response */ +#define IS_REDIS_OK(r, len) (r != NULL && len == 3 && !memcmp(r, "+OK", 3)) +#define NEGATIVE_LOCK_RESPONSE 1 + +#define CLUSTER_DEFAULT_PREFIX() \ + zend_string_init(CLUSTER_SESSION_PREFIX, sizeof(CLUSTER_SESSION_PREFIX) - 1, 0) + +ps_module ps_mod_redis = { + PS_MOD_UPDATE_TIMESTAMP(redis) +}; + +ps_module ps_mod_redis_cluster = { + PS_MOD_UPDATE_TIMESTAMP(rediscluster) +}; + +typedef struct { + zend_bool is_locked; + zend_string *session_key; + zend_string *lock_key; + zend_string *lock_secret; +} redis_session_lock_status; + +typedef struct redis_pool_member_ { + + RedisSock *redis_sock; + int weight; + struct redis_pool_member_ *next; + +} redis_pool_member; + +typedef struct { + + int totalWeight; + int count; + + redis_pool_member *head; + redis_session_lock_status lock_status; + +} redis_pool; + +// static char *session_conf_string(HashTable *ht, const char *key, size_t keylen) { +// } + +PHP_REDIS_API void +redis_pool_add(redis_pool *pool, RedisSock *redis_sock, int weight) +{ + redis_pool_member *rpm = ecalloc(1, sizeof(redis_pool_member)); + rpm->redis_sock = redis_sock; + rpm->weight = weight; + + rpm->next = pool->head; + pool->head = rpm; + + pool->totalWeight += weight; +} + +PHP_REDIS_API void +redis_pool_free(redis_pool *pool) { + + redis_pool_member *rpm, *next; + + if (pool == NULL) + return; + + rpm = pool->head; + while (rpm) { + next = rpm->next; + redis_sock_disconnect(rpm->redis_sock, 0, 1); + redis_free_socket(rpm->redis_sock); + efree(rpm); + rpm = next; + } + + /* Cleanup after our lock */ + if (pool->lock_status.session_key) zend_string_release(pool->lock_status.session_key); + if (pool->lock_status.lock_secret) zend_string_release(pool->lock_status.lock_secret); + if (pool->lock_status.lock_key) zend_string_release(pool->lock_status.lock_key); + + /* Cleanup pool itself */ + efree(pool); +} + +/* Retrieve session.gc_maxlifetime from php.ini protecting against an integer overflow */ +static int session_gc_maxlifetime(void) { + zend_long value = INI_INT("session.gc_maxlifetime"); + if (value > INT_MAX) { + php_error_docref(NULL, E_NOTICE, "session.gc_maxlifetime overflows INT_MAX, truncating."); + return INT_MAX; + } else if (value <= 0) { + php_error_docref(NULL, E_NOTICE, "session.gc_maxlifetime is <= 0, defaulting to 1440 seconds"); + return 1440; + } + + return value; +} + +/* Retrieve redis.session.compression from php.ini */ +static int session_compression_type(void) { + const char *compression = INI_STR("redis.session.compression"); + if(compression == NULL || *compression == '\0' || strncasecmp(compression, "none", sizeof("none") - 1) == 0) { + return REDIS_COMPRESSION_NONE; + } + +#ifdef HAVE_REDIS_LZF + if(strncasecmp(compression, "lzf", sizeof("lzf") - 1) == 0) { + return REDIS_COMPRESSION_LZF; + } +#endif +#ifdef HAVE_REDIS_ZSTD + if(strncasecmp(compression, "zstd", sizeof("zstd") - 1) == 0) { + return REDIS_COMPRESSION_ZSTD; + } +#endif +#ifdef HAVE_REDIS_LZ4 + if(strncasecmp(compression, "lz4", sizeof("lz4") - 1) == 0) { + return REDIS_COMPRESSION_LZ4; + } +#endif + + // E_NOTICE when outside of valid values + php_error_docref(NULL, E_NOTICE, "redis.session.compression is outside of valid values, disabling"); + + return REDIS_COMPRESSION_NONE; +} + +/* Helper to compress session data */ +static int +session_compress_data(RedisSock *redis_sock, char *data, size_t len, + char **compressed_data, size_t *compressed_len) +{ + if (redis_sock->compression) { + if(redis_compress(redis_sock, compressed_data, compressed_len, data, len)) { + return 1; + } + } + + *compressed_data = data; + *compressed_len = len; + + return 0; +} + +/* Helper to uncompress session data */ +static int +session_uncompress_data(RedisSock *redis_sock, char *data, size_t len, + char **decompressed_data, size_t *decompressed_len) { + if (redis_sock->compression) { + if(redis_uncompress(redis_sock, decompressed_data, decompressed_len, data, len)) { + return 1;
View file
redis-6.2.0.tgz/redis-6.2.0/redis_session.h
Added
@@ -0,0 +1,28 @@ +#ifndef REDIS_SESSION_H +#define REDIS_SESSION_H +#ifdef PHP_SESSION +#include "ext/session/php_session.h" + +PS_OPEN_FUNC(redis); +PS_CLOSE_FUNC(redis); +PS_READ_FUNC(redis); +PS_WRITE_FUNC(redis); +PS_DESTROY_FUNC(redis); +PS_GC_FUNC(redis); +PS_CREATE_SID_FUNC(redis); + +PS_VALIDATE_SID_FUNC(redis); +PS_UPDATE_TIMESTAMP_FUNC(redis); + +PS_OPEN_FUNC(rediscluster); +PS_CLOSE_FUNC(rediscluster); +PS_READ_FUNC(rediscluster); +PS_WRITE_FUNC(rediscluster); +PS_DESTROY_FUNC(rediscluster); +PS_GC_FUNC(rediscluster); +PS_CREATE_SID_FUNC(rediscluster); +PS_VALIDATE_SID_FUNC(rediscluster); +PS_UPDATE_TIMESTAMP_FUNC(rediscluster); + +#endif +#endif
View file
redis-6.2.0.tgz/redis-6.2.0/sentinel.md
Added
@@ -0,0 +1,237 @@ +Redis Sentinel +============== + +Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures. + +Redis Sentinel also provides other collateral tasks such as monitoring, notifications and acts as a configuration provider for clients. + +## Class RedisSentinel +----- + +##### *Parameters* + +*host*: String, IP address or hostname +*port*: Int (optional, default is 26379) +*timeout*: Float, value in seconds (optional, default is 0 meaning unlimited) +*persistent*: String, persistent connection id (optional, default is NULL meaning not persistent) +*retry_interval*: Int, value in milliseconds (optional, default is 0) +*read_timeout*: Float, value in seconds (optional, default is 0 meaning unlimited) +*auth*:String, or an Array with one or two elements, used to authenticate with the redis-sentinel. (optional, default is NULL meaning NOAUTH) + +##### *Examples for version 6.0 or later* + +~~~php +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', +); // default parameters +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', + 'port' => 26379, + 'connectTimeout' => 2.5, +); // 2.5 sec timeout. +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', + 'port' => 26379, + 'connectTimeout' => 2.5, + 'persistent' => 'sentinel', +); // persistent connection with id 'sentinel' +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', + 'port' => 26379, + 'connectTimeout' => 2.5, + 'persistent' => '', +); // also persistent connection with id '' +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', + 'port' => 26379, + 'connectTimeout' => 1, + 'persistent' => null, + 'retryInterval' => 100, +); // 1 sec timeout, 100ms delay between reconnection attempts. +$sentinel = new RedisSentinel( + 'host' => '127.0.0.1', + 'port' => 26379, + 'connectTimeout' => 0, + 'persistent' => null, + 'retryInterval' => 0, + 'readTimeout' => 0, + 'auth' => 'secret', +); // connect sentinel with password authentication +~~~ + +##### *Examples for versions older than 6.0* + +~~~php +$sentinel = new RedisSentinel('127.0.0.1'); // default parameters +$sentinel = new RedisSentinel('127.0.0.1', 26379, 2.5); // 2.5 sec timeout. +$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, 'sentinel'); // persistent connection with id 'sentinel' +$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, ''); // also persistent connection with id '' +$sentinel = new RedisSentinel('127.0.0.1', 26379, 1, null, 100); // 1 sec timeout, 100ms delay between reconnection attempts. +$sentinel = new RedisSentinel('127.0.0.1', 26379, 0, NULL, 0, 0, "secret"); // connect sentinel with password authentication +~~~ + +### Usage +----- + +* ckquorum(#ckquorum) - Check if the current Sentinel configuration is able to reach the quorum needed to failover. +* failover(#failover) - Force a failover as if the master was not reachable. +* flushconfig(#flushconfig) - Force Sentinel to rewrite its configuration on disk. +* getMasterAddrByName(#getMasterAddrByName) - Return the ip and port number of the master with that name. +* master(#master) - Return the state and info of the specified master. +* masters(#masters) - Return a list of monitored masters and their state. +* ping(#ping) - Ping the sentinel. +* reset(#reset) - Reset all the masters with matching name. +* sentinels(#sentinels) - Return a list of sentinel instances for this master, and their state. +* slaves(#slaves) - Return a list of replicas for this master, and their state. + +----- + +### ckquorum +----- +_**Description**_: Check if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok. + +##### *Parameters* +*String*: master name + +##### *Return value* +*Bool*: `TRUE` in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->ckquorum('mymaster'); +~~~ + +### failover +----- +_**Description**_: Force a failover as if the master was not reachable, and without asking for agreement to other Sentinels (however a new version of the configuration will be published so that the other Sentinels will update their configurations). + +##### *Parameters* +*String*: master name + +##### *Return value* +*Bool*: `TRUE` in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->failover('mymaster'); +~~~ + +### flushconfig +----- +_**Description**_: Force Sentinel to rewrite its configuration on disk, including the current Sentinel state. Normally Sentinel rewrites the configuration every time something changes in its state (in the context of the subset of the state which is persisted on disk across restart). However sometimes it is possible that the configuration file is lost because of operation errors, disk failures, package upgrade scripts or configuration managers. In those cases a way to to force Sentinel to rewrite the configuration file is handy. This command works even if the previous configuration file is completely missing. + +##### *Parameters* +(none) + +##### *Return value* +*Bool*: `TRUE` in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->flushconfig(); +~~~ + +### getMasterAddrByName +----- +_**Description**_: Return the ip and port number of the master with that name. If a failover is in progress or terminated successfully for this master it returns the address and port of the promoted replica. + +##### *Parameters* +*String*: master name + +##### *Return value* +*Array*, *Bool*: 'address', 'port' in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->getMasterAddrByName('mymaster'); +~~~ + +### master +----- +_**Description**_: Return the state and info of the specified master. + +##### *Parameters* +*String*: master name + +##### *Return value* +*Array*, *Bool*: Associative array with info in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->master('mymaster'); +~~~ + +### masters +----- +_**Description**_: Return a list of monitored masters and their state. + +##### *Parameters* +(none) + +##### *Return value* +*Array*, *Bool*: List of arrays with info for each master in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->masters(); +~~~ + +### ping +----- +_**Description**_: Ping the sentinel. + +##### *Parameters* +(none) + +##### *Return value* +*Bool*: `TRUE` in case of success, `FALSE` in case of failure. + +##### *Example* +~~~php +$sentinel->ping(); +~~~ + +### reset +----- +_**Description**_: This command will reset all the masters with matching name. The pattern argument is a glob-style pattern. The reset process clears any previous state in a master (including a failover in progress), and removes every replica and sentinel already discovered and associated with the master. + +##### *Parameters* +*String*: pattern
View file
redis-6.2.0.tgz/redis-6.2.0/sentinel_library.c
Added
@@ -0,0 +1,66 @@ +#include "sentinel_library.h" + +static zend_object_handlers redis_sentinel_object_handlers; + +static void +free_redis_sentinel_object(zend_object *object) +{ + redis_sentinel_object *obj = PHPREDIS_GET_OBJECT(redis_sentinel_object, object); + + if (obj->sock) { + redis_sock_disconnect(obj->sock, 0, 1); + redis_free_socket(obj->sock); + } + zend_object_std_dtor(&obj->std); +} + +zend_object * +create_sentinel_object(zend_class_entry *ce) +{ + redis_sentinel_object *obj = ecalloc(1, sizeof(*obj) + zend_object_properties_size(ce)); + + zend_object_std_init(&obj->std, ce); + object_properties_init(&obj->std, ce); + + memcpy(&redis_sentinel_object_handlers, zend_get_std_object_handlers(), sizeof(redis_sentinel_object_handlers)); + redis_sentinel_object_handlers.offset = XtOffsetOf(redis_sentinel_object, std); + redis_sentinel_object_handlers.free_obj = free_redis_sentinel_object; + obj->std.handlers = &redis_sentinel_object_handlers; + + return &obj->std; +} + +PHP_REDIS_API int +sentinel_mbulk_reply_zipped_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx) +{ + char inbuf4096; + int i, nelem; + size_t len; + zval z_ret; + + /* Throws exception on failure */ + if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0) { + RETVAL_FALSE; + return FAILURE; + } + + if (*inbuf != TYPE_MULTIBULK) { + if (*inbuf == TYPE_ERR) { + redis_sock_set_err(redis_sock, inbuf + 1, len - 1); + } + + RETVAL_FALSE; + return FAILURE; + } + array_init(&z_ret); + nelem = atoi(inbuf + 1); + for (i = 0; i < nelem; ++i) { + /* redis_mbulk_reply_zipped_raw calls redis_mbulk_reply_zipped + * which puts result into return_value via RETVAL_ZVAL */ + redis_mbulk_reply_zipped_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, ctx); + add_next_index_zval(&z_ret, return_value); + } + + RETVAL_ZVAL(&z_ret, 0, 1); + return SUCCESS; +}
View file
redis-6.2.0.tgz/redis-6.2.0/sentinel_library.h
Changed
(renamed from redis-5.3.7/sentinel_library.h)
View file
redis-6.2.0.tgz/redis-6.2.0/tests/RedisArrayTest.php
Added
@@ -0,0 +1,688 @@ +<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); + +require_once __DIR__ . "/TestSuite.php"; + +define('REDIS_ARRAY_DATA_SIZE', 1000); +define('REDIS_RA_DEFAULT_PORTS', 6379, 6380, 6381, 6382); + +function custom_hash($str) { + // str has the following format: $APPID_fb$FACEBOOKID_$key. + $pos = strpos($str, '_fb'); + if (preg_match("#\w+_fb(?<facebook_id>\d+)_\w+#", $str, $out)) { + return $out'facebook_id'; + } + return $str; +} + +function parseHostPort($str, &$host, &$port) { + $pos = strrpos($str, ':'); + $host = substr($str, 0, $pos); + $port = substr($str, $pos+1); +} + +function getRedisVersion(object $client) { + $arr_info = $client->info(); + if ( ! $arr_info || !isset($arr_info'redis_version')) { + return '0.0.0'; + } + return $arr_info'redis_version'; +} + +/* Determine the lowest redis version attached to this RedisArray object */ +function getMinVersion(object $ra) { + $min_version = '0.0.0'; + foreach ($ra->_hosts() as $host) { + $version = getRedisVersion($ra->_instance($host)); + if (version_compare($version, $min_version) > 0) { + $min_version = $version; + } + } + + return $min_version; +} + +class Redis_Array_Test extends TestSuite +{ + private $min_version; + private $strings; + public $ra = NULL; + private $data = NULL; + + public function setUp() { + // initialize strings. + $n = REDIS_ARRAY_DATA_SIZE; + $this->strings = ; + for ($i = 0; $i < $n; $i++) { + $this->strings'key-'.$i = 'val-'.$i; + } + + global $new_ring, $old_ring, $use_index; + $options = 'previous' => $old_ring, 'index' => $use_index; + if ($this->getAuth()) { + $options'auth' = $this->getAuth(); + } + + $this->ra = new RedisArray($new_ring, $options); + $this->min_version = getMinVersion($this->ra); + } + + public function testMSet() { + // run mset + $this->assertTrue($this->ra->mset($this->strings)); + + // check each key individually using the array + foreach ($this->strings as $k => $v) { + $this->assertEquals($v, $this->ra->get($k)); + } + + // check each key individually using a new connection + foreach ($this->strings as $k => $v) { + parseHostPort($this->ra->_target($k), $host, $port); + + $target = $this->ra->_target($k); + $pos = strrpos($target, ':'); + + $host = substr($target, 0, $pos); + $port = substr($target, $pos+1); + + $r = new Redis; + $r->pconnect($host, (int)$port); + if ($this->getAuth()) { + $this->assertTrue($r->auth($this->getAuth())); + } + $this->assertEquals($v, $r->get($k)); + } + } + + public function testMGet() { + $this->assertEquals(array_values($this->strings), $this->ra->mget(array_keys($this->strings))); + } + + private function addData($commonString) { + $this->data = ; + for ($i = 0; $i < REDIS_ARRAY_DATA_SIZE; $i++) { + $k = rand().'_'.$commonString.'_'.rand(); + $this->data$k = rand(); + } + $this->ra->mset($this->data); + } + + private function checkCommonLocality() { + // check that they're all on the same node. + $lastNode = NULL; + foreach ($this->data as $k => $v) { + $node = $this->ra->_target($k); + if ($lastNode) { + $this->assertEquals($node, $lastNode); + } + $this->assertEqualsWeak($v, $this->ra->get($k)); + $lastNode = $node; + } + } + + public function testKeyLocality() { + + // basic key locality with default hash + $this->addData('{hashed part of the key}'); + $this->checkCommonLocality(); + + // with common hashing function + global $new_ring, $old_ring, $use_index; + $options = + 'previous' => $old_ring, + 'index' => $use_index, + 'function' => 'custom_hash' + ; + if ($this->getAuth()) { + $options'auth' = $this->getAuth(); + } + $this->ra = new RedisArray($new_ring, $options); + + // basic key locality with custom hash + $this->addData('fb'.rand()); + $this->checkCommonLocality(); + } + + public function customDistributor($key) + { + $a = unpack("N*", md5($key, true)); + global $new_ring; + $pos = abs($a1) % count($new_ring); + + return $pos; + } + + public function testKeyDistributor() + { + global $new_ring, $useIndex; + + $options = + 'index' => $useIndex, + 'function' => 'custom_hash', + 'distributor' => $this, "customDistributor" + ; + + if ($this->getAuth()) { + $options'auth' = $this->getAuth(); + } + + $this->ra = new RedisArray($new_ring, $options); + + // custom key distribution function. + $this->addData('fb'.rand()); + + // check that they're all on the expected node. + $lastNode = NULL; + foreach ($this->data as $k => $v) { + $node = $this->ra->_target($k); + $pos = $this->customDistributor($k); + $this->assertEquals($node, $new_ring$pos); + } + } + + /* Scan a whole key and return the overall result */ + protected function execKeyScan($cmd, $key) { + $res = ; + + $it = NULL; + do { + $chunk = $this->ra->$cmd($key, $it); + foreach ($chunk as $field => $value) { + $res$field = $value; + } + } while ($it !== 0); + + return $res; + } + + public function testKeyScanning() { + $h_vals = 'foo' => 'bar', 'baz' => 'bop';
View file
redis-6.2.0.tgz/redis-6.2.0/tests/RedisClusterTest.php
Added
@@ -0,0 +1,892 @@ +<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); + +require_once __DIR__ . "/RedisTest.php"; + +/** + * Most RedisCluster tests should work the same as the standard Redis object + * so we only override specific functions where the prototype is different or + * where we're validating specific cluster mechanisms + */ +class Redis_Cluster_Test extends Redis_Test { + private $redis_types = + Redis::REDIS_STRING, + Redis::REDIS_SET, + Redis::REDIS_LIST, + Redis::REDIS_ZSET, + Redis::REDIS_HASH + ; + + private $failover_types = + RedisCluster::FAILOVER_NONE, + RedisCluster::FAILOVER_ERROR, + RedisCluster::FAILOVER_DISTRIBUTE + ; + + protected static array $seeds = ; + + private static array $seed_messages = ; + private static string $seed_source = ''; + + public function testServerInfo() { $this->markTestSkipped(); } + public function testServerInfoOldRedis() { $this->markTestSkipped(); } + + /* Tests we'll skip all together in the context of RedisCluster. The + * RedisCluster class doesn't implement specialized (non-redis) commands + * such as sortAsc, or sortDesc and other commands such as SELECT are + * simply invalid in Redis Cluster */ + public function testPipelinePublish() { $this->markTestSkipped(); } + public function testSortAsc() { $this->markTestSkipped(); } + public function testSortDesc() { $this->markTestSkipped(); } + public function testWait() { $this->markTestSkipped(); } + public function testSelect() { $this->markTestSkipped(); } + public function testReconnectSelect() { $this->markTestSkipped(); } + public function testMultipleConnect() { $this->markTestSkipped(); } + public function testDoublePipeNoOp() { $this->markTestSkipped(); } + public function testSwapDB() { $this->markTestSkipped(); } + public function testConnectException() { $this->markTestSkipped(); } + public function testTlsConnect() { $this->markTestSkipped(); } + public function testReset() { $this->markTestSkipped(); } + public function testInvalidAuthArgs() { $this->markTestSkipped(); } + public function testScanErrors() { $this->markTestSkipped(); } + + /* These 'directed node' commands work differently in RedisCluster */ + public function testConfig() { $this->markTestSkipped(); } + public function testFlushDB() { $this->markTestSkipped(); } + public function testFunction() { $this->markTestSkipped(); } + + /* Session locking feature is currently not supported in in context of Redis Cluster. + The biggest issue for this is the distribution nature of Redis cluster */ + public function testSession_lockKeyCorrect() { $this->markTestSkipped(); } + public function testSession_lockingDisabledByDefault() { $this->markTestSkipped(); } + public function testSession_lockReleasedOnClose() { $this->markTestSkipped(); } + public function testSession_ttlMaxExecutionTime() { $this->markTestSkipped(); } + public function testSession_ttlLockExpire() { $this->markTestSkipped(); } + public function testSession_lockHoldCheckBeforeWrite_otherProcessHasLock() { $this->markTestSkipped(); } + public function testSession_lockHoldCheckBeforeWrite_nobodyHasLock() { $this->markTestSkipped(); } + public function testSession_correctLockRetryCount() { $this->markTestSkipped(); } + public function testSession_defaultLockRetryCount() { $this->markTestSkipped(); } + public function testSession_noUnlockOfOtherProcess() { $this->markTestSkipped(); } + public function testSession_lockWaitTime() { $this->markTestSkipped(); } + + private function loadSeedsFromHostPort($host, $port) { + try { + $rc = new RedisCluster(NULL, "$host:$port", 1, 1, true, $this->getAuth()); + self::$seed_source = "Host: $host, Port: $port"; + return array_map(function($master) { + return sprintf('%s:%s', $master0, $master1); + }, $rc->_masters()); + } catch (Exception $ex) { + /* fallthrough */ + } + + self::$seed_messages = "--host=$host, --port=$port"; + + return false; + } + + private function loadSeedsFromEnv() { + $seeds = getenv('REDIS_CLUSTER_NODES'); + if ( ! $seeds) { + self::$seed_messages = "environment variable REDIS_CLUSTER_NODES ($seeds)"; + return false; + } + + self::$seed_source = 'Environment variable REDIS_CLUSTER_NODES'; + return array_filter(explode(' ', $seeds)); + } + + private function loadSeedsFromNodeMap() { + $nodemap_file = dirname($_SERVER'PHP_SELF') . '/nodes/nodemap'; + if ( ! file_exists($nodemap_file)) { + self::$seed_messages = "nodemap file '$nodemap_file'"; + return false; + } + + self::$seed_source = "Nodemap file '$nodemap_file'"; + return array_filter(explode("\n", file_get_contents($nodemap_file))); + } + + private function loadSeeds($host, $port) { + if (($seeds = $this->loadSeedsFromNodeMap())) + return $seeds; + if (($seeds = $this->loadSeedsFromEnv())) + return $seeds; + if (($seeds = $this->loadSeedsFromHostPort($host, $port))) + return $seeds; + + TestSuite::errorMessage("Error: Unable to load seeds for RedisCluster tests"); + foreach (self::$seed_messages as $msg) { + TestSuite::errorMessage(" Tried: %s", $msg); + } + + exit(1); + } + + /* Load our seeds on construction */ + public function __construct($host, $port, $auth) { + parent::__construct($host, $port, $auth); + + self::$seeds = $this->loadSeeds($host, $port); + } + + /* Override setUp to get info from a specific node */ + public function setUp() { + $this->redis = $this->newInstance(); + $info = $this->redis->info(uniqid()); + $this->version = $info'redis_version' ?? '0.0.0'; + $this->is_keydb = $this->detectKeyDB($info); + $this->is_valkey = $this->detectValkey($info); + } + + /* Override newInstance as we want a RedisCluster object */ + protected function newInstance() { + try { + return new RedisCluster(NULL, self::$seeds, 30, 30, true, $this->getAuth()); + } catch (Exception $ex) { + TestSuite::errorMessage("Fatal error: %s\n", $ex->getMessage()); + TestSuite::errorMessage("Seeds: %s\n", implode(' ', self::$seeds)); + TestSuite::errorMessage("Seed source: %s\n", self::$seed_source); + exit(1); + } + } + + /* Overrides for RedisTest where the function signature is different. This + * is only true for a few commands, which by definition have to be directed + * at a specific node */ + + public function testPing() { + for ($i = 0; $i < 20; $i++) { + $this->assertTrue($this->redis->ping("key:$i")); + $this->assertEquals('BEEP', $this->redis->ping("key:$i", 'BEEP')); + } + + /* Make sure both variations work in MULTI mode */ + $this->redis->multi(); + $this->redis->ping('{ping-test}'); + $this->redis->ping('{ping-test}', 'BEEP'); + $this->assertEquals(true, 'BEEP', $this->redis->exec()); + } + + public function testRandomKey() { + /* Ensure some keys are present to test */ + for ($i = 0; $i < 1000; $i++) { + if (rand(1, 2) == 1) { + $this->redis->set("key:$i", "val:$i"); + } + } + + for ($i = 0; $i < 1000; $i++) { + $k = $this->redis->randomKey("key:$i"); + $this->assertEquals(1, $this->redis->exists($k)); + } + } + + public function testEcho() { + $this->assertEquals('hello', $this->redis->echo('echo1', 'hello')); + $this->assertEquals('world', $this->redis->echo('echo2', 'world')); + $this->assertEquals(' 0123 ', $this->redis->echo('echo3', " 0123 ")); + } + + public function testSortPrefix() { + $this->redis->setOption(Redis::OPT_PREFIX, 'some-prefix:'); + $this->redis->del('some-item'); + $this->redis->sadd('some-item', 1); + $this->redis->sadd('some-item', 2); + $this->redis->sadd('some-item', 3); + + $this->assertEquals('1', '2', '3', $this->redis->sort('some-item')); + + // Kill our set/prefix
View file
redis-6.2.0.tgz/redis-6.2.0/tests/RedisSentinelTest.php
Added
@@ -0,0 +1,119 @@ +<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); + +require_once __DIR__ . "/TestSuite.php"; + +class Redis_Sentinel_Test extends TestSuite +{ + const NAME = 'mymaster'; + + /** + * @var RedisSentinel + */ + public $sentinel; + + /** + * Common fields + */ + protected $fields = + 'name', + 'ip', + 'port', + 'runid', + 'flags', + 'link-pending-commands', + 'link-refcount', + 'last-ping-sent', + 'last-ok-ping-reply', + 'last-ping-reply', + 'down-after-milliseconds', + ; + + protected function newInstance() + { + return new RedisSentinel('host' => $this->getHost()); + } + + public function setUp() + { + $this->sentinel = $this->newInstance(); + } + + public function testCkquorum() + { + $this->assertTrue($this->sentinel->ckquorum(self::NAME)); + } + + public function testFailover() + { + $this->assertFalse($this->sentinel->failover(self::NAME)); + } + + public function testFlushconfig() + { + $this->assertTrue($this->sentinel->flushconfig()); + } + + public function testGetMasterAddrByName() + { + $result = $this->sentinel->getMasterAddrByName(self::NAME); + $this->assertTrue(is_array($result)); + $this->assertEquals(2, count($result)); + } + + protected function checkFields(array $fields) + { + foreach ($this->fields as $k) { + $this->assertTrue(array_key_exists($k, $fields)); + } + } + + public function testMaster() + { + $result = $this->sentinel->master(self::NAME); + $this->assertTrue(is_array($result)); + $this->checkFields($result); + } + + public function testMasters() + { + $result = $this->sentinel->masters(); + $this->assertTrue(is_array($result)); + foreach ($result as $master) { + $this->checkFields($master); + } + } + + public function testMyid() + { + $result = $this->sentinel->myid(); + $this->assertTrue(is_string($result)); + } + + public function testPing() + { + $this->assertTrue($this->sentinel->ping()); + } + + public function testReset() + { + $this->assertEquals(1, $this->sentinel->reset('*')); + } + + public function testSentinels() + { + $result = $this->sentinel->sentinels(self::NAME); + $this->assertTrue(is_array($result)); + foreach ($result as $sentinel) { + $this->checkFields($sentinel); + } + } + + public function testSlaves() + { + $result = $this->sentinel->slaves(self::NAME); + $this->assertTrue(is_array($result)); + foreach ($result as $slave) { + $this->checkFields($slave); + } + } +}
View file
redis-6.2.0.tgz/redis-6.2.0/tests/RedisTest.php
Added
@@ -0,0 +1,8036 @@ +<?php defined('PHPREDIS_TESTRUN') or die('Use TestRedis.php to run tests!\n'); + +require_once __DIR__ . '/TestSuite.php'; +require_once __DIR__ . '/SessionHelpers.php'; + +class Redis_Test extends TestSuite { + /** + * @var Redis + */ + public $redis; + + /* City lat/long */ + protected $cities = + 'Chico' => -121.837478, 39.728494, + 'Sacramento' => -121.494400, 38.581572, + 'Gridley' => -121.693583, 39.363777, + 'Marysville' => -121.591355, 39.145725, + 'Cupertino' => -122.032182, 37.322998 + ; + + protected $serializers = + Redis::SERIALIZER_NONE, + Redis::SERIALIZER_PHP, + ; + + protected function getNilValue() { + return FALSE; + } + + protected function getSerializers() { + $result = Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP; + + if (defined('Redis::SERIALIZER_IGBINARY')) + $result = Redis::SERIALIZER_IGBINARY; + if (defined('Redis::SERIALIZER_JSON')) + $result = Redis::SERIALIZER_JSON; + if (defined('Redis::SERIALIZER_MSGPACK')) + $result = Redis::SERIALIZER_MSGPACK; + + return $result; + } + + protected function getCompressors() { + $result'none' = Redis::COMPRESSION_NONE; + if (defined('Redis::COMPRESSION_LZF')) + $result'lzf' = Redis::COMPRESSION_LZF; + if (defined('Redis::COMPRESSION_LZ4')) + $result'lz4' = Redis::COMPRESSION_LZ4; + if (defined('Redis::COMPRESSION_ZSTD')) + $result'zstd' = Redis::COMPRESSION_ZSTD; + + return $result; + } + + /* Overridable left/right constants */ + protected function getLeftConstant() { + return Redis::LEFT; + } + + protected function getRightConstant() { + return Redis::RIGHT; + } + + protected function detectKeyDB(array $info) { + return strpos($info'executable' ?? '', 'keydb') !== false || + isset($info'keydb') || + isset($info'mvcc_depth'); + } + + protected function detectValkey(array $info) { + return isset($info'server_name') && $info'server_name' === 'valkey'; + } + + public function setUp() { + $this->redis = $this->newInstance(); + $info = $this->redis->info(); + $this->version = (isset($info'redis_version')?$info'redis_version':'0.0.0'); + $this->is_keydb = $this->detectKeyDB($info); + $this->is_valkey = $this->detectValKey($info); + } + + protected function minVersionCheck($version) { + return version_compare($this->version, $version) >= 0; + } + + protected function mstime() { + return round(microtime(true)*1000); + } + + protected function getAuthParts(&$user, &$pass) { + $user = $pass = NULL; + + $auth = $this->getAuth(); + if ( ! $auth) + return; + + if (is_array($auth)) { + if (count($auth) > 1) { + list($user, $pass) = $auth; + } else { + $pass = $auth0; + } + } else { + $pass = $auth; + } + } + + protected function sessionPrefix(): string { + return 'PHPREDIS_SESSION:'; + } + + protected function sessionSaveHandler(): string { + return 'redis'; + } + + protected function sessionSavePath(): string { + return sprintf('tcp://%s:%d?%s', $this->getHost(), $this->getPort(), + $this->getAuthFragment()); + } + + protected function getAuthFragment() { + $this->getAuthParts($user, $pass); + + if ($user && $pass) { + return sprintf('authuser=%s&authpass=%s', $user, $pass); + } else if ($pass) { + return sprintf('authpass=%s', $pass); + } else { + return ''; + } + } + + protected function newInstance() { + $r = new Redis( + 'host' => $this->getHost(), + 'port' => $this->getPort(), + ); + + if ($this->getAuth()) { + $this->assertTrue($r->auth($this->getAuth())); + } + return $r; + } + + public function tearDown() { + if ($this->redis) { + $this->redis->close(); + } + } + + public function reset() { + $this->setUp(); + $this->tearDown(); + } + + /* Helper function to determine if the class has pipeline support */ + protected function havePipeline() { + return defined(get_class($this->redis) . '::PIPELINE'); + } + + protected function haveMulti() { + return defined(get_class($this->redis) . '::MULTI'); + } + + public function testMinimumVersion() { + $this->assertTrue(version_compare($this->version, '2.4.0') >= 0); + } + + public function testPing() { + /* Reply literal off */ + $this->assertTrue($this->redis->ping()); + $this->assertTrue($this->redis->ping(NULL)); + $this->assertEquals('BEEP', $this->redis->ping('BEEP')); + + /* Make sure we're good in MULTI mode */ + if ($this->haveMulti()) { + $this->assertEquals( + true, 'BEEP', + $this->redis->multi() + ->ping() + ->ping('BEEP') + ->exec() + ); + } + } + + public function testPipelinePublish() { + $ret = $this->redis->pipeline() + ->publish('chan', 'msg') + ->exec(); + + $this->assertIsArray($ret, 1); + $this->assertGT(-1, $ret0 ?? -1); + } + + // Run some simple tests against the PUBSUB command. This is problematic, as we + // can't be sure what's going on in the instance, but we can do some things. + public function testPubSub() { + // Only available since 2.8.0
View file
redis-6.2.0.tgz/redis-6.2.0/tests/SessionHelpers.php
Added
@@ -0,0 +1,353 @@ +<?php + +namespace SessionHelpers; + +class PhpSpawner { + protected static function appendPhpArgs(string $php): string { + $modules = shell_exec("$php --no-php-ini -m"); + + /* Determine if we need to specifically add extensions */ + $extensions = array_filter( + 'igbinary', 'msgpack', 'json', 'redis', + function ($module) use ($modules) { + return strpos($modules, $module) === false; + } + ); + + /* If any are needed add them to the command */ + if ($extensions) { + $php .= ' --no-php-ini'; + foreach ($extensions as $extension) { + /* We want to use the locally built redis extension */ + if ($extension == 'redis') { + $path = dirname(__DIR__) . '/modules/redis'; + if (is_file("{$path}.so")) + $extension = $path; + } + + $php .= " -dextension=$extension.so"; + } + } + + return $php; + } + + /** + * Return command to launch PHP with built extension enabled + * taking care of environment (TEST_PHP_EXECUTABLE and TEST_PHP_ARGS) + * + * @param string $script + * + * @return string + */ + public static function cmd(string $script): string { + static $cmd = NULL; + + if ( ! $cmd) { + $cmd = getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY; + + if ($test_args = getenv('TEST_PHP_ARGS')) { + $cmd .= ' ' . $test_args; + } else { + $cmd = self::appendPhpArgs($cmd); + } + } + + return $cmd . ' ' . __DIR__ . '/' . $script . ' '; + } +} + +class Runner { + const start_script = 'startSession.php'; + const regenerate_id_script = 'regenerateSessionId.php'; + const get_data_script = 'getSessionData.php'; + + private $required = 'host', 'handler', 'id'; + + private $args = + 'handler' => null, + 'save-path' => null, + 'id' => null, + 'sleep' => 0, + 'max-execution-time' => 300, + 'locking-enabled' => true, + 'lock-wait-time' => null, + 'lock-retries' => -1, + 'lock-expires' => 0, + 'data' => '', + 'lifetime' => 1440, + 'compression' => 'none', + ; + + private $prefix = NULL; + private $output_file; + private $exit_code = -1; + private $cmd = NULL; + private $pid; + private $output; + + public function __construct() { + $this->args'id' = $this->createId(); + } + + public function getExitCode(): int { + return $this->exit_code; + } + + public function getCmd(): ?string { + return $this->cmd; + } + + public function getId(): ?string { + return $this->args'id'; + } + + public function prefix(string $prefix): self { + $this->prefix = $prefix; + return $this; + } + + public function getSessionKey(): string { + return $this->prefix . $this->getId(); + } + + public function getSessionLockKey(): string { + return $this->getSessionKey() . '_LOCK'; + } + + protected function set($setting, $v): self { + $this->args$setting = $v; + return $this; + } + + public function handler(string $handler): self { + return $this->set('handler', $handler); + } + + public function savePath(string $path): self { + return $this->set('save-path', $path); + } + + public function id(string $id): self { + return $this->set('id', $id); + } + + public function sleep(int $sleep): self { + return $this->set('sleep', $sleep); + } + + public function maxExecutionTime(int $time): self { + return $this->set('max-execution-time', $time); + } + + public function lockingEnabled(bool $enabled): self { + return $this->set('locking-enabled', $enabled); + } + + public function lockWaitTime(int $time): self { + return $this->set('lock-wait-time', $time); + } + + public function lockRetries(int $retries): self { + return $this->set('lock-retries', $retries); + } + + public function lockExpires(int $expires): self { + return $this->set('lock-expires', $expires); + } + + public function data(string $data): self { + return $this->set('data', $data); + } + + public function lifetime(int $lifetime): self { + return $this->set('lifetime', $lifetime); + } + + public function compression(string $compression): self { + return $this->set('compression', $compression); + } + + protected function validateArgs(array $required) { + foreach ($required as $req) { + if ( ! isset($this->args$req) || $this->args$req === null) + throw new \Exception("Command requires '$req' arg"); + } + } + + private function createId(): string { + if (function_exists('session_create_id')) + return session_create_id(); + + return uniqid(); + } + + private function getTmpFileName() { + return '/tmp/sessiontmp.txt'; + return tempnam(sys_get_temp_dir(), 'session'); + } + + /* + * @param $client Redis client + * @param string $max_wait_sec + * + * Sometimes we want to block until a session lock has been detected + * This is better and faster than arbitrarily sleeping. If we don't + * detect the session key within the specified maximum number of + * seconds, the function returns failure. + * + * @return bool
View file
redis-6.2.0.tgz/redis-6.2.0/tests/TestRedis.php
Added
@@ -0,0 +1,127 @@ +<?php define('PHPREDIS_TESTRUN', true); + +require_once __DIR__ . "/TestSuite.php"; +require_once __DIR__ . "/RedisTest.php"; +require_once __DIR__ . "/RedisArrayTest.php"; +require_once __DIR__ . "/RedisClusterTest.php"; +require_once __DIR__ . "/RedisSentinelTest.php"; + +function getClassArray($classes) { + $result = ; + + if ( ! is_array($classes)) + $classes = $classes; + + foreach ($classes as $class) { + $result = array_merge($result, explode(',', $class)); + } + + return array_unique( + array_map(function ($v) { return strtolower($v); }, + $result + ) + ); +} + +function getTestClass($class) { + $valid_classes = + 'redis' => 'Redis_Test', + 'redisarray' => 'Redis_Array_Test', + 'rediscluster' => 'Redis_Cluster_Test', + 'redissentinel' => 'Redis_Sentinel_Test' + ; + + /* Return early if the class is one of our built-in ones */ + if (isset($valid_classes$class)) + return $valid_classes$class; + + /* Try to load it */ + return TestSuite::loadTestClass($class); +} + +function raHosts($host, $ports) { + if ( ! is_array($ports)) + $ports = 6379, 6380, 6381, 6382; + + return array_map(function ($port) use ($host) { + return sprintf("%s:%d", $host, $port); + }, $ports); +} + +/* Make sure errors go to stdout and are shown */ +error_reporting(E_ALL); +ini_set( 'display_errors','1'); + +/* Grab options */ +$opt = getopt('', 'host:', 'port:', 'class:', 'test:', 'nocolors', 'user:', 'auth:'); + +/* The test class(es) we want to run */ +$classes = getClassArray($opt'class' ?? 'redis'); + +$colorize = !isset($opt'nocolors'); + +/* Get our test filter if provided one */ +$filter = $opt'test' ?? NULL; + +/* Grab override host/port if it was passed */ +$host = $opt'host' ?? '127.0.0.1'; +$port = $opt'port' ?? 6379; + +/* Get optional username and auth (password) */ +$user = $opt'user' ?? NULL; +$auth = $opt'auth' ?? NULL; + +if ($user && $auth) { + $auth = $user, $auth; +} else if ($user && ! $auth) { + echo TestSuite::make_warning("User passed without a password!\n"); +} + +/* Toggle colorization in our TestSuite class */ +TestSuite::flagColorization($colorize); + +/* Let the user know this can take a bit of time */ +echo "Note: these tests might take up to a minute. Don't worry :-)\n"; +echo "Using PHP version " . PHP_VERSION . " (" . (PHP_INT_SIZE * 8) . " bits)\n"; + +foreach ($classes as $class) { + $class = getTestClass($class); + + /* Depending on the classes being tested, run our tests on it */ + echo "Testing class "; + if ($class == 'Redis_Array_Test') { + echo TestSuite::make_bold("RedisArray") . "\n"; + + $full_ring = raHosts($host, $port); + $sub_ring = array_slice($full_ring, 0, -1); + + echo TestSuite::make_bold("Full Ring: ") . implode(' ', $full_ring) . "\n"; + echo TestSuite::make_bold(" New Ring: ") . implode(' ', $sub_ring) . "\n"; + + foreach(true, false as $useIndex) { + echo "\n". ($useIndex ? "WITH" : "WITHOUT") . " per-node index:\n"; + + /* The various RedisArray subtests we can run */ + $test_classes = + 'Redis_Array_Test', 'Redis_Rehashing_Test', 'Redis_Auto_Rehashing_Test', + 'Redis_Multi_Exec_Test', 'Redis_Distributor_Test' + ; + + foreach ($test_classes as $test_class) { + /* Run until we encounter a failure */ + if (run_ra_tests($test_class, $filter, $host, $full_ring, $sub_ring, $auth) != 0) { + exit(1); + } + } + } + } else { + echo TestSuite::make_bold($class) . "\n"; + if (TestSuite::run("$class", $filter, $host, $port, $auth)) + exit(1); + } +} + +/* Success */ +exit(0); + +?>
View file
redis-6.2.0.tgz/redis-6.2.0/tests/TestSuite.php
Added
@@ -0,0 +1,638 @@ +<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n"); + +/* A specific exception for when we skip a test */ +class TestSkippedException extends Exception {} + +// phpunit is such a pain to install, we're going with pure-PHP here. +class TestSuite +{ + /* Host and port the unit tests will use */ + private string $host; + private ?int $port = 6379; + + /* Redis authentication we'll use */ + private $auth; + + /* Redis server version */ + protected $version; + protected bool $is_keydb; + protected bool $is_valkey; + + private static bool $colorize = false; + + private static $BOLD_ON = "\0331m"; + private static $BOLD_OFF = "\0330m"; + + private static $BLACK = "\0330;30m"; + private static $DARKGRAY = "\0331;30m"; + private static $BLUE = "\0330;34m"; + private static $PURPLE = "\0330;35m"; + private static $GREEN = "\0330;32m"; + private static $YELLOW = "\0330;33m"; + private static $RED = "\0330;31m"; + + public static array $errors = ; + public static array $warnings = ; + + public function __construct(string $host, ?int $port, $auth) { + $this->host = $host; + $this->port = $port; + $this->auth = $auth; + } + + public function getHost() { return $this->host; } + public function getPort() { return $this->port; } + public function getAuth() { return $this->auth; } + + public static function errorMessage(string $fmt, ...$args) { + $msg = vsprintf($fmt . "\n", $args); + + if (defined('STDERR')) { + fwrite(STDERR, $msg); + } else { + echo $msg; + } + } + + public static function make_bold(string $msg) { + return self::$colorize ? self::$BOLD_ON . $msg . self::$BOLD_OFF : $msg; + } + + public static function make_success(string $msg) { + return self::$colorize ? self::$GREEN . $msg . self::$BOLD_OFF : $msg; + } + + public static function make_fail(string $msg) { + return self::$colorize ? self::$RED . $msg . self::$BOLD_OFF : $msg; + } + + public static function make_warning(string $msg) { + return self::$colorize ? self::$YELLOW . $msg . self::$BOLD_OFF : $msg; + } + + protected function printArg($v) { + if (is_null($v)) + return '(null)'; + else if ($v === false || $v === true) + return $v ? '(true)' : '(false)'; + else if (is_string($v)) + return "'$v'"; + else + return print_r($v, true); + } + + protected function findTestFunction($bt) { + $i = 0; + while (isset($bt$i)) { + if (substr($bt$i'function', 0, 4) == 'test') + return $bt$i'function'; + $i++; + } + return NULL; + } + + protected function assertionTrace(?string $fmt = NULL, ...$args) { + $prefix = 'Assertion failed:'; + + $lines = ; + + $bt = debug_backtrace(); + + $msg = $fmt ? vsprintf($fmt, $args) : NULL; + + $fn = $this->findTestFunction($bt); + $lines = sprintf("%s %s - %s", $prefix, self::make_bold($fn), + $msg ? $msg : '(no message)'); + + array_shift($bt); + + for ($i = 0; $i < count($bt); $i++) { + $file = $bt$i'file'; + $line = $bt$i'line'; + $fn = $bt$i+1'function' ?? $bt$i'function'; + + $lines = sprintf("%s %s:%d (%s)%s", + str_repeat(' ', strlen($prefix)), $file, $line, + $fn, $msg ? " $msg" : ''); + + if (substr($fn, 0, 4) == 'test') + break; + } + + return implode("\n", $lines) . "\n"; + } + + protected function assert($fmt, ...$args) { + self::$errors = $this->assertionTrace($fmt, ...$args); + } + + protected function assertKeyEquals($expected, $key, $redis = NULL): bool { + $actual = ($redis ??= $this->redis)->get($key); + if ($actual === $expected) + return true; + + self::$errors = $this->assertionTrace("%s !== %s", $this->printArg($actual), + $this->printArg($expected)); + + return false; + } + + protected function assertKeyEqualsWeak($expected, $key, $redis = NULL): bool { + $actual = ($redis ??= $this->redis)->get($key); + if ($actual == $expected) + return true; + + self::$errors = $this->assertionTrace("%s != %s", $this->printArg($actual), + $this->printArg($expected)); + + return false; + } + + protected function assertKeyExists($key, $redis = NULL): bool { + if (($redis ??= $this->redis)->exists($key)) + return true; + + self::$errors = $this->assertionTrace("Key '%s' does not exist.", $key); + + return false; + } + + protected function assertKeyMissing($key, $redis = NULL): bool { + if ( ! ($redis ??= $this->redis)->exists($key)) + return true; + + self::$errors = $this->assertionTrace("Key '%s' exists but shouldn't.", $key); + + return false; + } + + protected function assertTrue($value): bool { + if ($value === true) + return true; + + self::$errors = $this->assertionTrace("%s !== %s", $this->printArg($value), + $this->printArg(true)); + + return false; + } + + protected function assertFalse($value): bool { + if ($value === false) + return true; + + self::$errors = $this->assertionTrace("%s !== %s", $this->printArg($value), + $this->printArg(false)); + + return false; + } + + protected function assertNull($value): bool { + if ($value === NULL) + return true; + + self::$errors = $this->assertionTrace("%s !== %s", $this->printArg($value), + $this->printArg(NULL)); + + return false; + } + + protected function assertInArray($ele, $arr, ?callable $cb = NULL): bool {
View file
redis-6.2.0.tgz/redis-6.2.0/tests/getSessionData.php
Added
@@ -0,0 +1,33 @@ +<?php + +require_once __DIR__ . '/SessionHelpers.php'; + +error_reporting(E_ERROR | E_WARNING); + +$opt = getopt('', 'handler:', 'save-path:', 'id:', 'lifetime:'); + +$handler = $opt'handler' ?? NULL; +$save_path = $opt'save-path' ?? NULL; +$id = $opt'id' ?? NULL; +$lifetime = $opt'lifetime' ?? NULL; + +if ( ! $handler) { + fprintf(STDERR, "--handler is required\n"); + exit(1); +} else if ( ! $save_path) { + fprintf(STDERR, "--save-path is required\n"); + exit(1); +} + +ini_set('session.save_handler', $handler); +ini_set('session.save_path', $save_path); +ini_set('session.gc_maxlifetime', $lifetime); + +session_id($id); +if ( ! session_start()) { + fprintf(STDERR, "session_start() was nut successful"); + exit(1); +} else { + echo isset($_SESSION'redis_test') ? $_SESSION'redis_test' : 'Key redis_test not found'; + exit(0); +}
View file
redis-6.2.0.tgz/redis-6.2.0/tests/make-cluster.sh
Added
@@ -0,0 +1,226 @@ +#!/bin/bash + +# make-cluster.sh +# This is a simple script used to automatically spin up a Redis cluster instance +# simplifying the process of running unit tests. +# +# Usage: +# ./make-cluster.sh start host +# ./make-cluster.sh stop host +# + +BASEDIR=`pwd` +NODEDIR=$BASEDIR/nodes +MAPFILE=$NODEDIR/nodemap + +REDIS_BINARY=${REDIS_BINARY:-redis-server} + +# Host, nodes, replicas, ports, etc. Change if you want different values +HOST="127.0.0.1" +NOASK=0 +NODES=12 +REPLICAS=3 +START_PORT=7000 +END_PORT=`expr $START_PORT + $NODES` + +# Helper to determine if we have an executable +checkExe() { + if ! hash $1 > /dev/null 2>&1; then + echo "Error: Must have $1 on the path!" + exit 1 + fi +} + +# Run a command and output what we're running +verboseRun() { + echo "Running: $@" + $@ +} + +# Spawn a specific redis instance, cluster enabled +spawnNode() { + # ACL file if we have one + if ! -z "$ACLFILE" ; then + ACLARG="--aclfile $ACLFILE" + fi + + # Attempt to spawn the node + verboseRun "$REDIS_BINARY" --cluster-enabled yes --dir $NODEDIR --port $PORT \ + --cluster-config-file node-$PORT.conf --daemonize yes --save \'\' \ + --bind $HOST --dbfilename node-$PORT.rdb $ACLARG + + # Abort if we can't spin this instance + if $? -ne 0 ; then + echo "Error: Can't spawn node at port $PORT." + exit 1 + fi +} + +# Spawn nodes from start to end port +spawnNodes() { + for PORT in `seq $START_PORT $END_PORT`; do + # Attempt to spawn the node + spawnNode $PORT + + # Add this host:port to our nodemap so the tests can get seeds + echo "$HOST:$PORT" >> $MAPFILE + done +} + +# Check to see if any nodes are running +checkNodes() { + echo -n "Checking port availability " + + for PORT in `seq $START_PORT $END_PORT`; do + redis-cli -p $PORT ping > /dev/null 2>&1 + if $? -eq 0 ; then + echo "FAIL" + echo "Error: There appears to be an instance running at port $PORT" + exit 1 + fi + done + + echo "OK" +} + +# Create our 'node' directory if it doesn't exist and clean out any previous +# configuration files from a previous run. +cleanConfigInfo() { + verboseRun mkdir -p $NODEDIR + verboseRun rm -f $NODEDIR/* + + if -f "$ACLFILE" ; then + cp $ACLFILE $NODEDIR/$ACLFILE + fi +} + +# Initialize our cluster with redis-trib.rb +initCluster() { + TRIBARGS="" + for PORT in `seq $START_PORT $END_PORT`; do + TRIBARGS="$TRIBARGS $HOST:$PORT" + done + + if ! -z "$USER" ; then + USERARG="--user $USER" + fi + if ! -z "$PASS" ; then + PASSARG="-a $PASS" + fi + + if "$1" -eq "1" ; then + echo yes | redis-cli $USERARG $PASSARG -p $START_PORT --cluster create $TRIBARGS --cluster-replicas $REPLICAS + else + verboseRun redis-cli $USERARG $PASSARG -p $START_PORT --cluster create $TRIBARGS --cluster-replicas $REPLICAS + fi + + if $? -ne 0 ; then + echo "Error: Couldn't create cluster!" + exit 1 + fi +} + +# Attempt to spin up our cluster +startCluster() { + # Make sure none of these nodes are already running + checkNodes + + # Clean out node configuration, etc + cleanConfigInfo + + # Attempt to spawn the nodes + spawnNodes + + # Attempt to initialize the cluster + initCluster $1 +} + +# Shut down nodes in our cluster +stopCluster() { + for PORT in `seq $START_PORT $END_PORT`; do + verboseRun redis-cli -p $PORT SHUTDOWN NOSAVE > /dev/null 2>&1 + done +} + +# Shut down nodes by killing them +killCluster() { + for PORT in `seq $START_PORT $END_PORT`; do + PID=$(ps aux|grep redis-server|grep $PORT|awk '{print $2}') + echo -n "Killing $PID: " + if kill $PID; then + echo "OK" + else + echo "ERROR" + fi + done +} + +printUsage() { + echo "Usage: make-cluster OPTIONS <start|stop|kill>" + echo + echo " Options" + echo + echo " -u Redis username to use when spawning cluster" + echo " -p Redis password to use when spawning cluster" + echo " -a Redis acl filename to use when spawning cluster" + echo " -y Automatically send 'yes' when starting cluster" + echo " -h This message" + echo + exit 0 +} + +checkExe "$REDIS_BINARY" + +while getopts "u:p:a:hy" OPT; do + case $OPT in + h) + printUsage + ;; + a) + if ! -f "$OPTARG" ; then + echo "Error: '$OPTARG' is not a filename!" + exit -1 + fi + ACLFILE=$OPTARG + ;; + u) + USER=$OPTARG + ;; + p) + PASS=$OPTARG + ;; + h) + HOST=$OPTARG + ;; + y) + NOASK=1 + ;; + *) + echo "Unknown option: $OPT"
View file
redis-6.2.0.tgz/redis-6.2.0/tests/mkring.sh
Changed
(renamed from redis-5.3.7/tests/mkring.sh)
View file
redis-6.2.0.tgz/redis-6.2.0/tests/regenerateSessionId.php
Added
@@ -0,0 +1,91 @@ +<?php + +error_reporting(E_ERROR | E_WARNING); + +$opt = getopt('', + 'handler:', 'save-path:', 'id:', 'locking-enabled:', + 'destroy-previous:', 'proxy:' +); + +$handler = $opt'handler' ?? NULL; +$save_path = $opt'save-path' ?? NULL; +$id = $opt'id' ?? NULL; +$locking_enabled = !!($opt'locking-enabled' ?? false); +$destroy_previous = !!($opt'destroy-previous' ?? false); +$proxy = !!($opt'proxy' ?? false); + +if ( ! $handler) { + fprintf(STDERR, "--handler is required\n"); + exit(1); +} else if ( ! $save_path) { + fprintf(STDERR, "--save-path is required\n"); + exit(1); +} + +ini_set('session.save_handler', $handler); +ini_set('session.save_path', $save_path); +ini_set('redis.session.locking_enabled', $locking_enabled); + +if (interface_exists('SessionHandlerInterface')) { + class TestHandler implements SessionHandlerInterface + { + /** + * @var SessionHandler + */ + private $handler; + + public function __construct() + { + $this->handler = new SessionHandler(); + } + + public function close() + { + return $this->handler->close(); + } + + public function destroy($session_id) + { + return $this->handler->destroy($session_id); + } + + public function gc($maxlifetime) + { + return $this->handler->gc($maxlifetime); + } + + public function open($save_path, $name) + { + return $this->handler->open($save_path, $name); + } + + public function read($session_id) + { + return $this->handler->read($session_id); + } + + public function write($session_id, $session_data) + { + return $this->handler->write($session_id, $session_data); + } + } +} + +if ($proxy) { + $handler = new TestHandler(); + session_set_save_handler($handler); +} + +session_id($id); + +if ( ! session_start()) { + $result = "FAILED: session_start()"; +} else if ( ! session_regenerate_id($destroy_previous)) { + $result = "FAILED: session_regenerateId()"; +} else { + $result = session_id(); +} + +session_write_close(); + +echo $result;
View file
redis-6.2.0.tgz/redis-6.2.0/tests/startSession.php
Added
@@ -0,0 +1,52 @@ +<?php +error_reporting(E_ERROR | E_WARNING); + +$opt = getopt('', + 'handler:', 'save-path:', 'id:', 'sleep:', 'max-execution-time:' , + 'locking-enabled:', 'lock-wait-time:', 'lock-retries:', 'lock-expires:', + 'data:', 'lifetime:', 'compression:' +); + +$handler = $opt'handler' ?? NULL; +$save_path = $opt'save-path' ?? NULL; +$id = $opt'id' ?? NULL; +$sleep = $opt'sleep' ?? 0; +$max_execution_time = $opt'max-execution-time' ?? 0; +$lock_retries = $opt'lock-retries' ?? 0; +$lock_expire = $opt'lock-expires' ?? 0; +$data = $opt'data' ?? NULL; +$lifetime = $opt'lifetime' ?? 0; +$locking_enabled = $opt'locking-enabled' ?? NULL; +$lock_wait_time = $opt'lock-wait-time' ?? 0; +$compression = $opt'compression' ?? NULL; + +if ( ! $handler) { + fprintf(STDERR, "--handler is required\n"); + exit(1); +} else if ( ! $save_path) { + fprintf(STDERR, "--save-path is required\n"); + exit(1); +} + +ini_set('session.save_handler', $handler); +ini_set('session.save_path', $save_path); +ini_set('max_execution_time', $max_execution_time); +ini_set("{$handler}.session.lock_retries", $lock_retries); +ini_set("{$handler}.session.lock_expire", $lock_expire); +ini_set('session.gc_maxlifetime', $lifetime); +ini_set("{$handler}.session.locking_enabled", $locking_enabled); +ini_set("{$handler}.session.lock_wait_time", $lock_wait_time); +ini_set('redis.session.compression', $compression); + +session_id($id); +$status = session_start(); + +sleep($sleep); + +if ($data) { + $_SESSION'redis_test' = $data; +} + +session_write_close(); + +echo $status ? 'SUCCESS' : 'FAILURE';
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.