jodosha/redis-store — Issue #122: Weird Redis key input
Author: larzconwell
Created: 2012-03-08 20:03:48+00:00
State: open

I'm not sure if this is what is supposed to be put into the Redis key. I just wanna make sure I have it working correctly. The sessions are working and the keys are expiring unless I keep refreshing then they continue longer.

I have Rails 3.2.2 and Redis 2.4.8

#### Here's the Gems I have installed.
'''Ruby
# Gemfile
gem "redis"
gem "redis-rails", "~> 3.2.1.rc"
'''

#### Here's my sessions controller in case it's needed
'''Ruby
# app/controllers/sessions_controller.rb
def create
user = User.where(email: params[:email]).first
# 'authenticate' comes from the 'has_secure_password' method in the User model
if user && user.authenticate(params[:password])
session[:user_id] = user.id # Set a session from the id
Time.zone = user.time_zone # Set the users time zone on sign in
redirect_to user, notice: "You have been signed in as #{user}."
else
flash.now[:error] = "There was an error, please check your email/password and try again."
render 'new'
end
end
'''

#### Here is the session config I have set up for redis-store
'''Ruby
# config/environments.rb
Hangout::Application.config.session_store :redis_store, servers: "redis://localhost:6379", expire_in: 7200
'''

#### The Redis server logs
'''Logs
# Redis server logs
[16304] 08 Mar 14:44:50 * The server is now ready to accept connections on port 6379
[16304] 08 Mar 14:44:50 - 0 clients connected (0 slaves), 717496 bytes in use

# Redis-cli connected
[16304] 08 Mar 14:44:53 - Accepted 127.0.0.1:40680
[16304] 08 Mar 14:44:55 - 1 clients connected (0 slaves), 726024 bytes in use
[16304] 08 Mar 14:45:00 - 1 clients connected (0 slaves), 726088 bytes in use
[16304] 08 Mar 14:45:05 - 1 clients connected (0 slaves), 726088 bytes in use
[16304] 08 Mar 14:45:10 - 1 clients connected (0 slaves), 726088 bytes in use

# Rails server connected
[16304] 08 Mar 14:45:13 - Accepted 127.0.0.1:40687
[16304] 08 Mar 14:45:15 - DB 0: 1 keys (1 volatile) in 4 slots HT.
[16304] 08 Mar 14:45:15 - 2 clients connected (0 slaves), 735224 bytes in use
[16304] 08 Mar 14:45:20 - DB 0: 1 keys (1 volatile) in 4 slots HT.
[16304] 08 Mar 14:45:20 - 2 clients connected (0 slaves), 735224 bytes in use
[16304] 08 Mar 14:45:25 - DB 0: 1 keys (1 volatile) in 4 slots HT.
[16304] 08 Mar 14:45:25 - 2 clients connected (0 slaves), 735224 bytes in use
[16304] 08 Mar 14:45:30 - DB 0: 1 keys (1 volatile) in 4 slots HT.
'''

#### Keys that were created during the Rails session
'''Logs
# Redis-cli

# Before Rails connects
redis 127.0.0.1:6379> keys *
(empty list or set)

# After Rails connects
redis 127.0.0.1:6379> keys *
1) "5e5733bf51ea86eb32db3e96b4e65b9b"

# After Rails connects and before user session is created
redis 127.0.0.1:6379> get 5e5733bf51ea86eb32db3e96b4e65b9b
"\x04\b{\x06I\"\x10_csrf_token\x06:\x06EFI\"1/76X9vHqMYUQ5siYXVktw9c/jZ1Hy3CKlJPQ36C/W4E=\x06;\x00F"

# After user session is created from Rails
redis 127.0.0.1:6379> get 5e5733bf51ea86eb32db3e96b4e65b9b
"\x04\b{\bI\"\x10_csrf_token\x06:\x06EFI\"1/76X9vHqMYUQ5siYXVktw9c/jZ1Hy3CKlJPQ36C/W4E=\x06;\x00FI\"\x0cuser_id\x06;\x00Fi\x06I\"\nflash\x06;\x00Fo:%ActionDispatch::Flash::FlashHash\t:\n@usedo:\bSet\x06:\n@hash{\x06:\x0bnoticeT:\x0c@closedF:\r@flashes{\x06;\nI\"0You have been signed in as Admin_test User.\x06;\x00F:\t@now0"

# After user session is destroyed from Rails
redis 127.0.0.1:6379> get 5e5733bf51ea86eb32db3e96b4e65b9b
"\x04\b{\aI\"\x10_csrf_token\x06:\x06EFI\"1/76X9vHqMYUQ5siYXVktw9c/jZ1Hy3CKlJPQ36C/W4E=\x06;\x00FI\"\nflash\x06;\x00Fo:%ActionDispatch::Flash::FlashHash\t:\n@usedo:\bSet\x06:\n@hash{\x06:\x0bnoticeT:\x0c@closedF:\r@flashes{\x06;\nI\")You have been signed out, thank you.\x06;\x00F:\t@now0"
redis 127.0.0.1:6379>
'''