mock_redis 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### 0.6.4
2
+ * Update INFO command for latest Redis 2.6 compatibility
3
+
1
4
  ### 0.6.3
2
5
  * Treat symbols as strings for keys
3
6
  * Add #reconnect method (no-op)
@@ -7,6 +7,7 @@ require 'mock_redis/string_methods'
7
7
  require 'mock_redis/zset_methods'
8
8
  require 'mock_redis/sort_method'
9
9
  require 'mock_redis/indifferent_hash'
10
+ require 'mock_redis/info_method'
10
11
 
11
12
  class MockRedis
12
13
  class Database
@@ -16,6 +17,7 @@ class MockRedis
16
17
  include StringMethods
17
18
  include ZsetMethods
18
19
  include SortMethod
20
+ include InfoMethod
19
21
 
20
22
  attr_reader :data, :expire_times
21
23
 
@@ -89,203 +91,6 @@ class MockRedis
89
91
  'OK'
90
92
  end
91
93
 
92
- def info
93
- astats = [
94
- ["2", "2699"],
95
- ["6", "1"],
96
- ["7", "1"],
97
- ["8", "17197"],
98
- ["9", "109875"],
99
- ["10", "94348"],
100
- ["11", "32580"],
101
- ["12", "52347"],
102
- ["13", "86475"],
103
- ["14", "58175"],
104
- ["15", "53408"],
105
- ["16", "876949"],
106
- ["17", "71157"],
107
- ["18", "5104"],
108
- ["19", "2705"],
109
- ["20", "2903"],
110
- ["21", "1024"],
111
- ["22", "2546"],
112
- ["23", "952"],
113
- ["24", "186080"],
114
- ["25", "611"],
115
- ["26", "40936"],
116
- ["27", "960"],
117
- ["28", "1323"],
118
- ["29", "14216"],
119
- ["30", "52412"],
120
- ["31", "21130"],
121
- ["32", "47959"],
122
- ["33", "6891"],
123
- ["34", "9712"],
124
- ["35", "3366"],
125
- ["36", "5737"],
126
- ["37", "11274"],
127
- ["38", "8057"],
128
- ["39", "2957"],
129
- ["40", "51200"],
130
- ["42", "8220"],
131
- ["43", "8278"],
132
- ["44", "6539"],
133
- ["45", "764"],
134
- ["47", "1018"],
135
- ["48", "19250"],
136
- ["49", "713"],
137
- ["51", "51"],
138
- ["53", "2"],
139
- ["55", "3922"],
140
- ["56", "153"],
141
- ["57", "614"],
142
- ["58", "1"],
143
- ["59", "1775"],
144
- ["61", "32865"],
145
- ["63", "2530"],
146
- ["64", "565"],
147
- ["65", "1322"],
148
- ["67", "1572"],
149
- ["69", "1421"],
150
- ["71", "1220"],
151
- ["72", "241"],
152
- ["73", "5432"],
153
- ["74", "1122"],
154
- ["75", "2555"],
155
- ["77", "1539"],
156
- ["78", "612"],
157
- ["79", "902"],
158
- ["81", "1678"],
159
- ["83", "51"],
160
- ["84", "612"],
161
- ["85", "706"],
162
- ["87", "410"],
163
- ["88", "5435"],
164
- ["89", "813"],
165
- ["90", "612"],
166
- ["93", "153"],
167
- ["94", "612"],
168
- ["96", "159"],
169
- ["97", "306"],
170
- ["99", "153"],
171
- ["101", "456"],
172
- ["103", "741"],
173
- ["105", "447"],
174
- ["107", "754"],
175
- ["109", "414"],
176
- ["111", "475"],
177
- ["113", "757"],
178
- ["115", "287"],
179
- ["117", "420"],
180
- ["118", "765"],
181
- ["119", "642"],
182
- ["120", "159"],
183
- ["121", "926"],
184
- ["122", "612"],
185
- ["123", "251"],
186
- ["125", "390"],
187
- ["127", "354"],
188
- ["128", "617"],
189
- ["129", "528"],
190
- ["131", "298"],
191
- ["132", "612"],
192
- ["133", "809"],
193
- ["135", "244"],
194
- ["136", "306"],
195
- ["137", "504"],
196
- ["139", "201"],
197
- ["141", "1124"],
198
- ["143", "139"],
199
- ["144", "159"],
200
- ["145", "1322"],
201
- ["147", "410"],
202
- ["149", "253"],
203
- ["151", "304"],
204
- ["153", "312"],
205
- ["155", "249"],
206
- ["157", "306"],
207
- ["159", "348"],
208
- ["161", "255"],
209
- ["163", "458"],
210
- ["165", "5"],
211
- ["167", "306"],
212
- ["168", "47"],
213
- ["169", "214"],
214
- ["171", "250"],
215
- ["173", "5"],
216
- ["177", "10"],
217
- ["179", "158"],
218
- ["181", "5"],
219
- ["183", "10"],
220
- ["185", "51"],
221
- ["187", "49"],
222
- ["191", "5"],
223
- ["192", "47"],
224
- ["193", "51"],
225
- ["197", "112"],
226
- ["199", "5"],
227
- ["201", "5"],
228
- ["203", "5"],
229
- ["209", "5"],
230
- ["213", "51"],
231
- ["217", "102"],
232
- ["225", "357"],
233
- ["229", "51"],
234
- ["233", "204"],
235
- ["237", "51"],
236
- ["239", "1"],
237
- ["247", "46"],
238
- ["255", "102"],
239
- [">=256", "6201"],
240
- ]
241
-
242
- {
243
- "allocation_stats" => astats.map {|(a,b)| "#{a}=#{b}"}.join(','),
244
- "aof_enabled" => "0",
245
- "arch_bits" => "64",
246
- "bgrewriteaof_in_progress" => "0",
247
- "bgsave_in_progress" => "0",
248
- "blocked_clients" => "0",
249
- "changes_since_last_save" => "0",
250
- "client_biggest_input_buf" => "0",
251
- "client_longest_output_list" => "0",
252
- "connected_clients" => "1",
253
- "connected_slaves" => "0",
254
- "db0" => "keys=8,expires=0",
255
- "evicted_keys" => "0",
256
- "expired_keys" => "0",
257
- "hash_max_zipmap_entries" => "512",
258
- "hash_max_zipmap_value" => "64",
259
- "keyspace_hits" => "62645",
260
- "keyspace_misses" => "29757",
261
- "last_save_time" => "1310596333",
262
- "loading" => "0",
263
- "lru_clock" => "1036434",
264
- "mem_fragmentation_ratio" => "2.04",
265
- "multiplexing_api" => "kqueue",
266
- "process_id" => "14508",
267
- "pubsub_channels" => "0",
268
- "pubsub_patterns" => "0",
269
- "redis_git_dirty" => "0",
270
- "redis_git_sha1" => "00000000",
271
- "redis_version" => "2.2.11",
272
- "role" => "master",
273
- "total_commands_processed" => "196800",
274
- "total_connections_received" => "4359",
275
- "uptime_in_days" => "0",
276
- "uptime_in_seconds" => "84215",
277
- "use_tcmalloc" => "0",
278
- "used_cpu_sys" => "5.54",
279
- "used_cpu_sys_childrens" => "0.00",
280
- "used_cpu_user" => "7.65",
281
- "used_cpu_user_childrens" => "0.02",
282
- "used_memory" => "931456",
283
- "used_memory_human" => "909.62K",
284
- "used_memory_rss" => "1904640",
285
- "vm_enabled" => "0",
286
- }
287
- end
288
-
289
94
  def keys(format = '*')
290
95
  data.keys.grep(redis_pattern_to_ruby_regex(format))
291
96
  end
@@ -0,0 +1,159 @@
1
+ class MockRedis
2
+ module InfoMethod
3
+ SERVER_INFO = {
4
+ "arch_bits" => "64",
5
+ "gcc_version" => "4.2.1",
6
+ "lru_clock" => "1036434",
7
+ "multiplexing_api" => "kqueue",
8
+ "os" => "Darwin 12.2.1 x86_64",
9
+ "process_id" => "14508",
10
+ "redis_git_dirty" => "0",
11
+ "redis_git_sha1" => "00000000",
12
+ "redis_mode" => "standalone",
13
+ "redis_version" => "2.6.10",
14
+ "run_id" => "1f3f7af2fc11eb68011eb43e154adce125c85e9a",
15
+ "tcp_port" => "6379",
16
+ "uptime_in_days" => "0",
17
+ "uptime_in_seconds" => "84215"
18
+ }
19
+
20
+ CLIENTS_INFO = {
21
+ "blocked_clients" => "0",
22
+ "client_biggest_input_buf" => "0",
23
+ "client_longest_output_list" => "0",
24
+ "connected_clients" => "1"
25
+ }
26
+
27
+ MEMORY_INFO = {
28
+ "mem_allocator" => "libc",
29
+ "mem_fragmentation_ratio" => "2.04",
30
+ "used_memory" => "931456",
31
+ "used_memory_human" => "909.62K",
32
+ "used_memory_lua" => "31744",
33
+ "used_memory_peak" => "1005424",
34
+ "used_memory_peak_human" => "981.86K",
35
+ "used_memory_rss" => "1904640"
36
+ }
37
+
38
+ PERSISTENCE_INFO = {
39
+ "aof_current_rewrite_time_sec" => "-1",
40
+ "aof_enabled" => "0",
41
+ "aof_last_bgrewrite_status" => "ok",
42
+ "aof_last_rewrite_time_sec" => "-1",
43
+ "aof_rewrite_in_progress" => "0",
44
+ "aof_rewrite_scheduled" => "0",
45
+ "loading" => "0",
46
+ "rdb_bgsave_in_progress" => "0",
47
+ "rdb_changes_since_last_save" => "0",
48
+ "rdb_current_bgsave_time_sec" => "-1",
49
+ "rdb_last_bgsave_status" => "ok",
50
+ "rdb_last_bgsave_time_sec" => "-1",
51
+ "rdb_last_save_time" => "1361423635"
52
+ }
53
+
54
+ STATS_INFO = {
55
+ "evicted_keys" => "0",
56
+ "expired_keys" => "0",
57
+ "instantaneous_ops_per_sec" => "0",
58
+ "keyspace_hits" => "62645",
59
+ "keyspace_misses" => "29757",
60
+ "latest_fork_usec" => "0",
61
+ "pubsub_channels" => "0",
62
+ "pubsub_patterns" => "0",
63
+ "rejected_connections" => "0",
64
+ "total_commands_processed" => "196800",
65
+ "total_connections_received" => "4359"
66
+ }
67
+
68
+ REPLICATION_INFO = {
69
+ "role" => "master",
70
+ "connected_slaves" => "0"
71
+ }
72
+
73
+ CPU_INFO = {
74
+ "used_cpu_sys" => "5.54",
75
+ "used_cpu_sys_childrens" => "0.00",
76
+ "used_cpu_user" => "7.65",
77
+ "used_cpu_user_childrens" => "0.02"
78
+ }
79
+
80
+ KEYSPACE_INFO = {
81
+ "db0" => "keys=8,expires=0"
82
+ }
83
+
84
+ # The Ruby Reids client returns commandstats differently when it's called as
85
+ # "INFO commandstats".
86
+ COMMAND_STATS_SOLO_INFO = {
87
+ "auth"=>{"calls"=>"572501", "usec"=>"2353163", "usec_per_call"=>"4.11"},
88
+ "client"=>{"calls"=>"1", "usec"=>"80", "usec_per_call"=>"80.00"},
89
+ "config"=>{"calls"=>"4", "usec"=>"71", "usec_per_call"=>"17.75"},
90
+ "flushall"=>{"calls"=>"2097790", "usec"=>"27473940655", "usec_per_call"=>"13096.61"},
91
+ "flushdb"=>{"calls"=>"692247", "usec"=>"2235143397", "usec_per_call"=>"3228.82"},
92
+ "get"=>{"calls"=>"185724", "usec"=>"604479", "usec_per_call"=>"3.25"},
93
+ "info"=>{"calls"=>"965566", "usec"=>"229377331", "usec_per_call"=>"237.56"},
94
+ "keys"=>{"calls"=>"16591", "usec"=>"917676", "usec_per_call"=>"55.31"},
95
+ "llen"=>{"calls"=>"39", "usec"=>"150", "usec_per_call"=>"3.85"},
96
+ "ping"=>{"calls"=>"697509", "usec"=>"3836044", "usec_per_call"=>"5.50"},
97
+ "rpush"=>{"calls"=>"2239810", "usec"=>"15013298", "usec_per_call"=>"6.70"},
98
+ "sadd"=>{"calls"=>"13950129156", "usec"=>"30126628979", "usec_per_call"=>"2.16"},
99
+ "scard"=>{"calls"=>"153929", "usec"=>"726596", "usec_per_call"=>"4.72"},
100
+ "set"=>{"calls"=>"6975081982", "usec"=>"16453671451", "usec_per_call"=>"2.36"},
101
+ "slowlog"=>{"calls"=>"136", "usec"=>"16815", "usec_per_call"=>"123.64"},
102
+ "smembers"=>{"calls"=>"58", "usec"=>"231", "usec_per_call"=>"3.98"},
103
+ "sunionstore"=>{"calls"=>"4185027", "usec"=>"11762454022", "usec_per_call"=>"2810.60"}
104
+ }
105
+
106
+ COMMAND_STATS_COMBINED_INFO = {
107
+ "cmdstat_auth"=>"calls=572506,usec=2353182,usec_per_call=4.11",
108
+ "cmdstat_client"=>"calls=1,usec=80,usec_per_call=80.00",
109
+ "cmdstat_config"=>"calls=4,usec=71,usec_per_call=17.75",
110
+ "cmdstat_flushall"=>"calls=2097790,usec=27473940655,usec_per_call=13096.61",
111
+ "cmdstat_flushdb"=>"calls=692247,usec=2235143397,usec_per_call=3228.82",
112
+ "cmdstat_get"=>"calls=185724,usec=604479,usec_per_call=3.25",
113
+ "cmdstat_info"=>"calls=965571,usec=229378327,usec_per_call=237.56",
114
+ "cmdstat_keys"=>"calls=16591,usec=917676,usec_per_call=55.31",
115
+ "cmdstat_llen"=>"calls=39,usec=150,usec_per_call=3.85",
116
+ "cmdstat_ping"=>"calls=697509,usec=3836044,usec_per_call=5.50",
117
+ "cmdstat_rpush"=>"calls=2239810,usec=15013298,usec_per_call=6.70",
118
+ "cmdstat_sadd"=>"calls=13950129156,usec=30126628979,usec_per_call=2.16",
119
+ "cmdstat_scard"=>"calls=153929,usec=726596,usec_per_call=4.72",
120
+ "cmdstat_set"=>"calls=6975081982,usec=16453671451,usec_per_call=2.36",
121
+ "cmdstat_slowlog"=>"calls=136,usec=16815,usec_per_call=123.64",
122
+ "cmdstat_smembers"=>"calls=58,usec=231,usec_per_call=3.98",
123
+ "cmdstat_sunionstore"=>"calls=4185027,usec=11762454022,usec_per_call=2810.60"
124
+ }
125
+
126
+ DEFAULT_INFO = [
127
+ SERVER_INFO,
128
+ CLIENTS_INFO,
129
+ MEMORY_INFO,
130
+ PERSISTENCE_INFO,
131
+ STATS_INFO,
132
+ REPLICATION_INFO,
133
+ CPU_INFO,
134
+ KEYSPACE_INFO
135
+ ].inject({}){|memo,info| memo.merge(info)}
136
+
137
+ ALL_INFO = [
138
+ DEFAULT_INFO,
139
+ COMMAND_STATS_COMBINED_INFO
140
+ ].inject({}){|memo,info| memo.merge(info)}
141
+
142
+ def info( section = :default )
143
+ case section
144
+ when :default ; DEFAULT_INFO
145
+ when :all ; ALL_INFO
146
+ when :server ; SERVER_INFO
147
+ when :clients ; CLIENTS_INFO
148
+ when :memory ; MEMORY_INFO
149
+ when :persistence ; PERSISTENCE_INFO
150
+ when :stats ; STATS_INFO
151
+ when :replication ; REPLICATION_INFO
152
+ when :cpu ; CPU_INFO
153
+ when :keyspace ; KEYSPACE_INFO
154
+ when :commandstats ; COMMAND_STATS_SOLO_INFO
155
+ end
156
+ end
157
+ end
158
+ end
159
+
@@ -1,3 +1,3 @@
1
1
  class MockRedis
2
- VERSION = '0.6.3'
2
+ VERSION = '0.6.4'
3
3
  end
@@ -1,13 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '#info [mock only]' do
4
- before { @info = @redises.mock.info }
4
+ let(:redis) { @redises.mock }
5
5
 
6
6
  it "responds with a config hash" do
7
- @info.should be_a(Hash)
7
+ redis.info.should be_a(Hash)
8
8
  end
9
9
 
10
- it "has some data in it" do
11
- @info.keys.length.should > 0
10
+ it "gets default set of info" do
11
+ info = redis.info
12
+ info["arch_bits"].should be_a(String)
13
+ info["connected_clients"].should be_a(String)
14
+ info["aof_rewrite_scheduled"].should be_a(String)
15
+ info["used_cpu_sys"].should be_a(String)
16
+ end
17
+
18
+ it "gets all info" do
19
+ info = redis.info(:all)
20
+ info["arch_bits"].should be_a(String)
21
+ info["connected_clients"].should be_a(String)
22
+ info["aof_rewrite_scheduled"].should be_a(String)
23
+ info["used_cpu_sys"].should be_a(String)
24
+ info["cmdstat_slowlog"].should be_a(String)
25
+ end
26
+
27
+ it "gets server info" do
28
+ redis.info(:server)["arch_bits"].should be_a(String)
29
+ end
30
+
31
+ it "gets clients info" do
32
+ redis.info(:clients)["connected_clients"].should be_a(String)
33
+ end
34
+
35
+ it "gets memory info" do
36
+ redis.info(:memory)["used_memory"].should be_a(String)
37
+ end
38
+
39
+ it "gets persistence info" do
40
+ redis.info(:persistence)["aof_rewrite_scheduled"].should be_a(String)
41
+ end
42
+
43
+ it "gets stats info" do
44
+ redis.info(:stats)["keyspace_hits"].should be_a(String)
45
+ end
46
+
47
+ it "gets replication info" do
48
+ redis.info(:replication)["role"].should be_a(String)
49
+ end
50
+
51
+ it "gets cpu info" do
52
+ redis.info(:cpu)["used_cpu_sys"].should be_a(String)
53
+ end
54
+
55
+ it "gets keyspace info" do
56
+ redis.info(:keyspace)["db0"].should be_a(String)
57
+ end
58
+
59
+ it "gets commandstats info" do
60
+ redis.info(:commandstats)["sunionstore"]["usec"].should be_a(String)
12
61
  end
13
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-03 00:00:00.000000000 Z
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -83,6 +83,7 @@ files:
83
83
  - lib/mock_redis/expire_wrapper.rb
84
84
  - lib/mock_redis/hash_methods.rb
85
85
  - lib/mock_redis/indifferent_hash.rb
86
+ - lib/mock_redis/info_method.rb
86
87
  - lib/mock_redis/list_methods.rb
87
88
  - lib/mock_redis/multi_db_wrapper.rb
88
89
  - lib/mock_redis/pipelined_wrapper.rb