vanity 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +35 -0
  2. data/README.rdoc +33 -6
  3. data/lib/vanity.rb +13 -7
  4. data/lib/vanity/backport.rb +43 -0
  5. data/lib/vanity/commands/report.rb +13 -3
  6. data/lib/vanity/experiment/ab_test.rb +98 -66
  7. data/lib/vanity/experiment/base.rb +51 -5
  8. data/lib/vanity/metric.rb +213 -0
  9. data/lib/vanity/mock_redis.rb +76 -0
  10. data/lib/vanity/playground.rb +78 -61
  11. data/lib/vanity/rails/dashboard.rb +11 -2
  12. data/lib/vanity/rails/helpers.rb +3 -3
  13. data/lib/vanity/templates/_ab_test.erb +3 -4
  14. data/lib/vanity/templates/_experiment.erb +4 -4
  15. data/lib/vanity/templates/_experiments.erb +2 -2
  16. data/lib/vanity/templates/_metric.erb +9 -0
  17. data/lib/vanity/templates/_metrics.erb +13 -0
  18. data/lib/vanity/templates/_report.erb +14 -3
  19. data/lib/vanity/templates/flot.min.js +1 -0
  20. data/lib/vanity/templates/jquery.min.js +19 -0
  21. data/lib/vanity/templates/vanity.css +16 -4
  22. data/lib/vanity/templates/vanity.js +96 -0
  23. data/test/ab_test_test.rb +159 -96
  24. data/test/experiment_test.rb +99 -18
  25. data/test/experiments/age_and_zipcode.rb +1 -0
  26. data/test/experiments/metrics/cheers.rb +3 -0
  27. data/test/experiments/metrics/signups.rb +2 -0
  28. data/test/experiments/metrics/yawns.rb +3 -0
  29. data/test/experiments/null_abc.rb +1 -0
  30. data/test/metric_test.rb +287 -0
  31. data/test/playground_test.rb +1 -80
  32. data/test/rails_test.rb +9 -6
  33. data/test/test_helper.rb +37 -6
  34. data/vanity.gemspec +1 -1
  35. data/vendor/{redis-0.1 → redis-rb}/LICENSE +0 -0
  36. data/vendor/{redis-0.1 → redis-rb}/README.markdown +0 -0
  37. data/vendor/{redis-0.1 → redis-rb}/Rakefile +0 -0
  38. data/vendor/redis-rb/bench.rb +44 -0
  39. data/vendor/redis-rb/benchmarking/suite.rb +24 -0
  40. data/vendor/redis-rb/benchmarking/worker.rb +71 -0
  41. data/vendor/redis-rb/bin/distredis +33 -0
  42. data/vendor/redis-rb/examples/basic.rb +16 -0
  43. data/vendor/redis-rb/examples/incr-decr.rb +18 -0
  44. data/vendor/redis-rb/examples/list.rb +26 -0
  45. data/vendor/redis-rb/examples/sets.rb +36 -0
  46. data/vendor/{redis-0.1 → redis-rb}/lib/dist_redis.rb +0 -0
  47. data/vendor/{redis-0.1 → redis-rb}/lib/hash_ring.rb +0 -0
  48. data/vendor/{redis-0.1 → redis-rb}/lib/pipeline.rb +0 -2
  49. data/vendor/{redis-0.1 → redis-rb}/lib/redis.rb +25 -7
  50. data/vendor/{redis-0.1 → redis-rb}/lib/redis/raketasks.rb +0 -0
  51. data/vendor/redis-rb/profile.rb +22 -0
  52. data/vendor/redis-rb/redis-rb.gemspec +30 -0
  53. data/vendor/{redis-0.1 → redis-rb}/spec/redis_spec.rb +113 -0
  54. data/vendor/{redis-0.1 → redis-rb}/spec/spec_helper.rb +0 -0
  55. data/vendor/redis-rb/speed.rb +16 -0
  56. data/vendor/{redis-0.1 → redis-rb}/tasks/redis.tasks.rb +5 -1
  57. metadata +37 -14
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'redis'
3
+
4
+ r = Redis.new
5
+
6
+ r.delete 'logs'
7
+
8
+ puts
9
+
10
+ p "pushing log messages into a LIST"
11
+ r.push_tail 'logs', 'some log message'
12
+ r.push_tail 'logs', 'another log message'
13
+ r.push_tail 'logs', 'yet another log message'
14
+ r.push_tail 'logs', 'also another log message'
15
+
16
+ puts
17
+ p 'contents of logs LIST'
18
+
19
+ p r.list_range('logs', 0, -1)
20
+
21
+ puts
22
+ p 'Trim logs LIST to last 2 elements(easy circular buffer)'
23
+
24
+ r.list_trim('logs', -2, -1)
25
+
26
+ p r.list_range('logs', 0, -1)
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'redis'
3
+
4
+ r = Redis.new
5
+
6
+ r.delete 'foo-tags'
7
+ r.delete 'bar-tags'
8
+
9
+ puts
10
+ p "create a set of tags on foo-tags"
11
+
12
+ r.set_add 'foo-tags', 'one'
13
+ r.set_add 'foo-tags', 'two'
14
+ r.set_add 'foo-tags', 'three'
15
+
16
+ puts
17
+ p "create a set of tags on bar-tags"
18
+
19
+ r.set_add 'bar-tags', 'three'
20
+ r.set_add 'bar-tags', 'four'
21
+ r.set_add 'bar-tags', 'five'
22
+
23
+ puts
24
+ p 'foo-tags'
25
+
26
+ p r.set_members('foo-tags')
27
+
28
+ puts
29
+ p 'bar-tags'
30
+
31
+ p r.set_members('bar-tags')
32
+
33
+ puts
34
+ p 'intersection of foo-tags and bar-tags'
35
+
36
+ p r.set_intersect('foo-tags', 'bar-tags')
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- require "redis"
2
-
3
1
  class Redis
4
2
  class Pipeline < Redis
5
3
  BUFFER_SIZE = 50_000
@@ -31,14 +31,18 @@ class Redis
31
31
  "sadd" => true,
32
32
  "srem" => true,
33
33
  "sismember" => true,
34
+ "rpoplpush" => true,
34
35
  "echo" => true,
35
36
  "getset" => true,
36
- "smove" => true
37
+ "smove" => true,
38
+ "zadd" => true,
39
+ "zrem" => true,
40
+ "zscore" => true
37
41
  }
38
-
42
+
39
43
  MULTI_BULK_COMMANDS = {
40
- "mset" => true,
41
- "msetnx" => true
44
+ "mset" => true,
45
+ "msetnx" => true
42
46
  }
43
47
 
44
48
  BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
@@ -49,6 +53,8 @@ class Redis
49
53
  "sadd" => BOOLEAN_PROCESSOR,
50
54
  "srem" => BOOLEAN_PROCESSOR,
51
55
  "smove" => BOOLEAN_PROCESSOR,
56
+ "zadd" => BOOLEAN_PROCESSOR,
57
+ "zrem" => BOOLEAN_PROCESSOR,
52
58
  "move" => BOOLEAN_PROCESSOR,
53
59
  "setnx" => BOOLEAN_PROCESSOR,
54
60
  "del" => BOOLEAN_PROCESSOR,
@@ -97,7 +103,14 @@ class Redis
97
103
  "set_move" => "smove",
98
104
  "set_unless_exists" => "setnx",
99
105
  "rename_unless_exists" => "renamenx",
100
- "type?" => "type"
106
+ "type?" => "type",
107
+ "zset_add" => "zadd",
108
+ "zset_count" => 'zcard',
109
+ "zset_range_by_score" => 'zrangebyscore',
110
+ "zset_reverse_range" => 'zrevrange',
111
+ "zset_range" => 'zrange',
112
+ "zset_delete" => 'zrem',
113
+ "zset_score" => 'zscore'
101
114
  }
102
115
 
103
116
  DISABLED_COMMANDS = {
@@ -155,8 +168,13 @@ class Redis
155
168
  secs = Integer(timeout)
156
169
  usecs = Integer((timeout - secs) * 1_000_000)
157
170
  optval = [secs, usecs].pack("l_2")
158
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
159
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
171
+ begin
172
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
173
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
174
+ rescue Exception => ex
175
+ # Solaris, for one, does not like/support socket timeouts.
176
+ @logger.info "Unable to use raw socket timeouts: #{ex.class.name}: #{ex.message}" if @logger
177
+ end
160
178
  end
161
179
  sock
162
180
  end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'ruby-prof'
3
+ require "#{File.dirname(__FILE__)}/lib/redis"
4
+
5
+
6
+ mode = ARGV.shift || 'process_time'
7
+ n = (ARGV.shift || 200).to_i
8
+
9
+ r = Redis.new
10
+ RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
11
+ RubyProf.start
12
+
13
+ n.times do |i|
14
+ key = "foo#{i}"
15
+ r[key] = key * 10
16
+ r[key]
17
+ end
18
+
19
+ results = RubyProf.stop
20
+ File.open("profile.#{mode}", 'w') do |out|
21
+ RubyProf::CallTreePrinter.new(results).print(out)
22
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{redis}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ezra Zygmuntowicz", "Taylor Weibley", "Matthew Clark", "Brian McKinney", "Salvatore Sanfilippo", "Luca Guidi"]
9
+ # s.autorequire = %q{redis-rb}
10
+ s.date = %q{2009-06-23}
11
+ s.description = %q{Ruby client library for redis key value storage server}
12
+ s.email = %q{ez@engineyard.com}
13
+ s.extra_rdoc_files = ["LICENSE"]
14
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/dist_redis.rb", "lib/hash_ring.rb", "lib/pipeline.rb", "lib/redis.rb", "spec/redis_spec.rb", "spec/spec_helper.rb"]
15
+ s.has_rdoc = true
16
+ s.homepage = %q{http://github.com/ezmobius/redis-rb}
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.3.1}
19
+ s.summary = %q{Ruby client library for redis key value storage server}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -275,6 +275,22 @@ describe "redis" do
275
275
  @r.lrem('list', 1, 'hello').should == 1
276
276
  @r.lrange('list', 0, -1).should == ['goodbye']
277
277
  end
278
+
279
+ it "should be able to pop values from a list and push them onto a temp list(RPOPLPUSH)" do
280
+ @r.rpush "list", 'one'
281
+ @r.rpush "list", 'two'
282
+ @r.rpush "list", 'three'
283
+ @r.type('list').should == "list"
284
+ @r.llen('list').should == 3
285
+ @r.lrange('list',0,-1).should == ['one', 'two', 'three']
286
+ @r.lrange('tmp',0,-1).should == []
287
+ @r.rpoplpush('list', 'tmp').should == 'three'
288
+ @r.lrange('tmp',0,-1).should == ['three']
289
+ @r.rpoplpush('list', 'tmp').should == 'two'
290
+ @r.lrange('tmp',0,-1).should == ['two', 'three']
291
+ @r.rpoplpush('list', 'tmp').should == 'one'
292
+ @r.lrange('tmp',0,-1).should == ['one','two','three']
293
+ end
278
294
  #
279
295
  it "should be able add members to a set (SADD)" do
280
296
  @r.sadd "set", 'key1'
@@ -415,6 +431,103 @@ describe "redis" do
415
431
  @r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha').should == ['taj', 'terrier']
416
432
  end
417
433
  #
434
+ it "should be able count the members of a zset" do
435
+ @r.set_add "set", 'key1'
436
+ @r.set_add "set", 'key2'
437
+ @r.zset_add 'zset', 1, 'set'
438
+ @r.zset_count('zset').should == 1
439
+ @r.delete('set')
440
+ @r.delete('zset')
441
+ end
442
+ #
443
+ it "should be able add members to a zset" do
444
+ @r.set_add "set", 'key1'
445
+ @r.set_add "set", 'key2'
446
+ @r.zset_add 'zset', 1, 'set'
447
+ @r.zset_range('zset', 0, 1).should == ['set']
448
+ @r.zset_count('zset').should == 1
449
+ @r.delete('set')
450
+ @r.delete('zset')
451
+ end
452
+ #
453
+ it "should be able delete members to a zset" do
454
+ @r.set_add "set", 'key1'
455
+ @r.set_add "set", 'key2'
456
+ @r.type?('set').should == "set"
457
+ @r.set_add "set2", 'key3'
458
+ @r.set_add "set2", 'key4'
459
+ @r.type?('set2').should == "set"
460
+ @r.zset_add 'zset', 1, 'set'
461
+ @r.zset_count('zset').should == 1
462
+ @r.zset_add 'zset', 2, 'set2'
463
+ @r.zset_count('zset').should == 2
464
+ @r.zset_delete 'zset', 'set'
465
+ @r.zset_count('zset').should == 1
466
+ @r.delete('set')
467
+ @r.delete('set2')
468
+ @r.delete('zset')
469
+ end
470
+ #
471
+ it "should be able to get a range of values from a zset" do
472
+ @r.set_add "set", 'key1'
473
+ @r.set_add "set", 'key2'
474
+ @r.set_add "set2", 'key3'
475
+ @r.set_add "set2", 'key4'
476
+ @r.set_add "set3", 'key1'
477
+ @r.type?('set').should == 'set'
478
+ @r.type?('set2').should == 'set'
479
+ @r.type?('set3').should == 'set'
480
+ @r.zset_add 'zset', 1, 'set'
481
+ @r.zset_add 'zset', 2, 'set2'
482
+ @r.zset_add 'zset', 3, 'set3'
483
+ @r.zset_count('zset').should == 3
484
+ @r.zset_range('zset', 0, 3).should == ['set', 'set2', 'set3']
485
+ @r.delete('set')
486
+ @r.delete('set2')
487
+ @r.delete('set3')
488
+ @r.delete('zset')
489
+ end
490
+ #
491
+ it "should be able to get a reverse range of values from a zset" do
492
+ @r.set_add "set", 'key1'
493
+ @r.set_add "set", 'key2'
494
+ @r.set_add "set2", 'key3'
495
+ @r.set_add "set2", 'key4'
496
+ @r.set_add "set3", 'key1'
497
+ @r.type?('set').should == 'set'
498
+ @r.type?('set2').should == 'set'
499
+ @r.type?('set3').should == 'set'
500
+ @r.zset_add 'zset', 1, 'set'
501
+ @r.zset_add 'zset', 2, 'set2'
502
+ @r.zset_add 'zset', 3, 'set3'
503
+ @r.zset_count('zset').should == 3
504
+ @r.zset_reverse_range('zset', 0, 3).should == ['set3', 'set2', 'set']
505
+ @r.delete('set')
506
+ @r.delete('set2')
507
+ @r.delete('set3')
508
+ @r.delete('zset')
509
+ end
510
+ #
511
+ it "should be able to get a range by score of values from a zset" do
512
+ @r.set_add "set", 'key1'
513
+ @r.set_add "set", 'key2'
514
+ @r.set_add "set2", 'key3'
515
+ @r.set_add "set2", 'key4'
516
+ @r.set_add "set3", 'key1'
517
+ @r.set_add "set4", 'key4'
518
+ @r.zset_add 'zset', 1, 'set'
519
+ @r.zset_add 'zset', 2, 'set2'
520
+ @r.zset_add 'zset', 3, 'set3'
521
+ @r.zset_add 'zset', 4, 'set4'
522
+ @r.zset_count('zset').should == 4
523
+ @r.zset_range_by_score('zset', 2, 3).should == ['set2', 'set3']
524
+ @r.delete('set')
525
+ @r.delete('set2')
526
+ @r.delete('set3')
527
+ @r.delete('set4')
528
+ @r.delete('zset')
529
+ end
530
+
418
531
  it "should provide info (INFO)" do
419
532
  [:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
420
533
  @r.info.keys.should include(x)
File without changes
@@ -0,0 +1,16 @@
1
+ require 'benchmark'
2
+ require "#{File.dirname(__FILE__)}/lib/redis"
3
+
4
+ r = Redis.new
5
+ n = (ARGV.shift || 20000).to_i
6
+
7
+ elapsed = Benchmark.realtime do
8
+ # n sets, n gets
9
+ n.times do |i|
10
+ key = "foo#{i}"
11
+ r[key] = key * 10
12
+ r[key]
13
+ end
14
+ end
15
+
16
+ puts '%.2f Kops' % (2 * n / 1000 / elapsed)
@@ -93,7 +93,11 @@ namespace :redis do
93
93
  task :download do
94
94
  sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
95
95
  sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
96
- sh "cd #{RedisRunner.redisdir} && git pull" if File.exists?("#{RedisRunner.redisdir}/.git")
96
+
97
+ if File.exists?("#{RedisRunner.redisdir}/.git")
98
+ arguments = ENV['COMMIT'].nil? ? "pull" : "reset --hard #{ENV['COMMIT']}"
99
+ sh "cd #{RedisRunner.redisdir} && git #{arguments}"
100
+ end
97
101
  end
98
102
 
99
103
  desc "Open an IRb session"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assaf Arkin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 -08:00
12
+ date: 2009-12-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,10 +24,13 @@ extra_rdoc_files:
24
24
  - CHANGELOG
25
25
  files:
26
26
  - bin/vanity
27
+ - lib/vanity/backport.rb
27
28
  - lib/vanity/commands/report.rb
28
29
  - lib/vanity/commands.rb
29
30
  - lib/vanity/experiment/ab_test.rb
30
31
  - lib/vanity/experiment/base.rb
32
+ - lib/vanity/metric.rb
33
+ - lib/vanity/mock_redis.rb
31
34
  - lib/vanity/playground.rb
32
35
  - lib/vanity/rails/dashboard.rb
33
36
  - lib/vanity/rails/helpers.rb
@@ -36,24 +39,44 @@ files:
36
39
  - lib/vanity/templates/_ab_test.erb
37
40
  - lib/vanity/templates/_experiment.erb
38
41
  - lib/vanity/templates/_experiments.erb
42
+ - lib/vanity/templates/_metric.erb
43
+ - lib/vanity/templates/_metrics.erb
39
44
  - lib/vanity/templates/_report.erb
45
+ - lib/vanity/templates/flot.min.js
46
+ - lib/vanity/templates/jquery.min.js
40
47
  - lib/vanity/templates/vanity.css
48
+ - lib/vanity/templates/vanity.js
41
49
  - lib/vanity.rb
42
- - vendor/redis-0.1/lib/dist_redis.rb
43
- - vendor/redis-0.1/lib/hash_ring.rb
44
- - vendor/redis-0.1/lib/pipeline.rb
45
- - vendor/redis-0.1/lib/redis/raketasks.rb
46
- - vendor/redis-0.1/lib/redis.rb
47
- - vendor/redis-0.1/LICENSE
48
- - vendor/redis-0.1/Rakefile
49
- - vendor/redis-0.1/README.markdown
50
- - vendor/redis-0.1/spec/redis_spec.rb
51
- - vendor/redis-0.1/spec/spec_helper.rb
52
- - vendor/redis-0.1/tasks/redis.tasks.rb
50
+ - vendor/redis-rb/bench.rb
51
+ - vendor/redis-rb/benchmarking/suite.rb
52
+ - vendor/redis-rb/benchmarking/worker.rb
53
+ - vendor/redis-rb/bin/distredis
54
+ - vendor/redis-rb/examples/basic.rb
55
+ - vendor/redis-rb/examples/incr-decr.rb
56
+ - vendor/redis-rb/examples/list.rb
57
+ - vendor/redis-rb/examples/sets.rb
58
+ - vendor/redis-rb/lib/dist_redis.rb
59
+ - vendor/redis-rb/lib/hash_ring.rb
60
+ - vendor/redis-rb/lib/pipeline.rb
61
+ - vendor/redis-rb/lib/redis/raketasks.rb
62
+ - vendor/redis-rb/lib/redis.rb
63
+ - vendor/redis-rb/LICENSE
64
+ - vendor/redis-rb/profile.rb
65
+ - vendor/redis-rb/Rakefile
66
+ - vendor/redis-rb/README.markdown
67
+ - vendor/redis-rb/redis-rb.gemspec
68
+ - vendor/redis-rb/spec/redis_spec.rb
69
+ - vendor/redis-rb/spec/spec_helper.rb
70
+ - vendor/redis-rb/speed.rb
71
+ - vendor/redis-rb/tasks/redis.tasks.rb
53
72
  - test/ab_test_test.rb
54
73
  - test/experiment_test.rb
55
74
  - test/experiments/age_and_zipcode.rb
75
+ - test/experiments/metrics/cheers.rb
76
+ - test/experiments/metrics/signups.rb
77
+ - test/experiments/metrics/yawns.rb
56
78
  - test/experiments/null_abc.rb
79
+ - test/metric_test.rb
57
80
  - test/playground_test.rb
58
81
  - test/rails_test.rb
59
82
  - test/test_helper.rb
@@ -68,7 +91,7 @@ licenses: []
68
91
  post_install_message: To get started run vanity --help
69
92
  rdoc_options:
70
93
  - --title
71
- - Vanity 1.0.0
94
+ - Vanity 1.1.0
72
95
  - --main
73
96
  - README.rdoc
74
97
  - --webcvs