Git Product home page Git Product logo

codeigniter-redis's Introduction

CodeIgniter Redis

This library is deprecated. We recommend migrating to Predis.

A CodeIgniter interface for the Redis data store. This library tries to adhere to the defined protocol, including responses.

Build Status

Requirements

  1. PHP 5+
  2. CodeIgniter 2.0+
  3. A Redis server compatible with the unified request protocol (Redis 1.2+)

Spark

This library is also released as a Spark. If you use this library in any other way, don't copy the autoload.php to your config directory.

Breaking changes

As of v0.4, this library does not longer support the plain text syntax for overloaded commands (i.e. $this->redis->set('foo bar')). Please pass extra command arguments as real PHP arguments instead (i.e. $this->redis->set('foo', 'bar')). You can still use the plain text syntax using the command method (e.g. $this->redis->command('SET foo bar')) if you need this functionality.

Documentation

Configuration

This library expects a configuration file to function correctly. A template for this file is provided with the library.

Multiple connection groups

If you want to use multiple Redis servers, you can add an additional array to the configuration file with the details of this server.

$config['redis_slave']['host'] = 'otherhost';
$config['redis_slave']['port'] = '6379';
$config['redis_slave']['password'] = '';

To use this connection group, you must create a new instance of this library like this:

$this->load->library('redis', array('connection_group' => 'slave'), 'redis_slave');
$this->redis_slave->command('PING')

This will create a new object named redis_slave which will use the configuration options of the slave connection group. The default connection group is loaded by when no connection group is specified.

Generic command

You can execute any command using the command() method, just like you're using redis-cli.

$this->redis->command('PING');

This library also support PHP's overloading functionality. This means you can call undefined methods, which are then dynamically created for you. These calls are routed to the generic __call() method. You can also pass in arrays.

$this->redis->hmset('foohash', array('key1' => 'value1', 'key2' => 'value2'));

Examples

Set a new key with a value and retrieve it again

$this->redis->set('foo', 'bar');

Get a value by its key

$this->redis->get('foo');

Delete a bunch of keys

$this->redis->del(array('foo', 'foo2'));

Working with lists

Because PHP lacks basic list and dictionary/map/hash data types, this library tries to detect this on its own. This is done by using the following heuristic; if the smallest key in an array equals 0 and the largest key equals the length of the array - 1, the array is considered to be a list. In this case, the library's internals will automatically strip away the keys before passing the array to the Redis server.

Contributing

I am a firm believer of social coding, so if you find a bug, please fork this code on GitHub and squash it. I will be happy to merge it back in to the code base (and add you to the "Thanks to" section). If you're not too comfortable using Git or messing with the inner workings of this library, please open a new issue.

License

This library is released under the MIT license.

Thanks to

Cheers, –– Joël Cox

codeigniter-redis's People

Contributors

aw avatar axelay avatar danhunsaker avatar integrii avatar joelcox avatar panman avatar swznd avatar

Watchers

 avatar

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.