Merge pull request #782 from mthogan/master

Added get_data_expires function to both Perl and Lua to retrieve Data…
This commit is contained in:
Chris Miles 2018-10-20 21:10:30 -05:00 committed by GitHub
commit 13f9c9fdb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 0 deletions

View File

@ -76,6 +76,31 @@ std::string DataBucket::GetData(std::string bucket_key) {
return std::string(row[0]);
}
/**
* Retrieves data expires time via bucket_name as key
* @param bucket_key
* @return
*/
std::string DataBucket::GetDataExpires(std::string bucket_key) {
std::string query = StringFormat(
"SELECT `expires` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1",
bucket_key.c_str(),
(long long) std::time(nullptr)
);
auto results = database.QueryDatabase(query);
if (!results.Success()) {
return std::string();
}
if (results.RowCount() != 1)
return std::string();
auto row = results.begin();
return std::string(row[0]);
}
/**
* Checks for bucket existence by bucket_name key
* @param bucket_key

View File

@ -14,6 +14,7 @@ public:
static void SetData(std::string bucket_key, std::string bucket_value, std::string expires_time = "");
static bool DeleteData(std::string bucket_key);
static std::string GetData(std::string bucket_key);
static std::string GetDataExpires(std::string bucket_key);
private:
static uint64 DoesBucketExist(std::string bucket_key);
static uint32 ParseStringTimeToInt(std::string time_string);

View File

@ -3596,6 +3596,21 @@ XS(XS__get_data) {
XSRETURN(1);
}
XS(XS__get_data_expires);
XS(XS__get_data_expires) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::get_data_expires(string bucket_key)");
dXSTARG;
std::string key = (std::string) SvPV_nolen(ST(0));
sv_setpv(TARG, DataBucket::GetDataExpires(key).c_str());
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
XS(XS__set_data);
XS(XS__set_data) {
dXSARGS;

View File

@ -822,6 +822,10 @@ std::string lua_get_data(std::string bucket_key) {
return DataBucket::GetData(bucket_key);
}
std::string lua_get_data_expires(std::string bucket_key) {
return DataBucket::GetDataExpires(bucket_key);
}
void lua_set_data(std::string bucket_key, std::string bucket_value) {
DataBucket::SetData(bucket_key, bucket_value);
}