LoginSignup
0
0

More than 5 years have passed since last update.

RailsでRedisに保存されたセッションを確認する

Posted at

業務の中でセッションIDを受け取ってRedisに保存されている値を読み出す際に、調査に少し時間がかかったのでメモ。

実装

# 接続するRedisの設定。REDIS_URLは環境変数で指定している
redis = Redis.new(url: "redis://#{ENV.fetch('REDIS_URL', 'localhost')}:6379/0")

# Marshalをつけないとハッシュとして取り扱えない
Marshal.load(redis.get "123")
# => { "id"=> "aaaaaa", "name"=> "bbbb" }

補足

MarshalはRailsのオブジェクトと文字列の変換を行うモジュール。
Redisに保存されているのがMarshalで変換された文字列だということに気づくまでに時間がかかった。

参考

Railsのセッション管理には何が最適か

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0