Download the PHP package icyboy/credis without Composer
On this page you can find all versions of the php package icyboy/credis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download icyboy/credis
More information about icyboy/credis
Files in icyboy/credis
Package credis
Short Description Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance.
License MIT
Homepage https://github.com/icyxp/credis
Informations about the package credis
Credis
Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance. This project was forked from one of the many redisent forks.
Getting Started
Credis_Client uses methods named the same as Redis commands, and translates return values to the appropriate PHP equivalents.
Redis error responses will be wrapped in a CredisException class and thrown.
Credis_Client also supports transparent command renaming. Write code using the original command names and the client will send the aliased commands to the server transparently. Specify the renamed commands using a prefix for md5, a callable function, individual aliases, or an array map of aliases. See "Redis Security":http://redis.io/topics/security for more info.
Clustering your servers
Credis also includes a way for developers to fully utilize the scalability of Redis with multiple servers and consistent hashing. Using the Credis_Cluster class, you can use Credis the same way, except that keys will be hashed across multiple servers. Here is how to set up a cluster:
Basic clustering example
Explicit definition of replicas
The consistent hashing strategy stores keys on a so called "ring". The position of each key is relative to the position of its target node. The target node that has the closest position will be the selected node for that specific key.
To avoid an uneven distribution of keys (especially on small clusters), it is common to duplicate target nodes. Based on the number of replicas, each target node will exist n times on the "ring".
The following example explicitly sets the number of replicas to 5. Both Redis instances will have 5 copies. The default value is 128.
Master/slave replication
The master/slave replication. Credis_Cluster will automatically perform read/write splitting and send the write requests exclusively to the master server. Read requests will be handled by all servers unless you set the write_only flag to true in the connection string of the master server.
Redis server settings for master/slave replication
Setting up master/slave replication is simple and only requires adding the following line to the config of the slave server:
Basic master/slave example
No read on master
The following example illustrates how to disable reading on the master server. This will cause the master server only to be used for writing. This should only happen when you have enough write calls to create a certain load on the master server. Otherwise this is an inefficient usage of server resources.
Automatic failover with Sentinel
Redis Sentinel is a system that can monitor Redis instances. You register master servers and Sentinel automatically detects its slaves.
When a master server dies, Sentinel will make sure one of the slaves is promoted to be the new master. This autofailover mechanism will also demote failed masters to avoid data inconsistency.
The Credis_Cluster objects and will set the master and slaves accordingly.
Sentinel uses the same protocol as Redis. In the example below we register the Sentinel server running on port 26379 and assign it to the Credis_Sentinel object. We then ask Sentinel the hostname and port for the master server known as mymaster. By calling the getCluster method we immediately get a Credis_Cluster object that allows us to perform basic Redis calls.
Additional parameters
Because Credis_Cluster objects using the "getCluster" or "createCluster" methods, additional parameters can be passed.
First of all there's the "write_only" flag. You can also define the selected database and the number of replicas. And finally there's a "selectRandomSlave" option.
The "selectRandomSlave" flag is used in setups for masters that have multiple slaves. The Credis_Sentinel will either select one random slave to be used when creating the Credis_Cluster object or to pass them all and use the built-in hashing.
The example below shows how to use these 3 options. It selects database 2, sets the number of replicas to 10, it doesn't select a random slave and doesn't allow reading on the master server.
About
© 2017 Icyboy