StaffCoder
Redis
RedisJava 25Node.js 24Python 3.13
1 module · 4 challengesSign up
Module 1 · Strings & Key Basics

First Keys

easy40%2 of 5 solved

Problem statement

Sessions stored in a dictionary belong to only one web server and disappear when it restarts. Store the sessions in Redis so every server sees the same values.

Requirements

The connected Redis client, the session key prefix and key_for(token) are already provided. Your task has six methods in src/token_store.py. The client returns raw bytes, while the public methods return either text or bytes as described below.

  • put(token, value) and get(token) store and return the exact text value under the key produced by key_for(token).
  • get(token) returns None when the token has no stored value.
  • Binary values passed to put(token, value) are stored without modification, and get_bytes(token) returns the exact value as bytes.
  • has(token) returns a bool that reports both present and absent tokens.
  • type_of(token) returns string for a stored session and none for an absent token.
  • remove(*tokens) deletes every named token and returns the number of keys that existed.
  • A later call to put(token, value) replaces the value already stored for that token.
Sample Usage

get("demo") after storing the text value active

active

has("missing")

False

Note: Refer to the README.md file for detailed implementation requirements.

More in Strings & Key Basics

See the module
Conditional Sets & CountersDecide a claim in one command instead of two. Write a key only when it is absent, only when it already exists, or while returning the value it replaced — each with a single SET — and keep per-user counters with INCR, INCRBY, DECR and INCRBYFLOAT, letting Redis's own error surface when a counter holds something that is not a number.50%1 of 2 solvedeasyKey Naming & ScanningGive a sprawling keyspace one namespaced scheme, then iterate it without stopping the server: drive SCAN's cursor to completion with MATCH and COUNT rather than calling KEYS, discarding the duplicates a cursor can return. Rename keys with and without overwriting, set expiries, and remove large keys with the non-blocking delete.100%1 of 1 solvedeasySession Token StoreBuild the session store the whole service signs people in with: issue a token exactly once with an expiry, refresh it while it is in use, revoke it on sign-out, count logins per user, and audit a user's open sessions on a live keyspace — using a cursor, never KEYS, and freeing keys without making other clients wait.100%1 of 1 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.