Design a thread-safe Redis inspired data structure that is accessed over the network and satisfies the following methods:
(Exact methods can vary to fit the conventions of the chosen programming language.)
The system must remain correct and performant under concurrent operations from multiple threads.
- set(key: string, value: string): void
- Sets a key to a string value.
- Concurrent calls to set on different keys should proceed independently, but updates to the same key
must be handled safely.
- listPush(key: string, value: string): void
- If there is no value at
key, this should create a new "list" containing the elementvalueand store it atkey. - If there is an existing "list" located at
key, push a string value onto the head of the "list".
- If there is no value at
- get(key: string): Entry
- Gets the value of any type out of the data structure.
- Return an
Entryobject that abstracts over the possible return types. - Should return null if no value is found for the key.
- Should allow multiple threads to read concurrently.
- expire(key: string, time: integer): bool
- Expires a key (value returns as null) after time in seconds has elapsed from when expire was called on the key.
- Subsequent calls to expire should override previous calls.
- Calling with a negative time should cancel any previous expire call.
- Mutating a key assignment in any way should cancel any previous expire calls on that key.
- Keys should expire asynchronously so that reads and writes continue without delay.
"a": [1, 2]
setKey("a",[1])
setKey("a", 2)
Comments (2)


