Class: Redis::Value

Inherits:
BaseObject show all
Includes:
Helpers::CoreCommands, Helpers::Serialize
Defined in:
lib/redis/value.rb

Overview

Class representing a simple value. You can use standard Ruby operations on it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Serialize

#from_redis, #to_redis

Methods included from Helpers::CoreCommands

#delete, #exists?, #expire, #expireat, #move, #rename, #renamenx, #sort, #ttl, #type

Constructor Details

#initialize(key, *args) ⇒ Value

Returns a new instance of Value.



14
15
16
17
# File 'lib/redis/value.rb', line 14

def initialize(key, *args)
  super(key, *args)
  @redis.setnx(key, @options[:default]) if @options[:default]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/redis/value.rb', line 13

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/redis/value.rb', line 13

def options
  @options
end

#redisObject (readonly)

Returns the value of attribute redis.



13
14
15
# File 'lib/redis/value.rb', line 13

def redis
  @redis
end

Instance Method Details

#==(x) ⇒ Object



30
# File 'lib/redis/value.rb', line 30

def ==(x); value == x; end

#nil?Boolean

Returns:

  • (Boolean)


31
# File 'lib/redis/value.rb', line 31

def nil?;  value.nil?; end

#to_sObject



29
# File 'lib/redis/value.rb', line 29

def to_s;  value.to_s; end

#valueObject Also known as: get



24
25
26
# File 'lib/redis/value.rb', line 24

def value
  from_redis redis.get(key)
end

#value=(val) ⇒ Object Also known as: set



19
20
21
# File 'lib/redis/value.rb', line 19

def value=(val)
  redis.set key, to_redis(val)
end