@@ -21,20 +21,20 @@ struct RedisDbKey {
21
21
22
22
// Parses a string as a RedisDB key. If the key is not in our expected format we
23
23
// return a status failure.
24
- absl::StatusOr<RedisDbKey> GetRedisDbKey (const std::string& key) {
25
- constexpr char kDelimiter [] = " : " ;
26
- std::vector<std::string> split = absl::StrSplit (key, kDelimiter );
24
+ absl::StatusOr<RedisDbKey> GetRedisDbKey (const std::string& key,
25
+ const std::string& delimiter) {
26
+ std::vector<std::string> split = absl::StrSplit (key, delimiter );
27
27
28
28
// If there is no ':' character then the key is incorrectly formatted for our
29
29
// use case.
30
30
if (split.size () == 1 ) {
31
31
return absl::Status (
32
32
absl::StatusCode::kInvalidArgument ,
33
- absl::StrCat (" Key does not have a '" , kDelimiter , " ': " , key));
33
+ absl::StrCat (" Key does not have a '" , delimiter , " ': " , key));
34
34
}
35
35
return RedisDbKey{
36
36
.table_name = split[0 ],
37
- .key = absl::StrJoin (split.begin () + 1 , split.end (), kDelimiter )};
37
+ .key = absl::StrJoin (split.begin () + 1 , split.end (), delimiter )};
38
38
}
39
39
40
40
} // namespace
@@ -80,7 +80,7 @@ std::unordered_map<std::string, std::string> FakeDBConnector::hgetall(
80
80
81
81
// If we get an invalid key we assume the entry does not exist and return
82
82
// an empty map..
83
- auto redis_key = GetRedisDbKey (key);
83
+ auto redis_key = GetRedisDbKey (key, delimiter_ );
84
84
if (!redis_key.ok ()) {
85
85
VLOG (1 ) << " WARNING: " << redis_key.status ();
86
86
return empty_map;
@@ -108,7 +108,7 @@ bool FakeDBConnector::exists(const std::string& key) {
108
108
109
109
// If we get an invalid key we assume the entry does not exist and return
110
110
// false.
111
- auto redis_key = GetRedisDbKey (key);
111
+ auto redis_key = GetRedisDbKey (key, delimiter_ );
112
112
if (!redis_key.ok ()) {
113
113
VLOG (1 ) << " WARNING: " << redis_key.status ();
114
114
return false ;
@@ -132,7 +132,7 @@ int64_t FakeDBConnector::del(const std::string& key) {
132
132
VLOG (1 ) << " Deleteing key: " << key;
133
133
134
134
// If we get an invalid key we assume the entry does not exist and return 0.
135
- auto redis_key = GetRedisDbKey (key);
135
+ auto redis_key = GetRedisDbKey (key, delimiter_ );
136
136
if (!redis_key.ok ()) {
137
137
VLOG (1 ) << " WARNING: " << redis_key.status ();
138
138
return 0 ;
@@ -182,7 +182,7 @@ void FakeDBConnector::hmset(const std::string& key,
182
182
183
183
// If we get an invalid key then someone is formatting something wrong
184
184
// internally. So just fail outright.
185
- auto redis_key = GetRedisDbKey (key);
185
+ auto redis_key = GetRedisDbKey (key, delimiter_ );
186
186
if (!redis_key.ok ()) {
187
187
LOG (FATAL) << " Cannot fake inserting an invalid key: "
188
188
<< redis_key.status ();
0 commit comments