Skip to content
Browse files

init

  • Loading branch information...
1 parent e6f4555 commit 6e07e5d86278ac48f9fb6a2aa39385ff28e57d8d @JeremyWei committed Jul 3, 2012
Showing with 122 additions and 0 deletions.
  1. +8 −0 LICENSE.md
  2. 0 README
  3. +31 −0 README.md
  4. +72 −0 classes/kohana/koredis.php
  5. +3 −0 classes/koredis.php
  6. +8 −0 config/koredis.php
View
8 LICENSE.md
@@ -0,0 +1,8 @@
+The MIT License (MIT)
+Copyright (c) 2012 Jeremy Wei
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
0 README
No changes.
View
31 README.md
@@ -0,0 +1,31 @@
+# koredis
+
+This module is a wrapper of [phpredis](https://github.com/nicolasff/phpredis) for kohana3.x.
+So make sure you have installed [phpredis](https://github.com/nicolasff/phpredis) before you start.
+
+## Installation
+
+ git submodule git@github.com:JeremyWei/koredis.git modules/koredis
+ git submodule update --init --recursive
+
+## Using
+
+Enable:
+
+ Kohana::modules(array(
+ //'auth' => MODPATH.'auth', // Basic authentication
+ 'cache' => MODPATH.'cache', // Caching with multiple backends
+ 'codebench' => MODPATH.'codebench', // Benchmarking tool
+ 'database' => MODPATH.'database', // Database access
+ // 'image' => MODPATH.'image', // Image manipulation
+ // 'orm' => MODPATH.'orm', // Object Relationship Mapping
+ 'unittest' => MODPATH.'unittest', // Unit testing
+ // 'userguide' => MODPATH.'userguide', // User guide and API documentation
+ 'koredis' => MODPATH.'koredis', // Redis
+ ));
+
+Example:
+
+ $redis = Koredis::factory();
+ $redis->set('foo', 'bar');
+ $redis->get('foo');
View
72 classes/kohana/koredis.php
@@ -0,0 +1,72 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * A wrapper of [phpredis](https://github.com/nicolasff/phpredis)
+ * for kohana3.x.
+ *
+ * @package Koredis
+ * @category Redis
+ * @author Jeremy Wei
+ * @copyright (c) 2012 Jeremy Wei
+ * @license http://www.opensource.org/licenses/mit-license.php
+ */
+class Kohana_Koredis {
+
+ /**
+ * single instance of the Redis object
+ *
+ * @var Redis
+ **/
+ private static $redis;
+
+ /**
+ * Returns the singleton instance of Redis. If no instance has
+ * been created, a new instance will be created.
+ *
+ * $redis = Koredis::factory();
+ *
+ * @return Kohana_Koredis
+ **/
+ public static function factory()
+ {
+ if (!Kohana_Koredis::$redis)
+ {
+ // Make sure Redis installed
+ if (!class_exists('Redis', FALSE))
+ {
+ throw new Kohana_Exception('class Redis can not be found. make sure
+ you have installed phpredis extension');
+ }
+
+ Kohana_Koredis::$redis = new Redis();
+
+ // No config file found
+ if (!Kohana::$config->load('koredis'))
+ {
+ Kohana_Koredis::$redis->pconnect('127.0.0.1', 6379, 1);
+ }
+ else
+ {
+ // Load config
+ $config = Kohana::$config->load('koredis');
+
+ $host = isset($config['host']) && ($config['host']) ? $config['host'] : '127.0.0.1';
+ $port = isset($config['port']) && ($config['port']) ? $config['port'] : 6379;
+ $timeout = isset($config['timeout']) && ($config['timeout']) ? $config['timeout'] : 1;
+ $pconnect = isset($config['pconnect']) && ($config['pconnect']) ? $config['pconnect'] : TRUE;
+
+ // Persistent connection
+ if ($pconnect === TRUE)
+ {
+ Kohana_Koredis::$redis->pconnect($host, $port, $timeout);
+ }
+ // Non persistent connection
+ else
+ {
+ Kohana_Koredis::$redis->connect($host, $port, $timeout);
+ }
+ }
+ }
+
+ return Kohana_Koredis::$redis;
+ }
+}
View
3 classes/koredis.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Koredis extends Kohana_Koredis {}
View
8 config/koredis.php
@@ -0,0 +1,8 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+return array(
+ 'host' => '127.0.0.1', // ip address or Unix socket(for example: /tmp/redis.sock), 127.0.0.1 default
+ 'port' => 6379, // port, 6379 default
+ 'timeout' => 1, // timeout, 1s default
+ 'pconnect' => TRUE, // whether using pconnect, TRUE default
+);

0 comments on commit 6e07e5d

Please sign in to comment.
Something went wrong with that request. Please try again.