Class: Kredis::Types::Scalar

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

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy

Instance Method Summary collapse

Methods included from DefaultValues

#initialize

Methods inherited from Proxying

#failsafe, #initialize, proxying, #unproxied_redis

Instance Attribute Details

#expires_inObject

Returns the value of attribute expires_in.



8
9
10
# File 'lib/kredis/types/scalar.rb', line 8

def expires_in
  @expires_in
end

#typedObject

Returns the value of attribute typed.



8
9
10
# File 'lib/kredis/types/scalar.rb', line 8

def typed
  @typed
end

Instance Method Details

#assigned?Boolean

Returns:

  • (Boolean)


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

def assigned?
  exists?
end

#clearObject



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

def clear
  del
end

#expire_at(datetime) ⇒ Object



40
41
42
# File 'lib/kredis/types/scalar.rb', line 40

def expire_at(datetime)
  expireat datetime.to_i
end

#expire_in(seconds) ⇒ Object



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

def expire_in(seconds)
  expire seconds.to_i
end

#to_sObject



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

def to_s
  get || default&.to_s
end

#valueObject



14
15
16
17
18
19
20
21
22
# File 'lib/kredis/types/scalar.rb', line 14

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



10
11
12
# File 'lib/kredis/types/scalar.rb', line 10

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