Module: Redis::Helpers::CoreCommands

Included in:
Counter, Redis::HashKey, List, Set, SortedSet, Value
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



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

def delete
  redis.del key
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  redis.exists key
end

#expire(seconds) ⇒ Object



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

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

#expireat(unixtime) ⇒ Object



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

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

#marshal(value, domarshal = false) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/redis/helpers/core_commands.rb', line 59

def marshal(value, domarshal=false)
  if options[:marshal] || domarshal
    Marshal.dump(value)
  else
    value
  end
end

#move(dbindex) ⇒ Object



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

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

#persistObject



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

def persist
  redis.persist key
end

#rename(name, setkey = true) ⇒ Object



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

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



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

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

#sort(options = {}) ⇒ Object



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

def sort(options={})
  options[:order] = "asc alpha" if options.keys.count == 0  # compat with Ruby
  val = redis.sort(key, options)
  val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val
end

#ttlObject



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

def ttl
  redis.ttl(@key)
end

#typeObject



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

def type
  redis.type key
end

#unmarshal(value, domarshal = false) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/redis/helpers/core_commands.rb', line 67

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
      Marshal.load(value) 
    end
  else
    value
  end
end