Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/rediscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ void RedisCommand::formatHDEL(const std::string& key, const std::vector<std::str
formatArgv(static_cast<int>(args.size()), args.data(), NULL);
}

/* Format EXPIRE key field command */
void RedisCommand::formatEXPIRE(const std::string& key, const int64_t& ttl)
{
return format("EXPIRE %s %lld", key.c_str(), ttl);
}

const char *RedisCommand::c_str() const
{
return temp;
Expand Down
3 changes: 3 additions & 0 deletions common/rediscommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class RedisCommand {
/* Format HDEL key multiple fields command */
void formatHDEL(const std::string& key, const std::vector<std::string>& fields);

/* Format EXPIRE key field command */
void formatEXPIRE(const std::string& key, const int64_t& ttl);

const char *c_str() const;

size_t length() const;
Expand Down
10 changes: 9 additions & 1 deletion common/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Table::hset(const string &key, const std::string &field, const std::string
}

void Table::set(const string &key, const vector<FieldValueTuple> &values,
const string& /*op*/, const string& /*prefix*/)
const string& /*op*/, const string& /*prefix*/, const int64_t &ttl)
{
if (values.size() == 0)
return;
Expand All @@ -132,6 +132,14 @@ void Table::set(const string &key, const vector<FieldValueTuple> &values,
cmd.formatHMSET(getKeyName(key), values.begin(), values.end());

m_pipe->push(cmd, REDIS_REPLY_STATUS);

if (ttl != DEFAULT_DB_TTL)
{
// Configure the expire time for the entry that was just added
cmd.formatEXPIRE(getKeyName(key), ttl);
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  [](http://example.com/codeflow?start=0&length=6)

Please indent with 4x spaces #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated indents in last commit


m_pipe->push(cmd, REDIS_REPLY_INTEGER);
}
if (!m_buffered)
{
m_pipe->flush();
Expand Down
9 changes: 7 additions & 2 deletions common/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ class TableEntryEnumerable {
void getContent(std::vector<KeyOpFieldsValuesTuple> &tuples);
};

/* The default time to live for a DB entry is infinite */
static constexpr int64_t DEFAULT_DB_TTL = -1;

class Table : public TableBase, public TableEntryEnumerable {
public:
Table(const DBConnector *db, const std::string &tableName);
Table(RedisPipeline *pipeline, const std::string &tableName, bool buffered);
~Table() override;

/* Set an entry in the DB directly (op not in use) */
/* Set an entry in the DB directly and configure its TTL, if provided (op not in use) */
virtual void set(const std::string &key,
const std::vector<FieldValueTuple> &values,
const std::string &op = "",
const std::string &prefix = EMPTY_PREFIX);
const std::string &prefix = EMPTY_PREFIX,
const int64_t &ttl = DEFAULT_DB_TTL);

/* Delete an entry in the table */
virtual void del(const std::string &key,
const std::string &op = "",
Expand Down