Class: RedisStore::MarshalledClient

Inherits:
Redis::Client
  • Object
show all
Defined in:
lib/redis_store/marshalled_client.rb

Instance Method Summary collapse

Instance Method Details

#marshalled_get(key, options = nil) ⇒ Object



28
29
30
31
32
# File 'lib/redis_store/marshalled_client.rb', line 28

def marshalled_get(key, options = nil)
  result = call_command([:get, key])
  result = Marshal.load result if unmarshal?(result, options)
  result
end

#marshalled_set(key, val, options = nil) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/redis_store/marshalled_client.rb', line 3

def marshalled_set(key, val, options = nil)
  val = marshal_value(val, options)
  if expires_in = expires_in(options)
    set_with_expire(key, val, expires_in)
  else
    set(key, val)
  end
end

#marshalled_setnx(key, val, options = nil) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/redis_store/marshalled_client.rb', line 12

def marshalled_setnx(key, val, options = nil)
  val = marshal_value(val, options)
  if expires_in = expires_in(options)
    setnx_with_expire(key, val, expires_in)
  else
    setnx(key, val)
  end
end

#setnx_with_expire(key, value, ttl) ⇒ Object



21
22
23
24
25
26
# File 'lib/redis_store/marshalled_client.rb', line 21

def setnx_with_expire(key, value, ttl)
  multi do
    setnx(key, val)
    expire(key, expires_in)
  end
end