Comments (12)
CodeIgniter's singleton oriented approach definitely is the culprit here.
When looking at the way CI handles multiple database connections (http://ellislab.com/codeigniter/user-guide/database/connecting.html) you see they added an extra parameter to return the object. Sadly this is not an option when loading libraries.
Another possibility would be to use the second and third argument in the Load::library()
method:
$this->load->library('redis', array('connection_group' => 'slave'), 'redis_slave');
// Instance of the class using this connection group would now be available like this
$this->redis_slave->ping();
As for backwards compatibility, ensuring compatibility with the current config structure would be preferable. I'd also suggest that you always connect to the master, without the need of running connect()
. If this is about performance, we can always decided to move it the the encode_request()
method and only connect on demand.
from codeigniter-redis.
Joel your suggestions were spot-on! π
I wasn't aware of the ability to assign a library to a different object name. That's so much better!!
I added this functionality in a new branch, you'll notice it doesn't require many changes and maintains backwards compatibility.
Tell me what you think.
from codeigniter-redis.
Looking good, but I'm not really a fan having multiple config files. What's the use case for this? Using a multidimensional array for the different connection groups would be better IMHO, just like CI does for databases.
$config['default']['redis_host'] = 'localhost';
$config['default']['redis_port'] = '6379';
$config['default']['redis_password'] = '';
$config['slave']['redis_host'] = 'otherhost';
$config['slave']['redis_port'] = '6379';
$config['slave']['redis_password'] = '';
If the config array isn't multidimensional (i.e. there is no 'default' key) it would assume you're using the old configuration style.
from codeigniter-redis.
hmmm.... yeah the problem is PHP doesn't allow using an array as a key inside an array. Once again I'm not sure what kind of magic CI is using for databases, but it's the only place i've seen that type of config in PHP.
Perhaps this: ??
$config['redis_host'] = 'localhost';
$config['redis_port'] = '6379';
$config['redis_password'] = '';
$config['redis_host_slave'] = 'otherhost';
$config['redis_port_slave'] = '6379';
$config['redis_password_slave'] = '';
from codeigniter-redis.
I pulled in your branch and made some changes for the solution I was thinking of. Let me know what you think. https://github.com/joelcox/codeigniter-redis/tree/multiple-servers. I moved 'redis' in front of the connection group to keep config items from colliding. This solutions allows for the following config styles:
$config['redis_default']['host'] = 'localhost';
$config['redis_default']['password'] = '1234';
$config['redis_default']['port'] = 'topsecret';
$config['redis_slave']['host'] = 'otherhost';
$config['redis_slave']['password'] = '1234';
$config['redis_slave']['port'] = 'topsecret2';
and the old style:
$config['redis_host'] = 'localhost';
$config['redis_password'] = '1234';
$config['redis_port'] = 'topsecret';
I've yet to thoroughly test the code and write tests for the branch mentioned above, but wanted to see what you think about this first.
from codeigniter-redis.
Hey Alex, care to pitch in on the changes I made to your code in the branch I mentioned above?
from codeigniter-redis.
Oh sorry for the delay! I'll have a look right now.
from codeigniter-redis.
Ah so far it appears AUTH is broken again ;)
From here: 7aac0bf
from codeigniter-redis.
OK I just tested the library with various Redis server configs, works perfectly after fixing the AUTH
issue!
from codeigniter-redis.
Great. I'll probably add some test cases this weekend and merge it into develop. Thanks for your contribution.
On Mar 28, 2013, at 3:04 PM, Alex Williams [email protected] wrote:
OK I just tested the library with various Redis server configs, works perfectly after fixing the AUTH issue!
β
Reply to this email directly or view it on GitHub.
from codeigniter-redis.
π Thanks for this library! β¨
from codeigniter-redis.
Hey Alex, I finally got around to writing some proper tests and merged the changes into develop. I added your name to the thank you section.
from codeigniter-redis.
Related Issues (20)
- _auth returns "invalid password" when $password === '' HOT 3
- In the Constructor, connection error should show $config['port'] HOT 1
- Some data does not properly return from redis HOT 6
- Set json string as value HOT 5
- test_empty_hash_values fails after changing bulk reply code HOT 8
- The library sometimes returns OK when getting data HOT 3
- Unable to connect to redis with a correct password HOT 7
- Cannot get limit to work - could be related to spaces?
- mget have no return and aways waiting
- _multi_bulk_reply is not working
- Redis pipeline - batch get HOT 4
- multi & exec hmget failed HOT 5
- method _bulk_reply is not returning the correct data HOT 3
- Deprecating this library HOT 2
- No way to check if redis is running HOT 4
- Any Support for Codeigniter 3+
- δ½Ώη¨scanε½δ»€ζΆθΏεεΌεΊι
- How can i set time for expire. HOT 3
- $this->redis->command('PING'); Error :: command On null()
- How can i use this in cli? HOT 2
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 codeigniter-redis.