标签云

微信群

扫码加入我们

WeChat QR Code

I have installed django-redis-session via pip and add this settings to the settings.py file:SESSION_ENGINE = 'redis_sessions.session'When I go to the terminal and type:$ redis-cli monitorI can see there are changes when I log in and log out (using python-social-auth).My question is: How can I get the session (from redis) based on the user?If I call is_authenticated() User's function it works, but my DB's (PostgreSQL) Session table has 0 rows.Fianlly, is there any way to write the session key and data manually? I will need to use a complex PK for session based in two fields stored in redis.


I don't understand your question. Why would you expect any rows in Posgres? You've specifically set the session backend to redis.

2019年04月22日13分20秒

DanielRoseman Yes, I don't expect rows in Postgres I was just saying that session has been succesfully stored in redis.

2019年04月22日13分20秒

From request.session I can access to user, thanks.

2019年04月22日13分20秒

If you need the logged in user, then use request.user - you shouldn't have to go via the session.

2019年04月23日13分20秒

Thanks again, one more question: Do you know how can I write the session manually? I need to use a complex PK for sessions and I'd like to store this in redis.

2019年04月22日13分20秒

I'm not sure what you mean by 'write the session manually'. You can store values in the session with request.session['key'] = 'value'. If you are trying to change the session key, then I'm not immediately sure how you would do that, and I don't think it's a good idea anyway. Session keys should not be guessable.

1970年01月01日00分03秒

I will take a look. Thanks again!

2019年04月22日13分20秒