2015-01-19 00:03:30 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-01-19 00:03:30 +08:00
|
|
|
|
#include <vector>
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
|
|
|
|
#include "redis_command.hpp"
|
2015-01-19 00:03:30 +08:00
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class redis_client;
|
|
|
|
|
class redis_result;
|
|
|
|
|
|
2015-03-27 17:05:12 +08:00
|
|
|
|
class ACL_CPP_API redis_transaction : virtual public redis_command
|
2015-01-19 00:03:30 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-29 19:27:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* see redis_command::redis_command()
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
redis_transaction(void);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* see redis_command::redis_command(redis_client*)
|
|
|
|
|
*/
|
2015-03-27 17:05:12 +08:00
|
|
|
|
redis_transaction(redis_client* conn);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2016-05-22 09:10:34 +08:00
|
|
|
|
* see redis_command::redis_command(redis_client_cluster*, size_t)
|
2015-03-29 19:27:41 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
redis_transaction(redis_client_cluster* cluster, size_t max_conns = 0);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
2016-01-17 13:35:12 +08:00
|
|
|
|
virtual ~redis_transaction(void);
|
2015-01-19 00:03:30 +08:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-01-29 00:38:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>֮ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ) key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* watch the given keys to determine execution of the MULTI/EXEC
|
|
|
|
|
* block, before EXEC some of the given keys were changed outer,
|
|
|
|
|
* the transaction will break
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param keys {const std::vector<string>&} key <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the given keys collection
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD> key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD>᷵<EFBFBD>سɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if success of this operation
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool watch(const std::vector<string>& keys);
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ȡ<EFBFBD><EFBFBD> WATCH <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* forget about all watched keys
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if success of this operation
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
bool unwatch(void);
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᰴ<EFBFBD><EFBFBD><EFBFBD>Ⱥ<EFBFBD>˳<EFBFBD>Ž<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>У<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> EXEC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(atomic)<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* mark the start of a transaction block
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if success of this operation
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
bool multi(void);
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>ijЩ) key <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WATCH <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD>£<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ) key <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô EXEC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ)
|
|
|
|
|
* key û<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>в<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(abort)<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD>ִ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> get_size()/get_child() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* execute all commands issued after MULTI
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if success of this operation
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
bool exec(void);
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> WATCH <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>ijЩ)
|
|
|
|
|
* key<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ôȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UNWATCH
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* discard all commands issued after MULTI
|
|
|
|
|
* @return {bool}
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
bool discard(void);
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* <EFBFBD><EFBFBD> multi <EFBFBD><EFBFBD> exec ֮<EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD>ε<EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* run one command between MULTI and EXEC
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param cmd {const char*} redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the command
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param argv {const char* []} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the args array associate with the command
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param lens [const size_t []} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the length array of the args array
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param argc {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the length of the array for args
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if successful
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2015-02-02 00:13:26 +08:00
|
|
|
|
bool run_cmd(const char* cmd, const char* argv[],
|
2015-01-19 00:03:30 +08:00
|
|
|
|
const size_t lens[], size_t argc);
|
|
|
|
|
|
2015-02-02 00:13:26 +08:00
|
|
|
|
/**
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* <EFBFBD><EFBFBD> multi <EFBFBD><EFBFBD> exec ֮<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* run one command between MULTI and exec, this function can be
|
|
|
|
|
* called more than once
|
2015-02-02 00:13:26 +08:00
|
|
|
|
* @param cmd {const char*} redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the redis command
|
2015-02-02 00:13:26 +08:00
|
|
|
|
* @param args {const std::vector<string>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the args array for the command
|
2015-02-02 00:13:26 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if successful
|
2015-02-02 00:13:26 +08:00
|
|
|
|
*/
|
|
|
|
|
bool run_cmd(const char* cmd, const std::vector<string>& args);
|
|
|
|
|
|
2015-01-29 00:38:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ڳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> exec <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* get the result array's length after EXEC
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
size_t get_size(void) const;
|
2015-01-29 00:38:29 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD>Ķ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* get the result of the given subscript
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param i {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* the given subscript
|
2015-01-29 00:38:29 +08:00
|
|
|
|
* @param cmd {string*} <EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD>Ӧ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* if not NULL, it will store the command of the given subscript
|
|
|
|
|
* @return {const redis_result*} ִ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> i Խ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL
|
|
|
|
|
* return the result of one command, NULL if i was out of bounds
|
2015-01-29 00:38:29 +08:00
|
|
|
|
*/
|
2015-01-20 00:10:17 +08:00
|
|
|
|
const redis_result* get_child(size_t i, string* cmd) const;
|
2015-01-19 00:03:30 +08:00
|
|
|
|
|
2015-02-02 00:13:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-04-12 21:37:17 +08:00
|
|
|
|
* get all the commands issued between MULTI and EXEC
|
2015-02-02 00:13:26 +08:00
|
|
|
|
* @return {const std::vector<string>&}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
const std::vector<string>& get_commands(void) const
|
2015-02-02 00:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
return cmds_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 00:03:30 +08:00
|
|
|
|
private:
|
|
|
|
|
std::vector<string> cmds_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|