Class: Redrecord
- Inherits:
-
Object
- Object
- Redrecord
- Defined in:
- lib/redrecord.rb
Defined Under Namespace
Modules: Model
Class Attribute Summary collapse
-
.enabled ⇒ Object
Returns the value of attribute enabled.
-
.redis ⇒ Object
Returns the value of attribute redis.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
-
.write_only ⇒ Object
Returns the value of attribute write_only.
Class Method Summary collapse
- .is_marshalled?(str) ⇒ Boolean
- .marshal(obj) ⇒ Object
- .redis_op(op, *args) ⇒ Object
- .unmarshal(str) ⇒ Object
- .update_queue ⇒ Object
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
7 8 9 |
# File 'lib/redrecord.rb', line 7 def enabled @enabled end |
.redis ⇒ Object
Returns the value of attribute redis.
7 8 9 |
# File 'lib/redrecord.rb', line 7 def redis @redis end |
.timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/redrecord.rb', line 7 def timeout @timeout end |
.write_only ⇒ Object
Returns the value of attribute write_only.
7 8 9 |
# File 'lib/redrecord.rb', line 7 def write_only @write_only end |
Class Method Details
.is_marshalled?(str) ⇒ Boolean
11 12 13 |
# File 'lib/redrecord.rb', line 11 def is_marshalled?(str) Marshal.dump(nil)[0,2] == str[0,2] end |
.marshal(obj) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/redrecord.rb', line 23 def marshal(obj) if Integer===obj || String===obj && obj !~ /^\d+$/ && !is_marshalled?(obj) obj.to_s else Marshal.dump(obj) end end |
.redis_op(op, *args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redrecord.rb', line 30 def redis_op(op, *args) if @enabled begin Timeout.timeout(@timeout || 15) do redis.send(op, *args) end rescue Exception => e $stderr.puts "Redrecord: Disabling redis due to exception (#{e})" @enabled = false end end end |
.unmarshal(str) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/redrecord.rb', line 14 def unmarshal(str) if(is_marshalled?(str)) Marshal.load(str) elsif(str =~ /^\d+$/) str.to_i else str end end |
.update_queue ⇒ Object
8 9 10 |
# File 'lib/redrecord.rb', line 8 def update_queue Thread.current[:redrecord_update_queue] ||= [] end |