Coder Social home page Coder Social logo

cakephp-redis-session's Introduction

Redis Session Store for CakePHP

This class can be used in CakePHP and saves session data into Redis, an open source key-value store.

Installation

  1. Place the redis_session.php into [yourapp]/config/.

  2. Open [yourapp]/config/core.php and find 'Session.save'.

  3. Change the value of the Configure call so that it looks like this:

    Configure::write('Session.save', 'redis_session');

That's it.

Usage

Redis on localhost

If you have a default Redis installation running on localhost you don't need to change anything. It will connect and take over.

To confirm that it does indeed write to Redis you can use redis-cli monitor and refresh your browser. You should see some GET and SETEX calls.

Redis on a foreign host

If you run on a different host you have to add two config settings in your core.php to setup the connection.

Configure::write('RedisSession.hostname', 'some.host.name');
Configure::write('RedisSession.port', 1337);

About

I've ran the core component tests with this store enabled (CakePHP 1.3.10).

The class comes with iRedis, a very lightweight Redis Library by Dan Horrigan. The library is embedded inside the source file, wrapped in a class_exists() condition. If you want to use your own version make sure to include it early or just delete the iRedis block. I leave that up to you. I wanted to keep this store small.

Garbage collection is handled by Redis. I use SETEX (expire) when writing to the store. The key will delete itself when the session expires. You can verify the remaining time with TTL [key].

I have no complex key-namespacing going on. The key however is prefixed with the session name ('Session.cookie' value) followed by the session_id()

The cookie.path is hardcoded to '/'

Enjoy!

cakephp-redis-session's People

Contributors

m3nt0r avatar

Watchers

 avatar  avatar  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.