blob: 730c5abd507e80bd9ae0c3b4cc40a8e165f65d7c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
module brpaste.storage;
import vibe.vibe;
class RedisStorage {
private RedisDatabase client;
this(URL url = URL("redis://127.0.0.1")) {
client = connectRedisDB(url);
}
void isDown() {
enforceHTTP(healthy, HTTPStatus.serviceUnavailable, "Redis is down.");
}
bool healthy() {
try {
client.client.ping;
} catch (Exception e) {
return false;
}
return true;
}
auto get(in string key) {
isDown;
enforceHTTP(client.exists(key), HTTPStatus.notFound, key ~ " not found.");
return client.get(key);
}
void put(in string key, in string data) {
isDown;
client.set(key, data);
}
void putCollision(in string key, in string data) {
isDown;
enforceHTTP(! client.exists(key), HTTPStatus.unprocessableEntity, key ~ " already exists.");
put(key, data);
}
}
|