module Redis::Store::Serialization

Public Instance Methods

get(key, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 16
def get(key, options = nil)
  _unmarshal super(key), options
end
mget(*keys, &blk) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 20
def mget(*keys, &blk)
  options = keys.pop if keys.last.is_a?(Hash)
  super(*keys) do |reply|
    reply.map! { |value| _unmarshal value, options }
    blk ? blk.call(reply) : reply
  end
end
mset(*args) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 28
def mset(*args)
  options = args.pop if args.length.odd?
  updates = []
  args.each_slice(2) do |(key, value)|
    updates << encode(key)
    _marshal(value, options) { |v| updates << encode(v) }
  end
  super(*updates)
end
set(key, value, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 4
def set(key, value, options = nil)
  _marshal(value, options) { |v| super encode(key), encode(v), options }
end
setex(key, expiry, value, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 12
def setex(key, expiry, value, options = nil)
  _marshal(value, options) { |v| super encode(key), expiry, encode(v), options }
end
setnx(key, value, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/serialization.rb, line 8
def setnx(key, value, options = nil)
  _marshal(value, options) { |v| super encode(key), encode(v), options }
end

Private Instance Methods

_marshal(val, options) { |marshal?(options) ? dump: val| ... } click to toggle source
# File lib/redis/store/serialization.rb, line 39
def _marshal(val, options)
  yield marshal?(options) ? @serializer.dump(val) : val
end
_unmarshal(val, options) click to toggle source
# File lib/redis/store/serialization.rb, line 43
def _unmarshal(val, options)
  unmarshal?(val, options) ? @serializer.load(val) : val
end
encode(string) click to toggle source
# File lib/redis/store/serialization.rb, line 56
def encode(string)
  key = string.to_s.dup
  key.force_encoding(Encoding::BINARY)
end
marshal?(options) click to toggle source
# File lib/redis/store/serialization.rb, line 47
def marshal?(options)
  !(options && options[:raw])
end
unmarshal?(result, options) click to toggle source
# File lib/redis/store/serialization.rb, line 51
def unmarshal?(result, options)
  result && result.size > 0 && marshal?(options)
end