Comments (4)
Adding support for named connections that uses an alias instead of the ip:port pair for the hashring should be quite easy with the development version of Predis by creating a subclass of PredisCluster that overrides Predis\Network\PredisCluster::add()
to use the already existing (but optional) alias
property for a connection. The configuration of the client would then look something like the following snippet:
SNIPPET REMOVED
Might end up adding this one as an optional cluster connection since it's quite easy.
UPDATE: well, I got it wrong... but it's still something easy to implement :-) See my next comment for more details.
Regarding a transparent master/slave configuration (@Seldaek's request), I'm still not sure how to implement this in a good way and, more than anything else, I don't think it could work decently alongside a clustered scenario (at least due to how Predis is structured right now).
Comments?
EDIT: I forgot to give you a clear answer about the case when the cluster configuration is changed! With the default implementation of a client-side cluster, when you change an ip:port pair of one of your Redis instances then you inevitably incur in the rehashing of some keys. With the proposed named-nodes approach, reashing occurs only when the number of nodes in your cluster configuration changes.
from predis.
Thanks for the response, and I'm glad to hear it's not a hard thing to do - That would be awesome!
Any estimate on when we'd see the cluster functionality released?
from predis.
Heh I got things a bit wrong, that's how it goes when spending a whole month without touching a single line of code :-) The distribution algorithm used by Predis\Network\PredisCluster
can be already customized using different distribution strategies, by default it's Predis\Distribution\HashRing
which uses the classic ip:port pair.
After pushing this slight change it's now possible to reuse most of the code of Predis\Distribution\HashRing
when, in a subclass, we just need to change how we get the hash of a node. With this change we can implement our strategy that calculates the hash of a node against its alias with very few lines of code:
<?php
class AliasBasedHashRing extends Predis\Distribution\HashRing {
public function add($node, $weight = null) {
$parameters = $node->getParameters();
if (!$parameters->isSetByUser('alias')) {
throw new \InvalidArgumentException(
"The 'alias' property must be set for {$node} to use " .
"this kind of distribution strategy"
);
}
parent::add($node, $weight);
}
protected function getNodeHash($nodeObject) {
return $nodeObject->getParameters()->alias;
}
}
You can find a complete and usable example in this gist. If you change the configuration of the nodes (e.g. you move one of them to a new port, or a completely new host) you'll notice that the number of keys for each node won't change.
I'm still not sure if, when and how I will merge this into the main repository (btw, the name AliasBasedHashRing is terrible!). It's something quite small and very specific that it could live in a future side-project related to Predis. In the meanwhile you can just get this class and use it in your project just like I did in the linked example.
I'll just leave this issue open for now until I decide how to proceed.
from predis.
It's been a while but I finally came up with something easy enough to set up in user's code and way more flexible than my previously proposed solution.
As explained in the message of 09de7be, you can now instruct the client to use the alias
parameter instead the default ip:port
pair using options and without the need to extend a base class:
use Predis\Cluster\Distribution\HashRing;
use Predis\Connection\PredisCluster;
$servers = array(
'tcp://10.0.0.1?alias=node01',
'tcp://10.0.0.2?alias=node02',
);
$options = array(
'nodehash' => function ($connection) {
return $connection->getParameters()->alias;
},
'cluster' => function ($options) {
$replicas = HashRing::DEFAULT_REPLICAS;
$hashring = new HashRing($replicas, $options->nodehash);
$cluster = new PredisCluster($hashring);
return $cluster;
}
);
$client = new Predis\Client($servers, $options);
This change will make it into Predis v0.8.1.
from predis.
Related Issues (20)
- Provide a hook so that a user can delete something from the cache storage
- Get from local cache
- Determine internal format of the cache (i.e is it key of value/expiration pairs, or something else)
- Save in local cache (presumably with an expiration)
- Cache configuration objects (to support memory, number of keys, etc)
- [v3] cherry-pick opt out setinfo for v3 HOT 1
- Update CLIENT-SETINFO to support suffixes HOT 1
- Missing BITFIELD_RO support HOT 1
- psubscribe seems to swallow exit, exceptions, disconnect, quit calls HOT 4
- Add support for GEOSHAPE index fields and WITHIN and CONTAINS query operators
- Error while writing bytes to the server HOT 3
- Error on RPOP expects exactly 1 argument, 2 given HOT 2
- Explain `expireResoluton` for `SET` HOT 1
- Improve connection speed by running fewer commands
- Question: the `ClientInterface::eval` signature and PhpRedis HOT 1
- Connect to Sentinel with username: how to implement right ? HOT 3
- Add support for HSCAN [NOVALUES]
- Add command filter for CLIENT KILL to support maximum age via [MAXAGE] option
- Support XREAD, XREADGROUP reading from last message of stream
- Supporting redis unstable commands
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from predis.