redis_object 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzZmMGZlNjJjNDM2NDUzZDc1NWY1YjdjMzNlMDRlZmI2OTljMmMwMg==
4
+ MzM4MzMyNzVhNTUxNWY4NDlhZDQ4ZGYxOTIxMDEwZGMxMjY2MjM4Yg==
5
5
  data.tar.gz: !binary |-
6
- NWM0MDhkYzAzODdiZDI3NDliMjViOGQ1Njg0ZDNmZmQ2YmFlODI2OQ==
6
+ MzU2MWQxMDA1MDUyMGUwYjc1Mzk0MzQxMjBkNTE0NDFmNzhmOTU1MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTlkMTQ2ZmZkY2ZlZmRkNjgyNTA1NDJiZjI5ZDk4Yjc5MTc2YTEzNjdlZThh
10
- ODM0YWIzMTdkNGE0NzgzNDM0OGViMzAwYTljYTg5YmY0NzkzMWQ0ZDQwNGIz
11
- NWE3YmRjYzJkZjcxMTFhOGNmOTJkM2RmNjg3NGMzZjA0NjdkZWU=
9
+ ZmVlMWJiMTBjNzg4ZDBlNzEzOGQ2ZTJmNzAzNWFhM2QwOGY3NDhiMWI3NmMw
10
+ ZTcyZGRmM2Y3ZGExZjgzNzI0ZTY1Yzk0MmFkMjJiN2Q0ODM0MzI5ODkyZTBm
11
+ YjdhMDY2NTkyOTM2N2RiNDIwZGY0YzNjMTk5NzQ5ODk2MTM0MDA=
12
12
  data.tar.gz: !binary |-
13
- YjBjM2IxNDkwNTRjYTVlYjU5ZGM0NzM1MTJlZjk4MGQ0YmQ2YjZlNzJjMDZh
14
- ZjY3MDk3YTVkMDM5NmM5YzFmZmViNGQ4Mjc2ODQ3ZTUyNDBkOTI2OTc0ZmM2
15
- M2FhY2I1ZmQzMjI3YTdkYzFiZjc5YjY5MWRmOTU2OWNmMDM2NWU=
13
+ YTllMGUzYzk3OTlhOTUwNDQzYmVhYmYzZDk4ZjQ1MjBhYjlhOWZjOTI4OTZi
14
+ N2E0N2ExODY1NDQ1N2NmYzM3NmY5NWM5NjFjZjYyZGRhY2NmZTY0Y2Y0NzA1
15
+ YThmNDgxOGQzMTc2MTZkMmYyZTEzZTVjOTJhYzYxODBkMTFiYzI=
data/lib/redis_object.rb CHANGED
@@ -45,4 +45,6 @@ module Seabright
45
45
  end
46
46
  end
47
47
 
48
+ require "redis_object/logger"
49
+
48
50
  ::RedisObject = Seabright::RedisObject
@@ -219,10 +219,10 @@ module Seabright
219
219
  def generate_id
220
220
  v = new_id
221
221
  while exists?(v) do
222
- puts "[RedisObject] Collision at id: #{v}" if Debug.verbose?
222
+ Log.verbose "[RedisObject] Collision at id: #{v}"
223
223
  v = new_id
224
224
  end
225
- puts "[RedisObject] Reserving key: #{v}" if Debug.verbose?
225
+ Log.verbose "[RedisObject] Reserving key: #{v}"
226
226
  reserve(v)
227
227
  v
228
228
  end
@@ -250,7 +250,7 @@ module Seabright
250
250
  if a = find_by_key(hkey(member))
251
251
  y << a
252
252
  else
253
- puts "[#{name}] Object listed but not found: #{member}" if DEBUG
253
+ Log.debug "[#{name}] Object listed but not found: #{member}"
254
254
  store.srem(plname,member)
255
255
  end
256
256
  end
@@ -319,12 +319,12 @@ module Seabright
319
319
  def cleanup!
320
320
  each_index do |key|
321
321
  unless a = class_const.find_by_key(at(key))
322
- puts "Deleting #{key} because not #{a.inspect}" if DEBUG
322
+ Log.debug "Deleting #{key} because not #{a.inspect}"
323
323
  delete at(key)
324
324
  end
325
325
  end
326
326
  if size < 1
327
- puts "Deleting collection #{@name} because empty" if DEBUG
327
+ Log.debug "Deleting collection #{@name} because empty"
328
328
  remove!
329
329
  end
330
330
  end
@@ -30,7 +30,7 @@ module Seabright
30
30
  end
31
31
 
32
32
  def self.load_object(klass,pkt)
33
- puts "Loading a #{klass.name}: #{pkt.inspect}" if DEBUG
33
+ Log.debug "Loading a #{klass.name}: #{pkt.inspect}"
34
34
  cols = nil
35
35
  pkt.delete(:collections).each do |col_name|
36
36
  if objs = pkt.delete(col_name.to_sym)
@@ -41,7 +41,7 @@ module Seabright
41
41
  obj = klass.create(pkt)
42
42
  if cols
43
43
  cols.each do |name,objs|
44
- puts " Loading in collected #{name}: #{objs.inspect}" if DEBUG
44
+ Log.debug " Loading in collected #{name}: #{objs.inspect}"
45
45
  obj.collect_type_by_key name, *objs
46
46
  end
47
47
  end
@@ -16,7 +16,7 @@ module Seabright
16
16
  end
17
17
 
18
18
  def benchmark_out(method,args,time)
19
- puts "[RedisObject::Benchmark] #{method}(#{args.join(",")}): #{time}"
19
+ Log.debug "[RedisObject::Benchmark] #{method}(#{args.join(",")}): #{time}"
20
20
  end
21
21
 
22
22
  def benchmark!
@@ -4,7 +4,7 @@ module Seabright
4
4
  RedisObject.store.keys("*:collections").each do |key|
5
5
  if obj = RedisObject.find_by_key(key.gsub(/:collections$/,''))
6
6
  obj.collections.each do |nm,col|
7
- puts "Cleaning: #{nm} #{col.class} #{col.inspect}" if DEBUG
7
+ Log.debug "Cleaning: #{nm} #{col.class} #{col.inspect}"
8
8
  col.cleanup!
9
9
  end
10
10
  end
@@ -23,7 +23,7 @@ module Seabright
23
23
  out = (@tmp_store || store).evalsha(get_script_sha(name,source),keys,args)
24
24
  rescue Redis::CommandError => e
25
25
  if e.message == NoScriptError && @rescue_recurse < 3
26
- puts "Rescuing NOSCRIPT error for #{name} - running again..." if DEBUG
26
+ Log.debug "Rescuing NOSCRIPT error for #{name} - running again..."
27
27
  untrack_script name
28
28
  @rescue_recurse += 1
29
29
  out = (@tmp_store || store).evalsha(get_script_sha(name,source),keys,args)
@@ -45,10 +45,10 @@ module Seabright
45
45
  def view_as_hash(name)
46
46
  return uncached_view_as_hash(name) unless self.class.view_should_be_cached?(name)
47
47
  if v = view_from_cache(name)
48
- puts " Got view from cache: #{name}" if DEBUG
48
+ Log.debug " Got view from cache: #{name}"
49
49
  Yajl::Parser.parse(v)
50
50
  else
51
- puts " View cache miss: #{name}" if DEBUG
51
+ Log.debug " View cache miss: #{name}"
52
52
  cache_view_content(name)[0]
53
53
  end
54
54
  end
@@ -57,10 +57,10 @@ module Seabright
57
57
  def view_as_json(name)
58
58
  return uncached_view_as_json(name) unless self.class.view_should_be_cached?(name)
59
59
  if v = view_from_cache(name)
60
- puts " Got view from cache: #{name}" if DEBUG
60
+ Log.debug " Got view from cache: #{name}"
61
61
  v
62
62
  else
63
- puts " View cache miss: #{name}" if DEBUG
63
+ Log.debug " View cache miss: #{name}"
64
64
  cache_view_content(name)[1]
65
65
  end
66
66
  end
@@ -107,7 +107,7 @@ module Seabright
107
107
  self.class_eval do
108
108
 
109
109
  def invalidate_cached_views(*names)
110
- puts "Invalidating cached views: #{names.join(", ")}" if Debug.verbose?
110
+ Log.verbose "Invalidating cached views: #{names.join(", ")}"
111
111
  run_script(:CachedViewInvalidator, [cached_view_key], names, CachedViewInvalidator)
112
112
  self.class.cache_invalidation_hooks do |hook|
113
113
  hook.call(names)
@@ -125,7 +125,7 @@ module Seabright
125
125
 
126
126
  def invalidate_downstream!
127
127
  return unless invalidations(:down).size > 0
128
- puts "Invalidating downstream: #{invalidations(:down).inspect}" if Debug.verbose?
128
+ Log.verbose "Invalidating downstream: #{invalidations(:down).inspect}"
129
129
  invalidations(:down).each do |col|
130
130
  if has_collection?(col) and (colctn = get_collection(col))
131
131
  colctn.each do |obj|
@@ -137,7 +137,7 @@ module Seabright
137
137
 
138
138
  def invalidate_upstream!
139
139
  return unless invalidations(:up).size > 0
140
- puts "Invalidating upstream: #{invalidations(:up).inspect}" if Debug.verbose?
140
+ Log.verbose "Invalidating upstream: #{invalidations(:up).inspect}"
141
141
  backreferences.each do |obj|
142
142
  obj = Object.const_get(obj) if obj.is_a?(String) or obj.is_a?(Symbol)
143
143
  if invalidations(:up).include?(obj.class) and obj.respond_to?(:invalidated_by_other)
@@ -170,7 +170,7 @@ module Seabright
170
170
 
171
171
  def invalidated_by_other(obj,chain)
172
172
  return if chain.include?(self.hkey)
173
- puts "#{self.class.name}:#{self.id}'s view caches were invalidated by upstream object: #{obj.class.name}:#{obj.id} (chain:#{chain.inspect})" if Debug.verbose?
173
+ Log.verbose "#{self.class.name}:#{self.id}'s view caches were invalidated by upstream object: #{obj.class.name}:#{obj.id} (chain:#{chain.inspect})"
174
174
  @invalidation_chain = chain
175
175
  [:invalidated_by,"invalidated_by_#{obj.class.name.underscore}".to_sym].each do |meth_sym|
176
176
  if respond_to?(meth_sym)
@@ -0,0 +1,47 @@
1
+ require 'logger'
2
+
3
+ module Seabright
4
+ class Log
5
+
6
+ class << self
7
+
8
+ def verbose(*args)
9
+ logger.verbose(*args) if logger.respond_to?(:verbose)
10
+ end
11
+
12
+ def debug(*args)
13
+ logger.debug(*args)
14
+ end
15
+
16
+ def info(*args)
17
+ logger.info(*args)
18
+ end
19
+
20
+ def warn(*args)
21
+ logger.warn(*args)
22
+ end
23
+
24
+ def error(*args)
25
+ logger.error(*args)
26
+ end
27
+
28
+ def fatal(*args)
29
+ logger.fatal(*args)
30
+ end
31
+
32
+ def logger
33
+ @@logger ||= Proc.new do
34
+ lg = Logger.new(STDOUT)
35
+ lg.level = Logger::WARN
36
+ lg
37
+ end.call
38
+ end
39
+
40
+ def logger=(new_logger)
41
+ @@logger = new_logger
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -66,7 +66,7 @@ module Seabright
66
66
  raise "Directory does not exist!" unless Dir.exists?(File.dirname(path))
67
67
  adapters.each do |name,adptr|
68
68
  if adptr.respond_to? :dump_to_file
69
- puts "Dumping #{name} into #{path}/#{name.to_s}.dump"
69
+ Log.info "Dumping #{name} into #{path}/#{name.to_s}.dump"
70
70
  adptr.dump_to_file("#{path}/#{name.to_s}.dump")
71
71
  end
72
72
  end
@@ -77,7 +77,7 @@ module Seabright
77
77
  Dir.glob(path + "/*.dump").each do |file|
78
78
  name = file.gsub(/\.[^\.]+$/,'').gsub(/.*\//,'').to_sym
79
79
  if (stor = store(name)) && stor.respond_to?(:restore_from_file)
80
- puts "Restoring #{name} from #{file}"
80
+ Log.info "Restoring #{name} from #{file}"
81
81
  stor.restore_from_file(file)
82
82
  end
83
83
  end
@@ -4,7 +4,7 @@ module Seabright
4
4
  class AWS
5
5
 
6
6
  def initialize(config={})
7
- puts "Got config: '#{config.inspect}'"
7
+ Log.debug "Got config: '#{config.inspect}'"
8
8
  @config = config
9
9
  end
10
10
 
@@ -4,11 +4,11 @@ module Seabright
4
4
 
5
5
  def method_missing(sym, *args, &block)
6
6
  return super unless connection.respond_to?(sym)
7
- puts "[Storage::Redis] #{sym}(#{args.inspect.gsub(/\[|\]/m,'')})" if Debug.verbose?
7
+ Log.verbose "[Storage::Redis] #{sym}(#{args.inspect.gsub(/\[|\]/m,'')})"
8
8
  begin
9
9
  connection.send(sym,*args, &block)
10
10
  rescue ::Redis::InheritedError, ::Redis::TimeoutError => err
11
- puts "Rescued: #{err.inspect}" if DEBUG
11
+ Log.debug "Rescued: #{err.inspect}"
12
12
  reset
13
13
  connection.send(sym,*args, &block)
14
14
  end
@@ -16,7 +16,7 @@ module Seabright
16
16
 
17
17
  def new_connection
18
18
  require 'redis'
19
- puts "Connecting to Redis with: #{config_opts(:path, :db, :password, :host, :port, :timeout, :tcp_keepalive).inspect}" if DEBUG
19
+ Log.debug "Connecting to Redis with: #{config_opts(:path, :db, :password, :host, :port, :timeout, :tcp_keepalive).inspect}"
20
20
  ::Redis.new(config_opts(:path, :db, :password, :host, :port, :timeout, :tcp_keepalive))
21
21
  end
22
22
 
@@ -6,7 +6,7 @@ module Seabright
6
6
  begin
7
7
  val.is_a?(DateTime) || val.is_a?(Date) || val.is_a?(Time) ? val : ( val.is_a?(String) ? DateTime.parse(val) : nil )
8
8
  rescue StandardError => e
9
- puts "Could not parse value as date using Date.parse. Returning nil instead. Value: #{val.inspect}\nError: #{e.inspect}" if DEBUG
9
+ Log.debug "Could not parse value as date using Date.parse. Returning nil instead. Value: #{val.inspect}\nError: #{e.inspect}"
10
10
  nil
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  module Seabright
2
2
  class RedisObject
3
- VERSION = "1.3.2"
3
+ VERSION = "1.3.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bragg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-13 00:00:00.000000000 Z
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utf8_utils
@@ -114,6 +114,7 @@ files:
114
114
  - lib/redis_object/indices.rb
115
115
  - lib/redis_object/inheritance_tracking.rb
116
116
  - lib/redis_object/keys.rb
117
+ - lib/redis_object/logger.rb
117
118
  - lib/redis_object/storage.rb
118
119
  - lib/redis_object/storage/adapter.rb
119
120
  - lib/redis_object/storage/aws.rb