Module: Redis::Store::Serialization

Defined in:
lib/redis/store/serialization.rb

Instance Method Summary collapse

Instance Method Details

#get(key, options = nil) ⇒ Object



16
17
18
# File 'lib/redis/store/serialization.rb', line 16

def get(key, options = nil)
  _unmarshal super(key), options
end

#mget(*keys, &blk) ⇒ Object



20
21
22
23
24
25
26
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



4
5
6
# 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) ⇒ Object



12
13
14
# 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) ⇒ Object



8
9
10
# 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