Class: Stat::Count::Client::ThriftStatCountClient
- Inherits:
-
Object
- Object
- Stat::Count::Client::ThriftStatCountClient
- Includes:
- ConfigLoader, Thrift
- Defined in:
- lib/stat-count-client/thrift_client.rb
Constant Summary collapse
- @@logger =
LoggerFactory.getLogger("StatCountThriftClient")
Instance Method Summary collapse
- #decr(name, id, count = 1, date = nil) ⇒ Object
- #decrByCount(count) ⇒ Object
- #decrByCountWithDate(dateCount) ⇒ Object
- #delByDateQuery(dateQuery) ⇒ Object
- #delByQuery(query) ⇒ Object
- #destroy ⇒ Object
- #get(name, id, limit = 1) ⇒ Object
- #getByDateQuery(dateQuery) ⇒ Object
- #getByIds(name, ids, limit = 1) ⇒ Object
- #getByNames(name, id, limit = 1) ⇒ Object
- #getByQuery(query) ⇒ Object
- #incr(name, id, count = 1, date = nil) ⇒ Object
- #incrByCount(count) ⇒ Object
- #incrByCountWithDate(date_count) ⇒ Object
-
#initialize(config = nil) ⇒ ThriftStatCountClient
constructor
A new instance of ThriftStatCountClient.
- #reset(name, id, limit = 1) ⇒ Object
- #set(name, id, value, date = nil) ⇒ Object
- #setByCount(count) ⇒ Object
- #setByCountWithDate(dateCount) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ ThriftStatCountClient
Returns a new instance of ThriftStatCountClient.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stat-count-client/thrift_client.rb', line 18 def initialize(config=nil) config ||= ConfigLoader::CONFIG['thrift'] || {} config['servers'] ||='localhost:9090' config['client_class'] ||= 'Stat::Count::Thrift::RemoteSimpleCountCollecter::Client' config['application_exception_classes'] ||= 'Stat::Count::Thrift::DataCollectionException' config['timeout'] ||= 10 if !config['size'].nil? && config['size'] > 1 config['pool_timeout'] = 12 end init(config) end |
Instance Method Details
#decr(name, id, count = 1, date = nil) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/stat-count-client/thrift_client.rb', line 51 def decr(name, id, count=1, date=nil) if(date.nil?) @client.decrBy(name, id.to_s, count) else @client.decrByWithDate(name, id.to_s, count, date) end end |
#decrByCount(count) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/stat-count-client/thrift_client.rb', line 59 def decrByCount(count) thrift_count = to_count(count) count_result_hash = @client.decrByCount(thrift_count).countResults count_result_hash = {}.tap{|hash|hash['countResults'] = count_result_hash} Stat::Count::Data::CountResult.new(count_result_hash) end |
#decrByCountWithDate(dateCount) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/stat-count-client/thrift_client.rb', line 66 def decrByCountWithDate(dateCount) thrift_date_count = to_date_count(dateCount) count_result_hash = @client.decrByCountWithDate(thrift_date_count).countResults count_result_hash = {}.tap{|hash|hash['countResults'] = count_result_hash} Stat::Count::Data::CountResult.new(count_result_hash) end |
#delByDateQuery(dateQuery) ⇒ Object
126 127 128 129 |
# File 'lib/stat-count-client/thrift_client.rb', line 126 def delByDateQuery(dateQuery) thrift_query = to_query(query) @client.delByDateQuery(thrift_query) end |
#delByQuery(query) ⇒ Object
121 122 123 124 |
# File 'lib/stat-count-client/thrift_client.rb', line 121 def delByQuery(query) thrift_query = to_query(query) @client.delByQuery(thrift_query) end |
#destroy ⇒ Object
131 132 133 |
# File 'lib/stat-count-client/thrift_client.rb', line 131 def destroy @client.destroy end |
#get(name, id, limit = 1) ⇒ Object
95 96 97 |
# File 'lib/stat-count-client/thrift_client.rb', line 95 def get(name, id, limit=1) @client.getByLimit(name, id.to_s, limit) end |
#getByDateQuery(dateQuery) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/stat-count-client/thrift_client.rb', line 114 def getByDateQuery(dateQuery) thrift_query = to_date_query(query) count_result_hash = @client.getByDateQuery(thrift_query).countResults count_result_hash = {}.tap{|hash|hash['countResults'] = count_result_hash} Stat::Count::Data::CountResult.new(count_result_hash) end |
#getByIds(name, ids, limit = 1) ⇒ Object
103 104 105 |
# File 'lib/stat-count-client/thrift_client.rb', line 103 def getByIds(name, ids, limit=1) @client.getByIdsAndLimit(name, ids.map {|id| id.to_s}, limit) end |
#getByNames(name, id, limit = 1) ⇒ Object
99 100 101 |
# File 'lib/stat-count-client/thrift_client.rb', line 99 def getByNames(name, id, limit=1) @client.getByNamesAndLimit(name, id.to_s, limit) end |
#getByQuery(query) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/stat-count-client/thrift_client.rb', line 107 def getByQuery(query) thrift_query = to_query(query) count_result_hash = @client.getByQuery(thrift_query).countResults count_result_hash = {}.tap{|hash|hash['countResults'] = count_result_hash} Stat::Count::Data::CountResult.new(count_result_hash) end |
#incr(name, id, count = 1, date = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/stat-count-client/thrift_client.rb', line 43 def incr(name, id, count=1, date=nil) if(date.nil?) count_result_hash = @client.incrBy(name,id.to_s, count) else @client.incrByWithDate(name, id.to_s, count, date) end end |
#incrByCount(count) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/stat-count-client/thrift_client.rb', line 36 def incrByCount(count) thrift_count = to_count(count) count_result_hash = @client.incrByCount(thrift_count).countResults count_result_hash = {}.tap{|hash|hash['countResults'] = count_result_hash} Stat::Count::Data::CountResult.new(count_result_hash) end |
#incrByCountWithDate(date_count) ⇒ Object
31 32 33 34 |
# File 'lib/stat-count-client/thrift_client.rb', line 31 def incrByCountWithDate(date_count) thrift_date_count = to_date_count(date_count) @client.incrByCountWithDate(thrift_date_count) end |
#reset(name, id, limit = 1) ⇒ Object
91 92 93 |
# File 'lib/stat-count-client/thrift_client.rb', line 91 def reset(name, id, limit=1) @client.resetByLimit(name, id.to_s, limit) end |
#set(name, id, value, date = nil) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/stat-count-client/thrift_client.rb', line 83 def set(name,id, value, date=nil) if(date.nil?) @client.setValue(name, id.to_s, value) else @client.setWithDate(name,id.to_s, value,date) end end |
#setByCount(count) ⇒ Object
78 79 80 81 |
# File 'lib/stat-count-client/thrift_client.rb', line 78 def setByCount(count) thrift_count = to_count(count) @client.setByCount(thrift_count) end |
#setByCountWithDate(dateCount) ⇒ Object
73 74 75 76 |
# File 'lib/stat-count-client/thrift_client.rb', line 73 def setByCountWithDate(dateCount) thrift_date_count = to_date_count(dateCount) @client.setByCountWithDate(thrift_date_count) end |