mirror of
https://github.com/KingDuckZ/incredis
synced 2024-12-27 21:35:42 +00:00
Accept lua scripts in a string_view rather than in a string.
This commit is contained in:
parent
0aee978661
commit
7b1931bca0
4 changed files with 10 additions and 9 deletions
|
@ -50,7 +50,7 @@ namespace redis {
|
|||
boost::string_view connection_error ( void ) const;
|
||||
|
||||
Batch make_batch ( void );
|
||||
Script make_script ( const std::string& parScript );
|
||||
Script make_script ( const boost::string_view& parScript );
|
||||
|
||||
template <typename... Args>
|
||||
Reply run ( const char* parCommand, Args&&... parArgs );
|
||||
|
|
|
@ -38,13 +38,13 @@ namespace redis {
|
|||
public:
|
||||
explicit ScriptManager ( Command* parCommand );
|
||||
|
||||
boost::string_view submit_lua_script ( const std::string& parScript );
|
||||
boost::string_view submit_lua_script ( const boost::string_view& parScript );
|
||||
void update_command_ptr (Command* parNewPtr);
|
||||
|
||||
private:
|
||||
using Sha1Array = std::array<char, 40>;
|
||||
|
||||
boost::string_view add_lua_script_ifn ( const std::string& parScript );
|
||||
boost::string_view add_lua_script_ifn ( const boost::string_view& parScript );
|
||||
|
||||
Command* m_command;
|
||||
#if defined(MAKE_SHA1_WITH_CRYPTOPP)
|
||||
|
@ -54,7 +54,7 @@ namespace redis {
|
|||
#endif
|
||||
};
|
||||
|
||||
inline boost::string_view ScriptManager::submit_lua_script (const std::string& parScript) {
|
||||
inline boost::string_view ScriptManager::submit_lua_script (const boost::string_view& parScript) {
|
||||
return add_lua_script_ifn(parScript);
|
||||
}
|
||||
} //namespace redis
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace redis {
|
|||
return Batch(&m_local_data->async_connection, m_local_data->thread_context);
|
||||
}
|
||||
|
||||
Script Command::make_script (const std::string &parScript) {
|
||||
Script Command::make_script (const boost::string_view &parScript) {
|
||||
auto sha1 = m_local_data->lua_scripts.submit_lua_script(parScript);
|
||||
return Script(sha1, m_local_data->lua_scripts);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace redis {
|
|||
}
|
||||
|
||||
#if defined(MAKE_SHA1_WITH_CRYPTOPP)
|
||||
boost::string_view ScriptManager::add_lua_script_ifn (const std::string& parScript) {
|
||||
boost::string_view ScriptManager::add_lua_script_ifn (const boost::string_view& parScript) {
|
||||
assert(m_command->is_connected());
|
||||
|
||||
if (parScript.empty())
|
||||
|
@ -88,10 +88,11 @@ namespace redis {
|
|||
return boost::string_view(it_inserted->data(), it_inserted->size());
|
||||
}
|
||||
#else
|
||||
boost::string_view ScriptManager::add_lua_script_ifn (const std::string& parScript) {
|
||||
boost::string_view ScriptManager::add_lua_script_ifn (const boost::string_view& parScript) {
|
||||
assert(m_command->is_connected());
|
||||
|
||||
auto it_found = m_known_scripts.find(parScript);
|
||||
std::string script_cpy = std::string(parScript);
|
||||
auto it_found = m_known_scripts.find(script_cpy);
|
||||
const bool was_present = (m_known_scripts.end() != it_found);
|
||||
if (was_present) {
|
||||
return boost::string_view(it_found->second.data(), it_found->second.size());
|
||||
|
@ -103,7 +104,7 @@ namespace redis {
|
|||
const auto sha1_str = get_string(reply);
|
||||
Sha1Array sha1_array;
|
||||
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));
|
||||
auto it_inserted = m_known_scripts.insert(it_found, std::make_pair(std::move(script_cpy), sha1_array));
|
||||
|
||||
return boost::string_view(it_inserted->second.data(), it_inserted->second.size());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue