jodosha/redis-store — pull request #207 by loe (2013-08-01 21:20:44+00:00)
Title: Fix session id locking and implement skip support

This fixes a couple of issues.

1.) When used inside Rails (with redis-actionpack) the generate_sid method is actually overwritten by the included Compatibility module, so it isn't even used, this uses a different method name to generate a session id to ensure we always call what we expect.

2.) The generate_sid implementation was subject to a race condition, between the GET and SET other worker processes could have also done the same and they would both assume incorrectly that they had a unique session id. Using SETNX we can atomically claim the session id, or generate a new one and try locking that.

3.) If env['rack.session.options'][:skip] = true then we should not even bother with talking to Redis, the session is going to be thrown away, instead we should just return an arbitrary session id and an empty hash. The :skip option was added in Rack 1.4+, which goes along with Rails 3.2+.