drocks ~master
RocksServer db client
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Drocks is a Dlang driver for RocksDB server RocksServer
Usage
Create
auto db = Client(host, port);
or
auto db = Client.createDefault();
Get
By single key
string value = db.get(key);
string value = db[key];
By multi keys
auto values = db.get(key1, key2, key3);
auto values = db.get([key1, key2, key3]);
auto values = db.get(keysRange);
auto values = db[key1, key2, key3];
auto values = db[[key1, key2, key3]];
auto values = db[keysRange];
Set / Replace
By single key
db.set(key, value);
db.set(Pair(key, value));
db[key] = value;
By multi keys
auto range = [
Pair(key1, val1),
Pair(key2, val2),
Pair(key3, val3),
];
db.set(range);
auto range = [
tuple(key1, val1),
tuple(key2, val2),
tuple(key3, val3),
];
db.set(range);
auto map = [
key1: val1,
key2: val2,
key3: val3,
];
db.set(map);
Delete keys
db.del(key);
db.del(key1, key2, key3);
db.del([key1, key2, key3]);
db.del(keysRange);
Increment value by key
db.incr(key, value);
db.incr(key);
db[key] += 7;
db[key] += -4;
db[key] -= 1;
++db[key];
--db[key];
Check if key exist
bool keyExist = db.has(key);
auto keyExist = db.has(key);
bool has = db.has(key).has;
string value = db.has(key).value;
Prefix iterator
auto range = db.getall(KeysPrefix);
Seek key and iterate
db.set([
"w:a" : "v-w:a",
"w:c" : "v-w:c",
"w:e" : "v-w:e",
"w:g" : "v-w:g",
"w:h" : "v-w:h",
"w:l" : "v-w:l",
"x:a" : "v-x:a",
"x:c" : "v-x:c",
]);
db.seekPrev("w:d")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l", "x:a", "x:c"]
db.seekPrev("w:d", "w:")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l"]
db.seekPrev("w:e")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a", "x:c"]
db.seekPrev("w:e", "w:")
retrieves range:
["w:e", "w:g", "w:h", "w:l"]
db.seekPrev("0:e")
retrieves all pairs
db.seekPrev("0:e", "w:")
retrieves empty range
db.seekPrevRange("w:d", "x:b")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekPrevRange("w:d", "x:b", "w:")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l"]
db.seekPrevRange("w:e", "x:b")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekPrevRange("w:e", "x:a")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekPrevRange("w:e", "x:b", "w:")
retrieves range:
["w:e", "w:g", "w:h", "w:l"]
db.seekNext("w:d")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l", "x:a", "x:c"]
db.seekNext("w:d", "w:")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l"]
db.seekNext("w:e")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a", "x:c"]
db.seekNext("w:e", "w:")
retrieves range:
["w:e", "w:g", "w:h", "w:l"]
db.seekNext("0:e")
retrieves all pairs
db.seekNext("0:e", "w:")
retrieves empty range
db.seekNextRange("w:d", "x:b")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekNextRange("w:d", "x:b", "w:")
retrieves range:
["w:c", "w:e", "w:g", "w:h", "w:l"]
db.seekNextRange("w:e", "x:b")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekNextRange("w:e", "x:a")
retrieves range:
["w:e", "w:g", "w:h", "w:l", "x:a"]
db.seekNextRange("w:e", "x:b", "w:")
retrieves range:
["w:e", "w:g", "w:h", "w:l"]
More details
For more details see exmaples, tests and sources
How to extend
import drocks;
struct CustomClient
{
mixin ExtendClient;
//...
}
See exmaple:
struct CustomClient
{
mixin ExtendClient;
// incriment value by key
long getIncr(string key, long value)
{
return _db.request.httpPost("get-incr", key, value).getValue().to!long;
}
long getIncr(string key)
{
return _db.request.httpPost("get-incr", key).getValue().to!long;
}
// Check if DB server is available
bool ping() //const
{
return "pong" == _db.request.httpGet("ping").raw();
}
// Seack first pair by key prefix
auto seekFirst(string prefix)
{
return _db.request.httpGet("seek-first", prefix).getPair();
}
// ...
}
try {
auto db = CustomClient.createDefault();
db.get("key1").writeln;
db.getIncr("incr1").writeln;
db.ping().writeln;
db.seekFirst("key-prefix:").writeln;
} catch (ClientException e) {
writeln(e.msg);
}
Tests
License
- Registered by Valmat
- ~master released a year ago
- valmat/drocks
- github.com/valmat/drocks
- MIT
- Authors:
- Dependencies:
- none
- Versions:
-
0.1.2 2023-Feb-20 0.1.1 2019-Jun-13 0.1.0 2019-May-31 0.0.1 2019-Jan-24 ~master 2023-Feb-20 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
19 downloads total
-
- Score:
- 0.4
- Short URL:
- drocks.dub.pm