Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTL not set on session keys #48

Closed
mfinelli opened this issue Sep 15, 2019 · 3 comments
Closed

TTL not set on session keys #48

mfinelli opened this issue Sep 15, 2019 · 3 comments

Comments

@mfinelli
Copy link

Hi, I'm not sure that I'm testing the right thing, and perhaps I'm not understanding the correct behavior, but I don't think that this gem is setting an expiration on the keys that it stores in redis.

If I setup a simple app with the following settings:

$redis = ConnectionPool.new(size: 25, timeout: 3) do
    Redis.new(url: 'redis://localhost)
end

use Rack::Session::Redis, pool: $redis, key: 'session',
      expires_in: 3600 # 1 hour

And then issue a request:

curl -sI http://localhost:9292 | grep Set-Cookie
Set-Cookie: session=d80dcc50e63c454dc467d3cc703e84f514b790f5ef6c20bbbb7f18be2c22cce5; path=/; HttpOnly

And then ask redis what the ttl is for the associated key:

127.0.0.1:6379> ttl d80dcc50e63c454dc467d3cc703e84f514b790f5ef6c20bbbb7f18be2c22cce5
(integer) -1

There is no TTL set on the key, but I think that there should be, no? Or am I misunderstanding how the expires_in option works?

Cheers

@tubbo
Copy link
Contributor

tubbo commented Sep 15, 2019 via email

@mfinelli
Copy link
Author

That does set the expires on the cookie that gets sent, but still no TTL on the redis key.

curl -sI http://localhost:9292 | grep Set-Cookie
Set-Cookie: session=68e212a79b5aa718580be9aecddc3bf90b91b54673e35d65800b875b270f4e80; path=/; expires=Sun, 15 Sep 2019 21:44:04 -0000; HttpOnly
127.0.0.1:6379> ttl 68e212a79b5aa718580be9aecddc3bf90b91b54673e35d65800b875b270f4e80
(integer) -1

@mfinelli
Copy link
Author

Apologies, I figured out my issue. I was passing in a connection pool initialized with a raw redis object instead of a redis-store. Switching to the redis-store started setting the TTL correctly.

All that being said, the readme for this project could use a couple of updates, if I have time I will send another PR.

Sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants