Skip to content

Instantly share code, notes, and snippets.

@scott1028
Last active July 12, 2021 23:51
Show Gist options
  • Save scott1028/6898a5999cb720c5e5337e0b6a6427c2 to your computer and use it in GitHub Desktop.
Save scott1028/6898a5999cb720c5e5337e0b6a6427c2 to your computer and use it in GitHub Desktop.
TEST-02: time based versioning KeyValue store
/* TEST-02
A simple version key value store mechanism
NOTE: here is the example about I will use this store instance.
const store = new Store();
store.put('scott', 1); // => 10000
store.put('scott', 2); // => 10010
store.put('scott', 3); // => 10020
store.get('robert', 9999); // => null
store.get('scott', 9999); // => null
store.get('scott', 10000); // => 1
store.get('scott', 10011); // => 2
store.get('scott', 10019); // => 2
store.get('scott', 10020); // => 3
*/
// NOTE: you can use lodash or any other `util libray` you want
const lodash = require('lodash');
class Store {
put(key, value) {
// TODO: return timestamp of this value
}
get(key, timestamp) {
// TODO: return the latest value "<=" the timestamp
}
// Feel free to extend any method your need
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment