1
0
Fork 0
mirror of https://github.com/KingDuckZ/incredis synced 2025-08-11 13:09:48 +00:00

Replace string_ref with string_view.

This commit is contained in:
King_DuckZ 2017-06-06 21:06:22 +01:00
parent 2c324ae647
commit ff802e975a
17 changed files with 103 additions and 104 deletions

View file

@ -199,7 +199,7 @@ namespace redis {
return connected;
}
boost::string_ref AsyncConnection::connection_error() const {
boost::string_view AsyncConnection::connection_error() const {
return m_local_data->connect_err_msg;
}

View file

@ -21,7 +21,7 @@
#include <memory>
#include <string>
#include <cstdint>
#include <boost/utility/string_ref.hpp>
#include <boost/utility/string_view.hpp>
struct redisAsyncContext;
struct ev_loop;
@ -44,7 +44,7 @@ namespace redis {
void wait_for_disconnect ( void );
bool is_connected ( void ) const;
boost::string_ref connection_error ( void ) const;
boost::string_view connection_error ( void ) const;
void wakeup_event_thread ( void );
std::mutex& event_mutex ( void );
redisAsyncContext* connection ( void );

View file

@ -77,7 +77,7 @@ namespace redis {
return m_local_data->async_connection.is_connected();
}
boost::string_ref Command::connection_error() const {
boost::string_view Command::connection_error() const {
return m_local_data->async_connection.connection_error();
}

View file

@ -81,45 +81,45 @@ namespace redis {
return m_command.make_batch();
}
auto IncRedis::scan (boost::string_ref parPattern) -> scan_range {
auto IncRedis::scan (boost::string_view parPattern) -> scan_range {
return scan_range(scan_iterator(&m_command, false, parPattern), scan_iterator(&m_command, true));
}
auto IncRedis::hscan (boost::string_ref parKey, boost::string_ref parPattern) -> hscan_range {
auto IncRedis::hscan (boost::string_view parKey, boost::string_view parPattern) -> hscan_range {
return hscan_range(hscan_iterator(&m_command, parKey, false, parPattern), hscan_iterator(&m_command, parKey, true));
}
auto IncRedis::sscan (boost::string_ref parKey, boost::string_ref parPattern) -> sscan_range {
auto IncRedis::sscan (boost::string_view parKey, boost::string_view parPattern) -> sscan_range {
return sscan_range(sscan_iterator(&m_command, parKey, false, parPattern), sscan_iterator(&m_command, parKey, true));
}
auto IncRedis::zscan (boost::string_ref parKey, boost::string_ref parPattern) -> zscan_range {
auto IncRedis::zscan (boost::string_view parKey, boost::string_view parPattern) -> zscan_range {
return zscan_range(zscan_iterator(&m_command, parKey, false, parPattern), zscan_iterator(&m_command, parKey, true));
}
auto IncRedis::hget (boost::string_ref parKey, boost::string_ref parField) -> opt_string {
auto IncRedis::hget (boost::string_view parKey, boost::string_view parField) -> opt_string {
return optional_string(m_command.run("HGET", parKey, parField));
}
int IncRedis::hincrby (boost::string_ref parKey, boost::string_ref parField, int parInc) {
int IncRedis::hincrby (boost::string_view parKey, boost::string_view parField, int parInc) {
const auto inc = dhandy::lexical_cast<std::string>(parInc);
auto reply = m_command.run("HINCRBY", parKey, parField, inc);
return get_integer(reply);
}
auto IncRedis::srandmember (boost::string_ref parKey, int parCount) -> opt_string_list {
auto IncRedis::srandmember (boost::string_view parKey, int parCount) -> opt_string_list {
return optional_string_list(m_command.run("SRANDMEMBER", parKey, dhandy::lexical_cast<std::string>(parCount)));
}
auto IncRedis::srandmember (boost::string_ref parKey) -> opt_string {
auto IncRedis::srandmember (boost::string_view parKey) -> opt_string {
return optional_string(m_command.run("SRANDMEMBER", parKey));
}
auto IncRedis::smembers (boost::string_ref parKey) -> opt_string_list {
auto IncRedis::smembers (boost::string_view parKey) -> opt_string_list {
return optional_string_list(m_command.run("SMEMBERS", parKey));
}
auto IncRedis::zrangebyscore (boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) -> opt_string_list {
auto IncRedis::zrangebyscore (boost::string_view parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) -> opt_string_list {
auto batch = make_batch();
batch.zrangebyscore(parKey, parMin, parMinIncl, parMax, parMaxIncl, parWithScores);
assert(batch.replies().size() == 1);
@ -141,7 +141,7 @@ namespace redis {
return ret;
}
bool IncRedis::expire (boost::string_ref parKey, RedisInt parTTL) {
bool IncRedis::expire (boost::string_view parKey, RedisInt parTTL) {
const auto ret = redis::get<RedisInt>(m_command.run("EXPIRE", parKey, dhandy::lexical_cast<std::string>(parTTL)));
return (ret == 1 ? true : false);
}
@ -150,11 +150,11 @@ namespace redis {
return optional_string_list(parReply);
}
auto IncRedis::get (boost::string_ref parKey) -> opt_string {
auto IncRedis::get (boost::string_view parKey) -> opt_string {
return optional_string(m_command.run("GET", parKey));
}
bool IncRedis::set (boost::string_ref parKey, boost::string_ref parField) {
bool IncRedis::set (boost::string_view parKey, boost::string_view parField) {
auto batch = make_batch();
batch.set(parKey, parField, IncRedisBatch::ADD_None);
assert(batch.replies().size() == 1);
@ -162,7 +162,7 @@ namespace redis {
return ret.is_ok();
}
RedisInt IncRedis::incr (boost::string_ref parKey) {
RedisInt IncRedis::incr (boost::string_view parKey) {
const auto ret = redis::get<RedisInt>(m_command.run("INCR", parKey));
return ret;
}

View file

@ -49,32 +49,32 @@ namespace redis {
return *this;
}
IncRedisBatch& IncRedisBatch::client_setname (boost::string_ref parName) {
IncRedisBatch& IncRedisBatch::client_setname (boost::string_view parName) {
m_batch.run("CLIENT", "SETNAME", parName);
return *this;
}
IncRedisBatch& IncRedisBatch::hget (boost::string_ref parKey, boost::string_ref parField) {
IncRedisBatch& IncRedisBatch::hget (boost::string_view parKey, boost::string_view parField) {
m_batch.run("HGET", parKey, parField);
return *this;
}
IncRedisBatch& IncRedisBatch::hincrby (boost::string_ref parKey, boost::string_ref parField, int parInc) {
IncRedisBatch& IncRedisBatch::hincrby (boost::string_view parKey, boost::string_view parField, int parInc) {
m_batch.run("HINCRBY", parKey, parField, dhandy::lexical_cast<std::string>(parInc));
return *this;
}
IncRedisBatch& IncRedisBatch::srandmember (boost::string_ref parKey, int parCount) {
IncRedisBatch& IncRedisBatch::srandmember (boost::string_view parKey, int parCount) {
m_batch.run("SRANDMEMBER", parKey, dhandy::lexical_cast<std::string>(parCount));
return *this;
}
IncRedisBatch& IncRedisBatch::srandmember (boost::string_ref parKey) {
IncRedisBatch& IncRedisBatch::srandmember (boost::string_view parKey) {
m_batch.run("SRANDMEMBER", parKey);
return *this;
}
IncRedisBatch& IncRedisBatch::set (boost::string_ref parKey, boost::string_ref parField, ADD_Mode parMode) {
IncRedisBatch& IncRedisBatch::set (boost::string_view parKey, boost::string_view parField, ADD_Mode parMode) {
switch(parMode) {
case ADD_None:
m_batch.run("SET", parKey, parField);
@ -89,7 +89,7 @@ namespace redis {
return *this;
}
IncRedisBatch& IncRedisBatch::zrangebyscore (boost::string_ref parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) {
IncRedisBatch& IncRedisBatch::zrangebyscore (boost::string_view parKey, double parMin, bool parMinIncl, double parMax, bool parMaxIncl, bool parWithScores) {
auto lower_bound = make_boundary(parMin, not parMinIncl);
auto upper_bound = make_boundary(parMax, not parMaxIncl);

View file

@ -25,11 +25,11 @@
namespace redis {
namespace implem {
ScanIteratorBaseClass::ScanIteratorBaseClass (Command* parCommand) :
ScanIteratorBaseClass(parCommand, boost::string_ref())
ScanIteratorBaseClass(parCommand, boost::string_view())
{
}
ScanIteratorBaseClass::ScanIteratorBaseClass (Command* parCommand, boost::string_ref parMatchPattern) :
ScanIteratorBaseClass::ScanIteratorBaseClass (Command* parCommand, boost::string_view parMatchPattern) :
m_command(parCommand),
m_match_pattern(parMatchPattern)
{
@ -50,7 +50,7 @@ namespace redis {
return m_command->run(parCommand, scan_context, "MATCH", m_match_pattern, "COUNT", count_hint);
}
Reply ScanIteratorBaseClass::run (const char* parCommand, const boost::string_ref& parParameter, RedisInt parScanContext, std::size_t parCount) {
Reply ScanIteratorBaseClass::run (const char* parCommand, const boost::string_view& parParameter, RedisInt parScanContext, std::size_t parCount) {
const auto scan_context = dhandy::lexical_cast<std::string>(parScanContext);
const auto count_hint = dhandy::lexical_cast<std::string>(parCount);
if (m_match_pattern.empty())

View file

@ -24,7 +24,7 @@ namespace redis {
{
}
Script::Script (boost::string_ref parSha1, ScriptManager& parManager) :
Script::Script (boost::string_view parSha1, ScriptManager& parManager) :
m_sha1(parSha1),
m_manager(&parManager)
{

View file

@ -45,11 +45,11 @@ namespace redis {
}
#if defined(MAKE_SHA1_WITH_CRYPTOPP)
boost::string_ref ScriptManager::add_lua_script_ifn (const std::string& parScript) {
boost::string_view ScriptManager::add_lua_script_ifn (const std::string& parScript) {
assert(m_command->is_connected());
if (parScript.empty())
return boost::string_ref();
return boost::string_view();
using dhandy::lexical_cast;
@ -75,7 +75,7 @@ namespace redis {
auto it_found = m_known_hashes.find(sha1_array);
const bool was_present = (m_known_hashes.end() != it_found);
if (was_present) {
return boost::string_ref(it_found->data(), it_found->size());
return boost::string_view(it_found->data(), it_found->size());
}
auto reply = m_command->run("SCRIPT", "LOAD", parScript);
@ -85,16 +85,16 @@ namespace redis {
const auto it_inserted = m_known_hashes.insert(it_found, sha1_array);
(void)reply;
return boost::string_ref(it_inserted->data(), it_inserted->size());
return boost::string_view(it_inserted->data(), it_inserted->size());
}
#else
boost::string_ref ScriptManager::add_lua_script_ifn (const std::string& parScript) {
boost::string_view ScriptManager::add_lua_script_ifn (const std::string& parScript) {
assert(m_command->is_connected());
auto it_found = m_known_scripts.find(parScript);
const bool was_present = (m_known_scripts.end() != it_found);
if (was_present) {
return boost::string_ref(it_found->second.data(), it_found->second.size());
return boost::string_view(it_found->second.data(), it_found->second.size());
}
auto reply = m_command->run("SCRIPT", "LOAD", parScript);
@ -105,7 +105,7 @@ namespace redis {
std::copy(sha1_str.begin(), sha1_str.end(), sha1_array.begin());
auto it_inserted = m_known_scripts.insert(it_found, std::make_pair(parScript, sha1_array));
return boost::string_ref(it_inserted->second.data(), it_inserted->second.size());
return boost::string_view(it_inserted->second.data(), it_inserted->second.size());
}
#endif
} //namespace redis