Permalink
Browse files

Module updates

  • Loading branch information...
jmhobbs committed Apr 18, 2012
1 parent 8d64e6e commit a625f51dfc29c04040293ede209a6a474ccd2c4b
Showing with 48,958 additions and 112 deletions.
  1. +17 −13 www/config/modules.php
  2. +19 −0 www/modules/cache_redis/LICENSE
  3. +63 −0 www/modules/cache_redis/README.md
  4. +2 −0 www/modules/cache_redis/VERSION
  5. +4 −0 www/modules/cache_redis/classes/cache/redis.php
  6. +256 −0 www/modules/cache_redis/classes/kohana/cache/redis.php
  7. +14 −0 www/modules/cache_redis/config/cache.php
  8. +22 −0 www/modules/cache_redis/vendor/redisent/LICENSE.txt
  9. +67 −0 www/modules/cache_redis/vendor/redisent/README.markdown
  10. +150 −0 www/modules/cache_redis/vendor/redisent/redisent.php
  11. +139 −0 www/modules/cache_redis/vendor/redisent/redisent_cluster.php
  12. +7 −0 www/modules/eorm/LICENSE
  13. +53 −6 www/modules/eorm/README.md
  14. +2 −0 www/modules/eorm/VERSION
  15. +94 −40 www/modules/eorm/classes/kohana/eorm.php
  16. +53 −6 www/modules/eorm/guide/eorm/index.md
  17. +19 −0 www/modules/faker/LICENSE
  18. +47 −0 www/modules/faker/README.md
  19. +4 −0 www/modules/faker/TODO
  20. +2 −0 www/modules/faker/VERSION
  21. +64 −0 www/modules/faker/classes/faker.php
  22. +34 −0 www/modules/faker/classes/kohana/faker.php
  23. +165 −0 www/modules/faker/classes/kohana/faker/address.php
  24. +65 −0 www/modules/faker/classes/kohana/faker/company.php
  25. +164 −0 www/modules/faker/classes/kohana/faker/internet.php
  26. +72 −0 www/modules/faker/classes/kohana/faker/lipsum.php
  27. +95 −0 www/modules/faker/classes/kohana/faker/module.php
  28. +62 −0 www/modules/faker/classes/kohana/faker/name.php
  29. +38 −0 www/modules/faker/classes/kohana/faker/phone.php
  30. +76 −0 www/modules/faker/config/faker/en/catch_phrase.php
  31. +4 −0 www/modules/faker/config/faker/en/city_prefix.php
  32. +8 −0 www/modules/faker/config/faker/en/city_suffix.php
  33. +4 −0 www/modules/faker/config/faker/en/company_suffix.php
  34. +59 −0 www/modules/faker/config/faker/en/country_name.php
  35. +4 −0 www/modules/faker/config/faker/en/domain_suffix.php
  36. +508 −0 www/modules/faker/config/faker/en/first_name.php
  37. +4 −0 www/modules/faker/config/faker/en/free_email_domain.php
  38. +84 −0 www/modules/faker/config/faker/en/last_name.php
  39. +25 −0 www/modules/faker/config/faker/en/lipsum.php
  40. +11 −0 www/modules/faker/config/faker/en/phone_number.php
  41. +7 −0 www/modules/faker/config/faker/en/postal_code.php
  42. +4 −0 www/modules/faker/config/faker/en/secondary_address.php
  43. +10 −0 www/modules/faker/config/faker/en/state_abbreviation.php
  44. +14 −0 www/modules/faker/config/faker/en/state_name.php
  45. +4 −0 www/modules/faker/config/faker/en/street_number.php
  46. +36 −0 www/modules/faker/config/faker/en/street_suffix.php
  47. +14 −0 www/modules/faker/config/userguide.php
  48. +1,719 −0 www/modules/faker/doxygen.cfg
  49. +43 −0 www/modules/faker/guide/faker/index.md
  50. +1 −0 www/modules/faker/guide/faker/menu.md
  51. +48 −0 www/modules/faker/views/faker/example.php
  52. +2 −0 www/modules/mailer/VERSION
  53. +2 −0 www/modules/mailer_log/VERSION
  54. +2 −0 www/modules/message/VERSION
  55. +2 −0 www/modules/simpleauth/VERSION
  56. +0 −47 www/modules/simpleauth/classes/simpleauth/orm/auth.php
  57. +19 −0 www/modules/simpletest/LICENSE
  58. +43 −0 www/modules/simpletest/README.html
  59. +36 −0 www/modules/simpletest/README.md
  60. +2 −0 www/modules/simpletest/VERSION
  61. +4 −0 www/modules/simpletest/classes/controller/simpletest.php
  62. +76 −0 www/modules/simpletest/classes/kohana/controller/simpletest.php
  63. +29 −0 www/modules/simpletest/classes/kohana/simpletest/group.php
  64. +74 −0 www/modules/simpletest/classes/kohana/simpletest/reporter.php
  65. +13 −0 www/modules/simpletest/classes/kohana/simpletest/test.php
  66. +6 −0 www/modules/simpletest/classes/kohana/simpletest/test/error.php
  67. +12 −0 www/modules/simpletest/classes/kohana/simpletest/test/exception.php
  68. +6 −0 www/modules/simpletest/classes/kohana/simpletest/test/fail.php
  69. +6 −0 www/modules/simpletest/classes/kohana/simpletest/test/pass.php
  70. +6 −0 www/modules/simpletest/classes/kohana/simpletest/test/skip.php
  71. +4 −0 www/modules/simpletest/classes/simpletest/group.php
  72. +4 −0 www/modules/simpletest/classes/simpletest/reporter.php
  73. +3 −0 www/modules/simpletest/classes/simpletest/test.php
  74. +3 −0 www/modules/simpletest/classes/simpletest/test/error.php
  75. +3 −0 www/modules/simpletest/classes/simpletest/test/exception.php
  76. +3 −0 www/modules/simpletest/classes/simpletest/test/fail.php
  77. +3 −0 www/modules/simpletest/classes/simpletest/test/pass.php
  78. +4 −0 www/modules/simpletest/classes/simpletest/test/skip.php
  79. +12 −0 www/modules/simpletest/config/simpletest.php.example
  80. +8 −0 www/modules/simpletest/init.php
  81. +17 −0 www/modules/simpletest/tests/unit/example.php
  82. +18 −0 www/modules/simpletest/tests/unit/exceptional.php
  83. +399 −0 www/modules/simpletest/vendor/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE
  84. +502 −0 www/modules/simpletest/vendor/simpletest/LICENSE
  85. +102 −0 www/modules/simpletest/vendor/simpletest/README
  86. +1 −0 www/modules/simpletest/vendor/simpletest/VERSION
  87. +237 −0 www/modules/simpletest/vendor/simpletest/authentication.php
  88. +99 −0 www/modules/simpletest/vendor/simpletest/autorun.php
  89. +1,144 −0 www/modules/simpletest/vendor/simpletest/browser.php
  90. +122 −0 www/modules/simpletest/vendor/simpletest/collector.php
  91. +166 −0 www/modules/simpletest/vendor/simpletest/compatibility.php
  92. +380 −0 www/modules/simpletest/vendor/simpletest/cookies.php
  93. +163 −0 www/modules/simpletest/vendor/simpletest/default_reporter.php
  94. +96 −0 www/modules/simpletest/vendor/simpletest/detached.php
  95. +378 −0 www/modules/simpletest/vendor/simpletest/docs/en/authentication_documentation.html
  96. +501 −0 www/modules/simpletest/vendor/simpletest/docs/en/browser_documentation.html
  97. +121 −0 www/modules/simpletest/vendor/simpletest/docs/en/docs.css
  98. +476 −0 www/modules/simpletest/vendor/simpletest/docs/en/expectation_documentation.html
  99. +351 −0 www/modules/simpletest/vendor/simpletest/docs/en/form_testing_documentation.html
  100. +252 −0 www/modules/simpletest/vendor/simpletest/docs/en/group_test_documentation.html
  101. +542 −0 www/modules/simpletest/vendor/simpletest/docs/en/index.html
  102. +870 −0 www/modules/simpletest/vendor/simpletest/docs/en/mock_objects_documentation.html
  103. +487 −0 www/modules/simpletest/vendor/simpletest/docs/en/overview.html
  104. +457 −0 www/modules/simpletest/vendor/simpletest/docs/en/partial_mocks_documentation.html
  105. +616 −0 www/modules/simpletest/vendor/simpletest/docs/en/reporter_documentation.html
  106. +442 −0 www/modules/simpletest/vendor/simpletest/docs/en/unit_test_documentation.html
  107. +588 −0 www/modules/simpletest/vendor/simpletest/docs/en/web_tester_documentation.html
  108. +371 −0 www/modules/simpletest/vendor/simpletest/docs/fr/authentication_documentation.html
  109. +500 −0 www/modules/simpletest/vendor/simpletest/docs/fr/browser_documentation.html
  110. +84 −0 www/modules/simpletest/vendor/simpletest/docs/fr/docs.css
  111. +451 −0 www/modules/simpletest/vendor/simpletest/docs/fr/expectation_documentation.html
  112. +353 −0 www/modules/simpletest/vendor/simpletest/docs/fr/form_testing_documentation.html
  113. +401 −0 www/modules/simpletest/vendor/simpletest/docs/fr/group_test_documentation.html
  114. +576 −0 www/modules/simpletest/vendor/simpletest/docs/fr/index.html
  115. +784 −0 www/modules/simpletest/vendor/simpletest/docs/fr/mock_objects_documentation.html
  116. +321 −0 www/modules/simpletest/vendor/simpletest/docs/fr/overview.html
  117. +464 −0 www/modules/simpletest/vendor/simpletest/docs/fr/partial_mocks_documentation.html
  118. +538 −0 www/modules/simpletest/vendor/simpletest/docs/fr/reporter_documentation.html
  119. +450 −0 www/modules/simpletest/vendor/simpletest/docs/fr/unit_test_documentation.html
  120. +570 −0 www/modules/simpletest/vendor/simpletest/docs/fr/web_tester_documentation.html
  121. +407 −0 www/modules/simpletest/vendor/simpletest/dumper.php
  122. +307 −0 www/modules/simpletest/vendor/simpletest/eclipse.php
  123. +649 −0 www/modules/simpletest/vendor/simpletest/encoding.php
  124. +267 −0 www/modules/simpletest/vendor/simpletest/errors.php
  125. +226 −0 www/modules/simpletest/vendor/simpletest/exceptions.php
  126. +984 −0 www/modules/simpletest/vendor/simpletest/expectation.php
  127. +196 −0 www/modules/simpletest/vendor/simpletest/extensions/pear_test_case.php
  128. +53 −0 www/modules/simpletest/vendor/simpletest/extensions/testdox.php
  129. +107 −0 www/modules/simpletest/vendor/simpletest/extensions/testdox/test.php
  130. +361 −0 www/modules/simpletest/vendor/simpletest/form.php
  131. +592 −0 www/modules/simpletest/vendor/simpletest/frames.php
  132. +628 −0 www/modules/simpletest/vendor/simpletest/http.php
  133. +139 −0 www/modules/simpletest/vendor/simpletest/invoker.php
  134. +1,641 −0 www/modules/simpletest/vendor/simpletest/mock_objects.php
  135. +542 −0 www/modules/simpletest/vendor/simpletest/page.php
  136. +1,054 −0 www/modules/simpletest/vendor/simpletest/php_parser.php
  137. +136 −0 www/modules/simpletest/vendor/simpletest/reflection_php4.php
  138. +386 −0 www/modules/simpletest/vendor/simpletest/reflection_php5.php
  139. +115 −0 www/modules/simpletest/vendor/simpletest/remote.php
  140. +445 −0 www/modules/simpletest/vendor/simpletest/reporter.php
  141. +875 −0 www/modules/simpletest/vendor/simpletest/scorer.php
  142. +141 −0 www/modules/simpletest/vendor/simpletest/selector.php
  143. +330 −0 www/modules/simpletest/vendor/simpletest/shell_tester.php
  144. +391 −0 www/modules/simpletest/vendor/simpletest/simpletest.php
  145. +312 −0 www/modules/simpletest/vendor/simpletest/socket.php
  146. +1,527 −0 www/modules/simpletest/vendor/simpletest/tag.php
  147. +1,729 −0 www/modules/simpletest/vendor/simpletest/test/acceptance_test.php
  148. +50 −0 www/modules/simpletest/vendor/simpletest/test/adapter_test.php
  149. +13 −0 www/modules/simpletest/vendor/simpletest/test/all_tests.php
  150. +145 −0 www/modules/simpletest/vendor/simpletest/test/authentication_test.php
  151. +23 −0 www/modules/simpletest/vendor/simpletest/test/autorun_test.php
  152. +10 −0 www/modules/simpletest/vendor/simpletest/test/bad_test_suite.php
  153. +802 −0 www/modules/simpletest/vendor/simpletest/test/browser_test.php
  154. +50 −0 www/modules/simpletest/vendor/simpletest/test/collector_test.php
  155. +40 −0 www/modules/simpletest/vendor/simpletest/test/command_line_test.php
  156. +87 −0 www/modules/simpletest/vendor/simpletest/test/compatibility_test.php
  157. +227 −0 www/modules/simpletest/vendor/simpletest/test/cookies_test.php
  158. +15 −0 www/modules/simpletest/vendor/simpletest/test/detached_test.php
  159. +88 −0 www/modules/simpletest/vendor/simpletest/test/dumper_test.php
  160. +32 −0 www/modules/simpletest/vendor/simpletest/test/eclipse_test.php
  161. +240 −0 www/modules/simpletest/vendor/simpletest/test/encoding_test.php
  162. +229 −0 www/modules/simpletest/vendor/simpletest/test/errors_test.php
  163. +183 −0 www/modules/simpletest/vendor/simpletest/test/exceptions_test.php
  164. +317 −0 www/modules/simpletest/vendor/simpletest/test/expectation_test.php
  165. +344 −0 www/modules/simpletest/vendor/simpletest/test/form_test.php
  166. +549 −0 www/modules/simpletest/vendor/simpletest/test/frames_test.php
  167. +492 −0 www/modules/simpletest/vendor/simpletest/test/http_test.php
  168. +137 −0 www/modules/simpletest/vendor/simpletest/test/interfaces_test.php
  169. +14 −0 www/modules/simpletest/vendor/simpletest/test/interfaces_test_php5_1.php
  170. +47 −0 www/modules/simpletest/vendor/simpletest/test/live_test.php
  171. +985 −0 www/modules/simpletest/vendor/simpletest/test/mock_objects_test.php
  172. +166 −0 www/modules/simpletest/vendor/simpletest/test/page_test.php
  173. +9 −0 www/modules/simpletest/vendor/simpletest/test/parse_error_test.php
  174. +642 −0 www/modules/simpletest/vendor/simpletest/test/parsing_test.php
  175. +489 −0 www/modules/simpletest/vendor/simpletest/test/php_parser_test.php
  176. +61 −0 www/modules/simpletest/vendor/simpletest/test/reflection_php4_test.php
  177. +263 −0 www/modules/simpletest/vendor/simpletest/test/reflection_php5_test.php
  178. +19 −0 www/modules/simpletest/vendor/simpletest/test/remote_test.php
  179. +38 −0 www/modules/simpletest/vendor/simpletest/test/shell_test.php
  180. +42 −0 www/modules/simpletest/vendor/simpletest/test/shell_tester_test.php
  181. +58 −0 www/modules/simpletest/vendor/simpletest/test/simpletest_test.php
  182. +6 −0 www/modules/simpletest/vendor/simpletest/test/site/file.html
  183. +25 −0 www/modules/simpletest/vendor/simpletest/test/socket_test.php
  184. 0 www/modules/simpletest/vendor/simpletest/test/support/collector/collectable.1
  185. 0 www/modules/simpletest/vendor/simpletest/test/support/collector/collectable.2
  186. +3 −0 www/modules/simpletest/vendor/simpletest/test/support/empty_test_file.php
  187. +9 −0 www/modules/simpletest/vendor/simpletest/test/support/failing_test.php
  188. +1 −0 www/modules/simpletest/vendor/simpletest/test/support/latin1_sample
  189. +9 −0 www/modules/simpletest/vendor/simpletest/test/support/passing_test.php
  190. +15 −0 www/modules/simpletest/vendor/simpletest/test/support/spl_examples.php
  191. +1 −0 www/modules/simpletest/vendor/simpletest/test/support/supplementary_upload_sample.txt
  192. +7 −0 www/modules/simpletest/vendor/simpletest/test/support/test1.php
  193. +1 −0 www/modules/simpletest/vendor/simpletest/test/support/upload_sample.txt
  194. +554 −0 www/modules/simpletest/vendor/simpletest/test/tag_test.php
  195. +8 −0 www/modules/simpletest/vendor/simpletest/test/test_with_parse_error.php
  196. +61 −0 www/modules/simpletest/vendor/simpletest/test/unit_tester_test.php
  197. +49 −0 www/modules/simpletest/vendor/simpletest/test/unit_tests.php
  198. +515 −0 www/modules/simpletest/vendor/simpletest/test/url_test.php
  199. +348 −0 www/modules/simpletest/vendor/simpletest/test/user_agent_test.php
  200. +495 −0 www/modules/simpletest/vendor/simpletest/test/visual_test.php
  201. +155 −0 www/modules/simpletest/vendor/simpletest/test/web_tester_test.php
  202. +187 −0 www/modules/simpletest/vendor/simpletest/test/xml_test.php
  203. +658 −0 www/modules/simpletest/vendor/simpletest/test_case.php
  204. +382 −0 www/modules/simpletest/vendor/simpletest/tidy_parser.php
  205. +413 −0 www/modules/simpletest/vendor/simpletest/unit_tester.php
  206. +550 −0 www/modules/simpletest/vendor/simpletest/url.php
  207. +328 −0 www/modules/simpletest/vendor/simpletest/user_agent.php
  208. +1,532 −0 www/modules/simpletest/vendor/simpletest/web_tester.php
  209. +647 −0 www/modules/simpletest/vendor/simpletest/xml.php
  210. +26 −0 www/modules/simpletest/views/simpletest/html.php
  211. +11 −0 www/modules/simpletest/views/simpletest/html/group.php
  212. +7 −0 www/modules/simpletest/views/simpletest/html/test/error.php
  213. +8 −0 www/modules/simpletest/views/simpletest/html/test/exception.php
  214. +7 −0 www/modules/simpletest/views/simpletest/html/test/fail.php
  215. +7 −0 www/modules/simpletest/views/simpletest/html/test/pass.php
  216. +7 −0 www/modules/simpletest/views/simpletest/html/test/skip.php
  217. +8 −0 www/modules/simpletest/views/simpletest/index.php
  218. +79 −0 www/modules/simpletest/views/simpletest/template_html.php
  219. +4 −0 www/modules/simpletest/views/simpletest/template_text.php
  220. +21 −0 www/modules/simpletest/views/simpletest/text.php
  221. +12 −0 www/modules/simpletest/views/simpletest/text/group.php
  222. +4 −0 www/modules/simpletest/views/simpletest/text/test/error.php
  223. +7 −0 www/modules/simpletest/views/simpletest/text/test/exception.php
  224. +4 −0 www/modules/simpletest/views/simpletest/text/test/fail.php
  225. +4 −0 www/modules/simpletest/views/simpletest/text/test/pass.php
  226. +4 −0 www/modules/simpletest/views/simpletest/text/test/skip.php
  227. +3 −0 www/modules/spelling/README.md
  228. +8 −0 www/modules/spelling/TODO
  229. +61 −0 www/modules/spelling/classes/kohana/spelling.php
  230. +4 −0 www/modules/spelling/classes/spelling.php
View
@@ -4,17 +4,21 @@
* Enable modules. Modules are referenced by a relative or absolute path.
*/
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
- // 'eorm' => MODPATH.'eorm', // Enhanced ORM
- // 'image' => MODPATH.'image', // Image manipulation
- // 'mailer' => MODPATH.'mailer', // Plugin backed, view based Mail API
- // 'mailer_log' => MODPATH.'mailer_log', // Log plugin for mailer
- // 'message' => MODPATH.'message', // Flash Messages
- // 'orm' => MODPATH.'orm', // Object Relationship Mapping
- // 'simpleauth' => MODPATH.'simpleauth', // Helper Classes for Auth Applications
- // 'unittest' => MODPATH.'unittest', // Unit testing
- // 'userguide' => MODPATH.'userguide', // User guide and API documentation
+ // 'auth' => MODPATH.'auth', // Basic authentication
+ // 'cache' => MODPATH.'cache', // Caching with multiple backends
+ // 'cache_redis' => MODPATH.'cache_redis' // Backend for cache using Redis
+ // 'codebench' => MODPATH.'codebench', // Benchmarking tool
+ // 'database' => MODPATH.'database', // Database access
+ // 'eorm' => MODPATH.'eorm', // Enhanced ORM
+ // 'faker' => MODPATH.'faker', // Generate psuedo-random fake data
+ // 'image' => MODPATH.'image', // Image manipulation
+ // 'mailer' => MODPATH.'mailer', // Plugin backed, view based Mail API
+ // 'mailer_log' => MODPATH.'mailer_log', // Log plugin for mailer
+ // 'message' => MODPATH.'message', // Flash Messages
+ // 'orm' => MODPATH.'orm', // Object Relationship Mapping
+ // 'simpleauth' => MODPATH.'simpleauth', // Helper Classes for Auth Applications
+ // 'simpletest' => MODPATH.'simpletest', // Alternative unit testing module
+ // 'unittest' => MODPATH.'unittest', // Unit testing
+ // 'userguide' => MODPATH.'userguide', // User guide and API documentation
+ // 'whatcheer' => MODPATH.'whatcheer', // Bucket of scraps
));
@@ -0,0 +1,19 @@
+Copyright (c) 2011 John Hobbs
+
+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.
@@ -0,0 +1,63 @@
+K3-Cache_Redis Module
+==============
+
+A Ko3 Module by [**John Hobbs**](http://twitter.com/jmhobbs)
+
+Introduction
+------------
+
+This module provides a Redis backed cache engine for the [cache module](https://github.com/kohana/cache)
+
+Installation
+------------
+
+K3-Cache_Redis is a simple, standard module.
+
+1. Drop the source in your MODPATH folder.
+2. Add the module to Kohana::modules in your bootstrap.php
+3. Ensure you have enabled the [cache module](https://github.com/kohana/cache) as well.
+
+Usage
+-----
+
+To use K3-Cache_Redis you need to configure your Redis servers in <tt>application/config/cache.php</tt>
+
+
+Example Config:
+
+ <?php defined('SYSPATH') or die('No direct script access.');
+
+ return array(
+ 'redis' => array(
+ 'driver' => 'redis',
+ 'servers' => array(
+ array(
+ 'host' => 'localhost',
+ 'port' => 6379,
+ 'alias' => 'local',
+ ),
+ array(
+ 'host' => 'redis.domain.tld',
+ 'alias' => 'remote',
+ ),
+ ),
+ );
+
+If you provide multiple servers in your configuration the keys are hashed and safely distributed across them.
+
+Once you have it configured, use it as you would a normal cache plugin.
+
+Example:
+
+ Cache::instance( 'redis' )->set( 'key', 'value' );
+ echo Cache::instance( 'redis' )->get( 'key' );
+ // Prints "value"
+
+## Credits
+
+K3-Cache_Redis uses [Redisent](https://github.com/jdp/redisent) for Redis access.
+
+## License
+
+K3-Cache_Redis is licensed under the MIT License. See <tt>LICENSE</tt> for more details.
+
@@ -0,0 +1,2 @@
+https://github.com/jmhobbs/K3-Cache_Redis
+bcd038f - 2012-04-18
@@ -0,0 +1,4 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+ class Cache_Redis extends Kohana_Cache_Redis{}
+
@@ -0,0 +1,256 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+ /**
+ * [Kohana Cache](api/Kohana_Cache) Redis driver,
+ *
+ * ### Supported cache engines
+ *
+ * * [Redis](http://redis.io/)
+ *
+ * ### Configuration example
+ *
+ * Below is an example of a _redis_ server configuration.
+ *
+ * return array(
+ * 'default' => array( // Default group
+ * 'driver' => 'redis' // using Redis driver
+ * 'servers' => array( // Available server definitions
+ * // First redis server
+ * array(
+ * 'host' => 'localhost',
+ * 'port' => 6379,
+ * 'alias' => 'local',
+ * ),
+ * // Second redis server
+ * array(
+ * 'host' => 'redis.domain.tld',
+ * 'port' => 6379,
+ * 'alias' => 'remote',
+ * ),
+ * ),
+ * ),
+ * )
+ *
+ * In cases where only one cache group is required, if the group is named `default` there is
+ * no need to pass the group name when instantiating a cache instance.
+ *
+ * #### General cache group configuration settings
+ *
+ * Below are the settings available to all types of cache driver.
+ *
+ * Name | Required | Description
+ * -------------- | -------- | ---------------------------------------------------------------
+ * driver | __YES__ | (_string_) The driver type to use
+ * servers | __YES__ | (_array_) Associative array of server details, must include a __host__ key. (see _Redis server configuration_ below)
+ *
+ * #### Redis server configuration
+ *
+ * The following settings should be used when defining each redis server
+ *
+ * Name | Required | Description
+ * ---------------- | -------- | ---------------------------------------------------------------
+ * host | __YES__ | (_string_) The host of the redis server, i.e. __localhost__; or __127.0.0.1__; or __redis.domain.tld__
+ * port | __NO__ | (_integer_) Point to the port where redis is listening for connections. Default __6379__
+ * alias | __NO__ | (_string_) Name for direct reference to this server. Default __NULL__
+ *
+ * ### System requirements
+ *
+ * * Kohana 3.0.x
+ * * PHP 5.2.4 or greater
+ *
+ * @package Kohana/Cache
+ * @category Module
+ * @version 1.0
+ * @author John Hobbs
+ * @copyright (c) 2011 John Hobbs
+ * @license http://www.opensource.org/licenses/mit-license.php
+ */
+ class Kohana_Cache_Redis extends Cache {
+
+ /**
+ * Used as a prefix on all cache keys to make Cache_Redis::delete_all safer.
+ */
+ protected static $KEY_PREFIX = 'kohana-cache-redis-';
+
+ /**
+ * Redis resource
+ *
+ * @var Redis
+ */
+ protected $_redis;
+
+ /**
+ * The default configuration for the redis server
+ *
+ * @var array
+ */
+ protected $_default_config = array(
+ 'host' => 'localhost',
+ 'port' => 6379,
+ 'alias' => NULL,
+ );
+
+ /**
+ * Constructs the redis Kohana_Cache object
+ *
+ * @param array configuration
+ * @throws Kohana_Cache_Exception
+ */
+ protected function __construct(array $config)
+ {
+ if( ! defined( 'KOHANA_CACHE_REDIS_LOADED' ) ) {
+ $path = Kohana::find_file( 'vendor', 'redisent/redisent_cluster' );
+ if( false === $path ) {
+ throw new Kohana_Cache_Exception('Redisent vendor code not found');
+ }
+ require_once( $path );
+ define( 'KOHANA_CACHE_REDIS_LOADED', true );
+ }
+
+ parent::__construct($config);
+
+ // Load servers from configuration
+ $_servers = Arr::get( $this->_config, 'servers', NULL );
+
+ if ( ! $_servers) {
+ // Throw an exception if no server found
+ throw new Kohana_Cache_Exception('No Redis servers defined in configuration');
+ }
+
+ $servers = array();
+
+ // Normalize the settings into redisent format.
+ foreach( $_servers as $server ) {
+
+ $server += $this->_default_config;
+
+ if( is_null( $server['alias'] ) ) {
+ $servers[] = array( 'host' => $server['host'], 'port' => $server['port'] );
+ }
+ else {
+ $servers[$server['alias']] = array( 'host' => $server['host'], 'port' => $server['port'] );
+ }
+
+ }
+
+ // Setup Redis
+ $this->_redis = new RedisentCluster( $servers );
+ }
+
+ /**
+ * Retrieve a cached value entry by id.
+ *
+ * // Retrieve cache entry from redis group
+ * $data = Cache::instance('redis')->get('foo');
+ *
+ * // Retrieve cache entry from redis group and return 'bar' if miss
+ * $data = Cache::instance('redis')->get('foo', 'bar');
+ *
+ * @param string id of cache to entry
+ * @param string default value to return if cache miss
+ * @return mixed
+ * @throws Kohana_Cache_Exception
+ */
+ public function get($id, $default = NULL)
+ {
+ // Get the value from Redis
+ $value = $this->_redis->get($this->_sanitize_id($id));
+
+ // If the value wasn't found, normalise it. Otherwise, unpack it.
+ if ( is_null( $value ) ) {
+ $value = $default;
+ }
+ else {
+ $value = unserialize( $value );
+ }
+
+ // Return the value
+ return $value;
+ }
+
+ /**
+ * Set a value to cache with id and lifetime
+ *
+ * $data = 'bar';
+ *
+ * // Set 'bar' to 'foo' in redis group for 10 minutes
+ * if (Cache::instance('redis')->set('foo', $data, 600))
+ * {
+ * // Cache was set successfully
+ * return
+ * }
+ *
+ * @param string id of cache entry
+ * @param mixed data to set to cache
+ * @param integer lifetime in seconds, default __3600__
+ * @return boolean
+ */
+ public function set($id, $data, $lifetime = 3600)
+ {
+ // Set the data to redis
+ return 'OK' === $this->_redis->setex( $this->_sanitize_id( $id ), $lifetime, serialize( $data ) );
+ }
+
+ /**
+ * Delete a cache entry based on id
+ *
+ * // Delete the 'foo' cache entry immediately
+ * Cache::instance('redis')->delete('foo');
+ *
+ * // Delete the 'bar' cache entry after 30 seconds
+ * Cache::instance('redis')->delete('bar', 30);
+ *
+ * @param string id of entry to delete
+ * @param integer timeout of entry, if zero item is deleted immediately, otherwise the item will delete after the specified value in seconds
+ * @return boolean
+ */
+ public function delete($id, $timeout = 0)
+ {
+ if( $timeout > 0 ) {
+ return 1 === $this->_redis->expire( $this->_sanitize_id( $id ), $timeout );
+ }
+ else {
+ return 0 != $this->_redis->del( $this->_sanitize_id( $id ) );
+ }
+ }
+
+ /**
+ * Delete all cache entries.
+ *
+ * Beware of using this method when
+ * using shared memory cache systems, as it will wipe every
+ * entry within the system for all clients.
+ *
+ * // Delete all cache entries in the default group
+ * Cache::instance('redis')->delete_all();
+ *
+ * @return boolean
+ */
+ public function delete_all()
+ {
+ // TODO: Un-loop this. DEL can handle multiple keys.
+ foreach( $this->_redis->keys( self::$KEY_PREFIX . '*' ) as $key ) {
+ $this->_redis->del( $key );
+ }
+ return true;
+ }
+
+ /**
+ * Replaces troublesome characters with underscores.
+ *
+ * For Redis cache we take the extra step of pre-pending an identifier to make
+ * Cache_Redis::delete_all safer for mixed use redis servers.
+ *
+ * // Sanitize a cache id
+ * $id = $this->_sanitize_id($id);
+ *
+ * @param string id of cache to sanitize
+ * @return string
+ */
+ protected function _sanitize_id($id)
+ {
+ // Change slashes and spaces to underscores
+ return self::$KEY_PREFIX . parent::_sanitize_id( $id );
+ }
+
+ }
@@ -0,0 +1,14 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+ return array(
+ 'redis' => array(
+ 'driver' => 'redis',
+ 'servers' => array(
+ array(
+ 'host' => 'localhost',
+ 'port' => 6379,
+ ),
+ ),
+ ),
+ );
+
Oops, something went wrong.

0 comments on commit a625f51

Please sign in to comment.