Code Monkey home page Code Monkey logo

Comments (12)

joelcox avatar joelcox commented on May 18, 2024

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.

aw avatar aw commented on May 18, 2024

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.

joelcox avatar joelcox commented on May 18, 2024

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.

aw avatar aw commented on May 18, 2024

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.

joelcox avatar joelcox commented on May 18, 2024

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.

joelcox avatar joelcox commented on May 18, 2024

Hey Alex, care to pitch in on the changes I made to your code in the branch I mentioned above?

from codeigniter-redis.

aw avatar aw commented on May 18, 2024

Oh sorry for the delay! I'll have a look right now.

from codeigniter-redis.

aw avatar aw commented on May 18, 2024

Ah so far it appears AUTH is broken again ;)

From here: 7aac0bf

from codeigniter-redis.

aw avatar aw commented on May 18, 2024

OK I just tested the library with various Redis server configs, works perfectly after fixing the AUTH issue!

from codeigniter-redis.

joelcox avatar joelcox commented on May 18, 2024

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.

aw avatar aw commented on May 18, 2024

πŸ‘ Thanks for this library! ✨

from codeigniter-redis.

joelcox avatar joelcox commented on May 18, 2024

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.

297fda6

from codeigniter-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.