Core dataWeb and mobile

Session Management

Store sessions with automatic expiry, and find or revoke them by user, role or device without building an index.

lookup to find a user's sessions
1
secondary indexes
0
expiry, tags included
Auto
Step 1 of 5
Sign in on three devices

Each device gets its own session with a 30 minute expiry.

Example sessionplaying
# Sign in on three devices
hotkv> SET session:9f2c "{\"user\":42}" EX 1800
OK

An animated walkthrough with real HotKV commands and example replies. Click any step to jump to it.

The problem

Sessions are small, hot and short-lived, which suits an in-memory store. The hard part comes later, when support needs to sign a user out everywhere, or security needs to end every session for a role or a device. A plain key-value store can only look up a session by its id.

How HotKV handles it

HotKV stores each session as a key with an expiry and lets you tag it with the user, role or device it belongs to. Tags are part of the engine and go away with the key, so you can list or revoke all matching sessions with one lookup instead of maintaining a parallel set of keys.

Step by step

What happens, command by command

  1. 01

    Sign in on three devices

    Each device gets its own session with a 30 minute expiry.

    SET session:9f2c "{\"user\":42}" EX 1800
  2. 02

    Tag each session

    User, role and device are attached right after the session is created.

    TAG.SET session:9f2c user:42 role:admin device:ios
  3. 03

    Stay signed in while active

    Every request refreshes the expiry, which gives a sliding timeout.

    EXPIRE session:9f2c 1800
  4. 04

    Find every session of user 42

    A stolen laptop is reported. One lookup returns all of the user's sessions.

    TAG.MEMBERS user:42
  5. 05

    Sign out everywhere

    Delete the keys that came back. Their tags go with them, and every device is signed out.

    DEL session:9f2c session:71aa session:0c8e
Where it fits

Real-world scenarios

Banking and fintech apps

Security teams end all sessions of a compromised account, or of every device on an outdated app version, in one action.

SaaS products

When an admin's role is removed, every session tagged with that role is revoked at once.

Streaming services

Count and limit concurrent sessions per account from the TAG.MEMBERS reply for the user tag.

Built in

What you get

Automatic expiry

Sessions disappear on their own when the TTL runs out, and their tags go with them.

EXEXPIRE

Lookup without an index

Find sessions by any tag, or by several tags at once.

TAG.MEMBERSTAG.INTER

Check tags quickly

TAG.COUNT and TAG.EXISTS tell you what a key carries.

TAG.COUNTTAG.EXISTS

Fast under login storms

Session reads and writes run on parallel threads.

Common questions

How do I log a user out of only one device?

Use TAG.INTER with the user tag and the device tag, then delete the keys it returns.

What happens to a tag when its session expires?

A key's tags go when the key does, including on expiry. Tags are not part of snapshots, so re-apply them if the server restarts from a snapshot.

Can I limit concurrent sessions per account?

Yes. TAG.MEMBERS on the user tag lists the sessions, so you can count them and refuse or end the oldest one at sign-in.

Related use cases

Try it on your own workload

HotKV speaks the Redis protocol, so you can point an existing client at it and run these same commands.