HW 2 – Key-value data stores. Redis

(5 points)

  1. Design the data structures based on the analytical tasks (see HW 1) that are intended to be solved with Redis.
    • The structures must be designed so that the target queries are feasible.
    • Use native Redis data types (HASH/SET/ZSET/STREAM; BITMAP/HLL if needed). Avoid storing everything as plain strings/JSON.
    • Do not use Lua or Redis modules.
  2. Insert the data into Redis from the dataset produced in HW 0 (CSV/JSON).
    • Select and import only the subset/fields strictly required to execute your Redis tasks (do not import unnecessary data).
    • Document the selection/transformation rules (filters, projections, denormalization) so the same subset can be reproduced.
    • The import script must be idempotent: repeated runs must not create duplicates.
    • Do not pre-aggregate outside Redis: each raw event should map to one (or a small fixed bundle of) native Redis command(s).
  3. Implement and run the queries (see HW 1).
  4. Prepare a report and include:
    • the text from HW 0 and HW 1 (edited if necessary) related to Redis;
    • the structure-creation commands with explanations of why these structures were chosen;
    • the data import code;
    • the exact Redis commands used to load the minimal subset and the exact Redis commands used to answer the tasks;
    • the queries used to solve the analytical tasks. For each task, provide:
      • the task number (as in the HW 1);
      • the verbal description of the task;
      • the command(s) with a short explanation;
      • a screenshot of the query result.

Note. If some analytical tasks turn out to be infeasible under Redis’ data model or performance constraints, replace them with other meaningful tasks and propagate the corresponding changes to the earlier work (HW 0/HW 1).

Submit to the BRUTE system:

  • HW2.docx file — the report (human-readable, formatted).
    • Includes: short HW0/HW1 recap (only parts relevant to Redis), minimal fields table, Redis key schema and TTL rules, event→command mapping, exact query commands with screenshots.
  • hw2_insert.py — Python script to insert the big subset into Redis (idempotent; uses the necessary subset of the HW 0 dataset as the only source).
  • hw2_queries.py — Python script to run the same queries as in your Redis example, but via `redis-py` on the big subset.
  • base_small.txt — a minimal, readable set of native insert commands that demonstrates your mapping (one raw event → one or a fixed bundle of commands).
  • Q_small.txt — small Redis query script (hand-crafted).
    • Exact native query commands for your HW1 tasks (e.g., `ZUNIONSTORE`, `ZINTERSTORE`, `ZREVRANGE WITHSCORES`, `ZRANGE WITHSCORES`, optional `HGET` lookups).
    • Must match the logic shown in HW2.docx.
  • data/ — folder with the subset of HW0 used for Redis (only necessary fields).
  • Include comments in all files with scripts and commands.

Submit hw2_insert.py, hw2_queries.py, base_small.txt, Q_small.txt, and the subset archive to the NoSQL server nosql.felk.cvut.cz.

  • Execute the following shell command to evaluate the whole REDIS script
    • redis-cli -h 127.0.0.1 -p $PORT -a $PASSWORD FLUSHDB
    • cat base_small.txt | redis-cli -h 127.0.0.1 -p $PORT -a $PASSWORD
    • cat Q_small.txt | redis-cli -h 127.0.0.1 -p $PORT -a $PASSWORD
    • $PASSWORD is an initial password (see the first email)
  • If you cannot connect to your Redis instance remotely, create an ssh tunnel first:
    • ssh -L $PORT:127.0.0.1:$PORT $USERNAME@nosql.felk.cvut.cz
    • Then from your local device you can connect to Redis on localhost (127.0.0.1) using your port and password, e.g.:
    • redis-cli -h 127.0.0.1 -p $PORT -a $PASSWORD
  • Your script will be tested on the server. Before submitting it, run the code and check if it works.

Redis command dictionary tailored to HW2

Example of base_small.txt and Q_small.txt with explanation

courses/be4m36ds2/homework/hw2.txt · Last modified: 2025/10/29 17:04 by prokoyul