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

- (Object) delete Also known as: del, clear



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

def delete
  redis.del key
end

- (Boolean) exists?



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

def exists?
  redis.exists key
end

- (Object) expire(seconds)



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

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

- (Object) expireat(unixtime)



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

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

- (Object) marshal(value, domarshal = false)



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

- (Object) move(dbindex)



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

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

- (Object) persist



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

def persist
  redis.persist key
end

- (Object) rename(name, setkey = true)



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

- (Object) renamenx(name, setkey = true)



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

- (Object) sort(options = {})



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

- (Object) ttl



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

def ttl
  redis.ttl(@key)
end

- (Object) type



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

def type
  redis.type key
end

- (Object) unmarshal(value, domarshal = false)



67
68
69
70
71
72
73
74
75
# File 'lib/redis/helpers/core_commands.rb', line 67

def unmarshal(value, domarshal=false)
  if value.nil?
    nil
  elsif options[:marshal] || domarshal
    Marshal.load(value) 
  else
    value
  end
end