{"id":14977772,"url":"https://github.com/salimane/rediscluster-php","last_synced_at":"2025-10-28T05:31:02.120Z","repository":{"id":4913086,"uuid":"6069385","full_name":"salimane/rediscluster-php","owner":"salimane","description":"a PHP interface to a Cluster of Redis key-value stores.","archived":false,"fork":false,"pushed_at":"2013-08-31T10:45:58.000Z","size":248,"stargazers_count":26,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T12:11:12.357Z","etag":null,"topics":["cluster","php","redis"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"abhishekkr/eden_guide_to_vim","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/salimane.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-04T01:35:34.000Z","updated_at":"2024-01-29T06:40:43.000Z","dependencies_parsed_at":"2022-09-07T09:00:18.136Z","dependency_job_id":null,"html_url":"https://github.com/salimane/rediscluster-php","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salimane%2Frediscluster-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salimane%2Frediscluster-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salimane%2Frediscluster-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salimane%2Frediscluster-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salimane","download_url":"https://codeload.github.com/salimane/rediscluster-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603665,"owners_count":19499488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cluster","php","redis"],"created_at":"2024-09-24T13:56:18.620Z","updated_at":"2025-10-28T05:30:56.870Z","avatar_url":"https://github.com/salimane.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"rediscluster-php\n===============\n\na PHP interface to a Cluster of Redis key-value stores.\n\nProject Goals\n-------------\n\nThe goal of ``rediscluster-php``, together with `rediscluster-py \u003chttps://github.com/salimane/rediscluster-py.git\u003e`_,\nis to have a consistent, compatible client libraries accross programming languages\nwhen sharding among different Redis instances in a transparent, fast, and\nfault tolerant way. ``rediscluster-php`` uses `phpredis \u003chttps://github.com/nicolasff/phpredis.git\u003e`_\nwhen connecting to the redis servers, thus the original api commands would work without problems within\nthe context of a cluster of redis servers.\n\nContinuous Integration\n------------------------------\n\nCurrently, ``rediscluster-php`` is being tested via travis/drone.io ci for php\nversion 5.3 and 5.4: |Travis Status| |Drone.io Status|\n\nInstallation\n------------\n\nDownload via `Composer \u003chttp://getcomposer.org/\u003e`_\nCreate a ``composer.json`` file if you don't already have one in your projects root directory and require rediscluster:\n\n::\n\n    {\n      \"require\": {\n        \"rediscluster/rediscluster\": \"0.5.*\"\n      }\n    }\n\nInstall Composer:\n\n::\n\n    $ curl -s http://getcomposer.org/installer | php\n\nRun the install command:\n\n::\n\n    $ php composer.phar install\n\nThis will download ``rediscluster`` into the `vendor/rediscluster/rediscluster` directory.\nTo learn more about Composer visit http://getcomposer.org/\n\nRunning Tests\n-------------\n\n::\n\n    $ git clone https://github.com/salimane/rediscluster-php.git\n    $ cd rediscluster-php\n    $ vi Tests/config.php\n    $ phpunit\n\nGetting Started\n---------------\n\n::\n\n    php -a\n    Interactive shell\n\n    php \u003e require \"/home/salimane/htdocs/rediscluster-php/vendor/autoload.php\";\n    php \u003e $cluster = array(\n    php (     //node names\n    php (     'nodes' =\u003e array(\n    php (       //masters\n    php (       'node_1' =\u003e array('host' =\u003e '127.0.0.1', 'port' =\u003e 63791),\n    php (       'node_2' =\u003e array('host' =\u003e '127.0.0.1', 'port' =\u003e 63792),\n    php (     )\n    php ( );\n    php \u003e\n    php \u003e $r = new RedisCluster\\RedisCluster($cluster, 4);\n    php \u003e var_dump($r-\u003eset('foo', 'bar'));\n    bool(true)\n    php \u003e var_dump($r-\u003eget('foo'));\n    string(3) \"bar\"\n\n\nCluster Configuration\n---------------------\n\nThe cluster configuration is a hash that is mostly based on the idea of a node, which is simply a host:port pair\nthat points to a single redis-server instance. This is to make sure it doesn’t get tied it\nto a specific host (or port).\nThe advantage of this is that it is easy to add or remove nodes from\nthe system to adjust the capacity while the system is running.\n\nRead Slaves \u0026 Write Masters\n---------------------------\n\n``rediscluster``, by default, uses the master servers stored in the cluster hash passed during instantiation to auto discover\nif any slave is attached to them. It then transparently relay read redis commands to slaves and writes commands to masters.\n\nThere is also support to only use masters even if read redis commands are issued, just specify it at client instantiation like :\n\n::\n\n    php \u003e $r = new RedisCluster\\RedisCluster($cluster, 4); // read redis commands are routed to slaves\n    ...\n    php \u003e $r = new RedisCluster\\RedisCluster($cluster, 4, true); // read redis commands are routed to masters\n    ...\n\nPartitioning Algorithm\n----------------------\n\nIn order to map every given key to the appropriate Redis node, the algorithm used, based on crc32 and modulo, is :\n\n::\n\n    ((abs(crc32(\u003ckey\u003e)) % \u003cnumber of masters\u003e) + 1)\n\n\nA function ``getnodefor`` is provided to get the node a particular key will be/has been stored to.\n\n::\n\n    php \u003e print_r($r-\u003egetnodefor('foo'));\n    Array\n    (\n        [node_2] =\u003e Array\n            (\n                [host] =\u003e 127.0.0.1\n                [port] =\u003e 63792\n            )\n\n    )\n    php \u003e\n\nHash Tags\n-----------\n\nIn order to specify your own hash key (so that related keys can all land\non a given node), ``rediscluster`` allows you to pass a string  in the form \"a{b}\" where you’d normally pass a scalar.\nThe first element of the list is the key to use for the hash and the\nsecond is the real key that should be fetched/modify:\n\n::\n\n    php \u003e $r-\u003eget(\"bar{foo}\")\n    ...\n    php \u003e $r-\u003emset(array(\"bar{foo}\" =\u003e \"bar\", \"foo\" =\u003e \"foo\"))\n    ...\n    php \u003e $r-\u003emget(array(\"bar{foo}\", \"foo\"))\n\nIn that case “foo” is the hash key but “bar” is still the name of\nthe key that is fetched from the redis node that “foo” hashes to.\n\nMultiple Keys Redis Commands\n----------------------------\n\nIn the context of storing an application data accross many redis servers, commands taking multiple keys\nas arguments are harder to use since, if the two keys will hash to two different\ninstances, the operation can not be performed. Fortunately, rediscluster is a little fault tolerant\nin that it still fetches the right result for those multi keys operations as far as the client is concerned.\nTo do so it processes the related involved redis servers at interface level.\n\n::\n\n    php \u003e foreach(array('b1', 'a2', 'b3') as $i) $r-\u003esadd('bar', $i);\n    php \u003e foreach(array('a1', 'a2', 'a3') as $i) $r-\u003esadd('foo', $i);\n    php \u003e var_dump($r-\u003esdiffstore('foobar', 'foo', 'bar'));\n    int(2)\n    php \u003e\n    php \u003e print_r($r-\u003esmembers('foobar'));\n    Array\n    (\n        [0] =\u003e a1\n        [1] =\u003e a3\n    )\n    php \u003e\n    php \u003e print_r($r-\u003egetnodefor('foo'));\n    Array\n    (\n        [node_2] =\u003e Array\n            (\n                [host] =\u003e 127.0.0.1\n                [port] =\u003e 63792\n            )\n\n    )\n    php \u003e print_r($r-\u003egetnodefor('bar'));\n    Array\n    (\n        [node_1] =\u003e Array\n            (\n                [host] =\u003e 127.0.0.1\n                [port] =\u003e 63791\n            )\n\n    )\n    php \u003e print_r($r-\u003egetnodefor('foobar'));\n    Array\n    (\n        [node_2] =\u003e Array\n            (\n                [host] =\u003e 127.0.0.1\n                [port] =\u003e 63792\n            )\n\n    )\n    php \u003e\n\n\nRedis-Sharding \u0026 Redis-Copy\n---------------------------\n\nIn order to help with moving an application with a single redis server to a cluster of redis servers\nthat could take advantage of ``rediscluster``, i wrote `redis-sharding \u003chttps://github.com/salimane/redis-tools#redis-sharding\u003e`_\nand `redis-copy \u003chttps://github.com/salimane/redis-tools#redis-copy\u003e`_\n\nInformation\n-----------\n\n-  Code: ``git clone git://github.com/salimane/rediscluster-php.git``\n-  Home: http://github.com/salimane/rediscluster-php\n-  Bugs: http://github.com/salimane/rediscluster-php/issues\n\nAuthor\n------\n\n``rediscluster-php`` is developed and maintained by Salimane Adjao Moustapha\n(me@salimane.com). It can be found here:\nhttp://github.com/salimane/rediscluster-php\n\n.. |Travis Status| image:: https://secure.travis-ci.org/salimane/rediscluster-php.png?branch=master\n   :target: http://travis-ci.org/salimane/rediscluster-php\n.. |Drone.io Status| image:: https://drone.io/github.com/salimane/rediscluster-php/status.png\n   :target: https://drone.io/github.com/salimane/rediscluster-php/latest\n\n.. image:: https://d2weczhvl823v0.cloudfront.net/salimane/rediscluster-php/trend.png\n   :alt: Bitdeli badge\n   :target: https://bitdeli.com/free\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalimane%2Frediscluster-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalimane%2Frediscluster-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalimane%2Frediscluster-php/lists"}