RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
core/banker/migration/redis_old_types.h
00001 /* redis_old_types.h
00002    Wolfgang Sourdeau, 7 January 2013
00003    Copyright (c) 2013 Datacratic.  All rights reserved.
00004  */
00005 
00006 #ifndef REDIS_OLD_TYPES_H
00007 #define REDIS_OLD_TYPES_H
00008 
00009 namespace Redis {
00010     class AsyncConnection;
00011 }
00012 
00013 namespace RTBKIT {
00014 
00015 extern const std::string CampaignsPrefix;
00016 
00017 struct Campaign;
00018 struct Strategy;
00019 
00020 typedef std::unordered_map<std::string, Campaign> Campaigns;
00021 typedef std::unordered_map<std::string, Strategy> Strategies;
00022 
00023 struct Campaign {
00024     Campaign(const std::string & key = "",
00025              long long available = -1,
00026              long long transferred = -1);
00027 
00028     void load(Redis::AsyncConnection & redis);
00029     void save(Redis::AsyncConnection & redis) const;
00030 
00031     bool validateAll(int acceptedDelta) const;
00032 
00033     std::string key_;
00034 
00035     long long int available_;
00036     long long int transferred_;
00037 
00038     std::vector<Strategy> strategies;
00039 };
00040 
00041 struct Strategy {
00042     Strategy(const std::string & key,
00043              const std::string & campaignKey,
00044              long long available = -1,
00045              long long spent = -1,
00046              long long transferred = -1);
00047 
00048     void load(Redis::AsyncConnection & redis, int acceptedDelta);
00049     void assignToParent(Campaigns & campaigns) const;
00050 
00051     void save(Redis::AsyncConnection & redis) const;
00052 
00053     std::string key_;
00054     std::string campaignKey_;
00055     bool valid_;
00056 
00057     long long available_;
00058     long long spent_;
00059     long long transferred_;
00060 };
00061 
00062 } // namespace RTBKIT
00063 
00064 #endif /* REDIS_OLD_TYPES_H */
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator