B
B
blabs2018-03-09 13:54:12
PHP
blabs, 2018-03-09 13:54:12

How to organize user sessions with Redis?

Introductory
- Only one user can sit under one account
- The session has a lifetime = 48h
- Tokens are needed in order to process API requests
Option: Put the token and user identifier (id) in Redis, and also set the TTL, after which the record is removed. On every request (GET/POST/PUT/DELETE) we update the token.
Questions

  1. To what extent is the option of organizing user sessions applicable above?
  2. Is there a tool that will allow you to search for an entry in Redis by value, not by key?
  3. Are there alternative solutions provided that the tokens need to be read through Redis? For example, store the last token in PostgreSQL and update it there as well

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Tsvetkov, 2018-03-09
@yellow79

1. A very acceptable option.
2. There is no such tool. Select all keys by mask, then compare values. That is, all your sessions should look something like this sessions:session_id , make a selection of keys by the sessions:* mask and search for the desired value by enumeration.

On every request (GET/POST/PUT/DELETE) we update the token.
you need to update TTL for writing

P
Puma Thailand, 2018-03-09
@opium

If there are few sessions, then postgres will also go, it’s just that postgres will lie on its back for a thousand connectors, and the radish will not sneeze further

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question