-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update StorageInterface and Redis Implementation (#96)
* Update StorageInterface and redis implementation * Use unique_ptr
- Loading branch information
1 parent
0f1cfc7
commit 89af52f
Showing
5 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
#include "redis.h" | ||
|
||
using namespace sw::redis; | ||
redisCli::redisCli(const std::string &redis_ip, int redis_port) { | ||
connection_options.host = redis_ip; | ||
connection_options.port = redis_port; | ||
|
||
redisCli::redisCli() { | ||
} | ||
|
||
void redisCli::reconnect() { | ||
this->redisConn = sw::redis::Redis("tcp://127.0.0.1:6379"); | ||
redisConn = std::make_unique<Redis>(connection_options); | ||
} | ||
|
||
std::string redisCli::get(const std::string &key) { | ||
return this->redisConn.get(key).value_or(""); | ||
} | ||
|
||
sw::redis::Pipeline redisCli::pipe() { | ||
return this->redisConn.pipeline(); | ||
return redisConn->get(key).value_or(""); | ||
} | ||
|
||
void redisCli::put(const std::string &key, const std::string &value) { | ||
this->redisConn.set(key, value); | ||
redisConn->set(key, value); | ||
} | ||
|
||
void redisCli::put_batch(const std::vector<std::pair<std::string, std::string>> &operations) { | ||
auto pipe = redisConn->pipeline(); | ||
for (auto &op : operations) { | ||
pipe.set(op.first, op.second); | ||
} | ||
pipe.exec(); | ||
} |