Module: Redis::Helpers::CoreCommands

Included in:
BaseObject
Defined in:
lib/redis/helpers/core_commands.rb

Overview

These are core commands that all types share (rename, etc)

Instance Method Summary collapse

Instance Method Details

#deleteObject Also known as: del, clear

Delete key. Redis: DEL



14
15
16
# File 'lib/redis/helpers/core_commands.rb', line 14

def delete
  redis.del key
end

#existsObject



5
6
7
# File 'lib/redis/helpers/core_commands.rb', line 5

def exists
  redis.exists key
end

#exists?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/redis/helpers/core_commands.rb', line 9

def exists?
  redis.exists? key
end

#expire(seconds) ⇒ Object



38
39
40
# File 'lib/redis/helpers/core_commands.rb', line 38

def expire(seconds)
  redis.expire key, seconds
end

#expireat(unixtime) ⇒ Object



42
43
44
# File 'lib/redis/helpers/core_commands.rb', line 42

def expireat(unixtime)
  redis.expireat key, unixtime
end

#marshal(value, domarshal = false) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/redis/helpers/core_commands.rb', line 62

def marshal(value, domarshal=false)
  if options[:marshal] || domarshal
    dump_args = options[:marshal_dump_args] || []
    serializer.dump(value, *(dump_args.is_a?(Array) ? dump_args : [dump_args]))
  else
    value
  end
end

#move(dbindex) ⇒ Object



54
55
56
# File 'lib/redis/helpers/core_commands.rb', line 54

def move(dbindex)
  redis.move key, dbindex
end

#persistObject



46
47
48
# File 'lib/redis/helpers/core_commands.rb', line 46

def persist
  redis.persist key
end

#rename(name, setkey = true) ⇒ Object



24
25
26
27
28
29
# File 'lib/redis/helpers/core_commands.rb', line 24

def rename(name, setkey=true)
  dest = name.is_a?(self.class) ? name.key : name
  ret  = redis.rename key, dest
  @key = dest if ret && setkey
  ret
end

#renamenx(name, setkey = true) ⇒ Object



31
32
33
34
35
36
# File 'lib/redis/helpers/core_commands.rb', line 31

def renamenx(name, setkey=true)
  dest = name.is_a?(self.class) ? name.key : name
  ret  = redis.renamenx key, dest
  @key = dest if ret && setkey
  ret
end

#serializerObject



58
59
60
# File 'lib/redis/helpers/core_commands.rb', line 58

def serializer
  options[:serializer] || Marshal
end

#ttlObject



50
51
52
# File 'lib/redis/helpers/core_commands.rb', line 50

def ttl
  redis.ttl(@key)
end

#typeObject



20
21
22
# File 'lib/redis/helpers/core_commands.rb', line 20

def type
  redis.type key
end

#unmarshal(value, domarshal = false) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/redis/helpers/core_commands.rb', line 71

def unmarshal(value, domarshal=false)
  if value.nil?
    nil
  elsif options[:marshal] || domarshal
    if value.is_a?(Array)
      value.map{|v| unmarshal(v, domarshal)}
    elsif !value.is_a?(String)
      value
    else
      load_args = options[:marshal_load_args] || []
      serializer.load(value, *(load_args.is_a?(Array) ? load_args : [load_args]))
    end
  else
    value
  end
end