Problem statement
Session keys named without a shared scheme cannot be found one user at a time, and listing the whole keyspace in one call stops the server for everyone else. A namespaced key scheme and a cursor walk let a worker find one user's keys in small batches.
Requirements
The connected Jedis client and size() are already provided. Your task has six methods in src/main/java/com/staffcoder/redis/Keyspace.java. A colon-separated namespace lets the cursor-based SCAN command filter one user's keys on the server, a small batch at a time.
- key(userId, token) returns session:tok:<userId>:<token>.
- scanMatch(pattern, count) returns every key that matches pattern exactly once, even when the server returns the same key in more than one batch.
- scanMatch(pattern, count) walks the cursor until it returns to 0, sends pattern as MATCH and count as COUNT on every call, and never uses KEYS.
- rename(from, to) moves a value and its lifetime to the target in one command, replacing an existing target.
- renameIfFree(from, to) moves a value in one command only when the target is free, and returns whether it moved.
- expire(key, seconds) gives a key a lifetime and returns whether the key existed.
- dropBig(String... keys) deletes the keys with the non-blocking delete command and returns how many keys were removed.
Sample Usage
key("u1", "abc")
session:tok:u1:abcscanMatch("session:tok:u1:*", 10) with keys session:tok:u1:a, session:tok:u1:b and session:tok:u2:c stored (keys come back in any order)
[session:tok:u1:b, session:tok:u1:a]renameIfFree("session:tok:u1:a", "session:tok:u1:b") when the target exists
falseexpire("session:tok:u1:missing", 60)
falseNote: Refer to the README.md file for detailed implementation requirements.
Session keys named without a shared scheme cannot be found one user at a time, and listing the whole keyspace in one call stops the server for everyone else. A namespaced key scheme and a cursor walk let a worker find one user's keys in small batches.
Requirements
The connected Redis client and size() are already provided. Your task has six methods in src/keyspace.js. A colon-separated namespace lets the cursor-based SCAN command filter one user's keys on the server, a small batch at a time.
- key(userId, token) returns session:tok:<userId>:<token>.
- scanMatch(pattern, count) resolves to every key that matches pattern exactly once, even when the server returns the same key in more than one batch.
- scanMatch(pattern, count) walks the cursor until it returns to 0, sends pattern as MATCH and count as COUNT on every call, and never uses KEYS.
- rename(from, to) moves a value and its lifetime to the target in one command, replacing an existing target.
- renameIfFree(from, to) moves a value in one command only when the target is free, and resolves to whether it moved.
- expire(key, seconds) gives a key a lifetime and resolves to whether the key existed.
- dropBig(...keys) deletes the keys with the non-blocking delete command and resolves to how many keys were removed.
Sample Usage
key("u1", "abc")
session:tok:u1:abcawait scanMatch("session:tok:u1:*", 10) with keys session:tok:u1:a, session:tok:u1:b and session:tok:u2:c stored (keys come back in any order)
[ 'session:tok:u1:b', 'session:tok:u1:a' ]await renameIfFree("session:tok:u1:a", "session:tok:u1:b") when the target exists
falseawait expire("session:tok:u1:missing", 60)
falseNote: Refer to the README.md file for detailed implementation requirements.
Session keys named without a shared scheme cannot be found one user at a time, and listing the whole keyspace in one call stops the server for everyone else. A namespaced key scheme and a cursor walk let a worker find one user's keys in small batches.
Requirements
The connected Redis client and size() are already provided. Your task has six methods in src/keyspace.py. A colon-separated namespace lets the cursor-based SCAN command filter one user's keys on the server, a small batch at a time.
- key(user_id, token) returns session:tok:<user_id>:<token>.
- scan_match(pattern, count) returns every key that matches pattern exactly once, as str, even when the server returns the same key in more than one batch.
- scan_match(pattern, count) walks the cursor until it returns to 0, sends pattern as MATCH and count as COUNT on every call, and never uses KEYS.
- rename(source, target) moves a value and its lifetime to the target in one command, replacing an existing target.
- rename_if_free(source, target) moves a value in one command only when the target is free, and returns whether it moved.
- expire(key, seconds) gives a key a lifetime and returns whether the key existed.
- drop_big(*keys) deletes the keys with the non-blocking delete command and returns how many keys were removed.
Sample Usage
key("u1", "abc")
session:tok:u1:abcscan_match("session:tok:u1:*", 10) with keys session:tok:u1:a, session:tok:u1:b and session:tok:u2:c stored (keys come back in any order)
['session:tok:u1:b', 'session:tok:u1:a']rename_if_free("session:tok:u1:a", "session:tok:u1:b") when the target exists
Falseexpire("session:tok:u1:missing", 60)
FalseNote: Refer to the README.md file for detailed implementation requirements.
