Class: Kredis::Types::Scalar

Inherits:
Proxying show all
Defined in:
lib/kredis/types/scalar.rb

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy, #redis

Instance Method Summary collapse

Methods inherited from Proxying

#failsafe, #initialize, proxying

Constructor Details

This class inherits a constructor from Kredis::Types::Proxying

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



4
5
6
# File 'lib/kredis/types/scalar.rb', line 4

def default
  @default
end

#expires_inObject

Returns the value of attribute expires_in.



4
5
6
# File 'lib/kredis/types/scalar.rb', line 4

def expires_in
  @expires_in
end

#typedObject

Returns the value of attribute typed.



4
5
6
# File 'lib/kredis/types/scalar.rb', line 4

def typed
  @typed
end

Instance Method Details

#assigned?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/kredis/types/scalar.rb', line 24

def assigned?
  exists?
end

#clearObject



28
29
30
# File 'lib/kredis/types/scalar.rb', line 28

def clear
  del
end

#expire_at(datetime) ⇒ Object



36
37
38
# File 'lib/kredis/types/scalar.rb', line 36

def expire_at(datetime)
  expireat datetime.to_i
end

#expire_in(seconds) ⇒ Object



32
33
34
# File 'lib/kredis/types/scalar.rb', line 32

def expire_in(seconds)
  expire seconds.to_i
end

#to_sObject



20
21
22
# File 'lib/kredis/types/scalar.rb', line 20

def to_s
  get || default&.to_s
end

#valueObject



10
11
12
13
14
15
16
17
18
# File 'lib/kredis/types/scalar.rb', line 10

def value
  value_after_casting = string_to_type(get, typed)

  if value_after_casting.nil?
    default
  else
    value_after_casting
  end
end

#value=(value) ⇒ Object



6
7
8
# File 'lib/kredis/types/scalar.rb', line 6

def value=(value)
  set type_to_string(value, typed), ex: expires_in
end