mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
Introduce command class
This commit is contained in:
47
Redis/include/Poco/Redis/Command.h
Normal file
47
Redis/include/Poco/Redis/Command.h
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Command.h
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: Redis
|
||||
// Package: Redis
|
||||
// Module: Command
|
||||
//
|
||||
// Definition of the Command class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#ifndef Redis_Command_INCLUDED
|
||||
#define Redis_Command_INCLUDED
|
||||
|
||||
#include "Poco/Redis/Redis.h"
|
||||
#include "Poco/Redis/Array.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Redis {
|
||||
|
||||
class Redis_API Command : public Array
|
||||
/// Helper class for creating commands. This class contains
|
||||
/// factory methods for common used Redis commands.
|
||||
{
|
||||
public:
|
||||
Command(const std::string& command);
|
||||
/// Constructor
|
||||
|
||||
Command(const Command& copy);
|
||||
/// Copy constructor
|
||||
|
||||
virtual ~Command();
|
||||
/// Destructor
|
||||
|
||||
static Command set(const std::string& key, const std::string& value, bool overwrite = true, const Poco::Timespan& expireTime = 0, bool create = true);
|
||||
/// Returns a SET command to set the key with a value
|
||||
};
|
||||
|
||||
}} // namespace Poco::Redis
|
||||
|
||||
#endif // Redis_Command_INCLUDED
|
||||
54
Redis/src/Command.cpp
Normal file
54
Redis/src/Command.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Command.cpp
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: Redis
|
||||
// Package: Redis
|
||||
// Module: Command
|
||||
//
|
||||
// Implementation of the Command class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#include "Poco/Redis/Command.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Redis {
|
||||
|
||||
Command::Command(const std::string& command) : Array()
|
||||
{
|
||||
add(command);
|
||||
}
|
||||
|
||||
Command::Command(const Command& copy) : Array(copy)
|
||||
{
|
||||
}
|
||||
|
||||
Command::~Command()
|
||||
{
|
||||
}
|
||||
|
||||
Command Command::set(const std::string& key, const std::string& value, bool overwrite, const Poco::Timespan& expireTime, bool create)
|
||||
{
|
||||
Command cmd("SET");
|
||||
cmd.add(key);
|
||||
cmd.add(value);
|
||||
if ( ! overwrite ) cmd.add("NX");
|
||||
if ( ! create ) cmd.add("XX");
|
||||
|
||||
if ( expireTime.totalMicroseconds() > 0 )
|
||||
{
|
||||
cmd.add("PX");
|
||||
cmd.add(expireTime.totalMilliseconds());
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
}} // Poco::Redis
|
||||
Reference in New Issue
Block a user