Class: Familia::String
Instance Attribute Summary
Attributes inherited from DataType
#dump_method, #keystring, #load_method, #opts, #parent
Attributes included from Features
#features_enabled
Instance Method Summary
collapse
Methods inherited from DataType
#class?, #dbclient, #dbkey, #initialize, #logical_database, #parent?, #parent_class?, #parent_instance?, #uri
Methods included from Features
#feature
#has_relations?, #inherited, #logical_database, #register, #uri, #valid_keys_only
#deserialize_value, #deserialize_values, #deserialize_values_with_nil, #serialize_value
#current_expiration, #delete!, #echo, #exists?, #expire, #expireat, #move, #persist, #rename, #renamenx, #type
Methods included from Base
add_feature, #generate_id, #update_expiration, #uuid
Instance Method Details
#append(val) ⇒ Object
Also known as:
<<
77
78
79
80
81
|
# File 'lib/familia/datatype/types/string.rb', line 77
def append(val)
ret = dbclient.append dbkey, val
update_expiration
ret
end
|
#char_count ⇒ Integer
Also known as:
size
Returns the number of elements in the list
9
10
11
|
# File 'lib/familia/datatype/types/string.rb', line 9
def char_count
to_s.size
end
|
#decrement ⇒ Object
Also known as:
decr
63
64
65
66
67
|
# File 'lib/familia/datatype/types/string.rb', line 63
def decrement
ret = dbclient.decr dbkey
update_expiration
ret
end
|
#decrementby(val) ⇒ Object
Also known as:
decrby
70
71
72
73
74
|
# File 'lib/familia/datatype/types/string.rb', line 70
def decrementby(val)
ret = dbclient.decrby dbkey, val.to_i
update_expiration
ret
end
|
#empty? ⇒ Boolean
14
15
16
|
# File 'lib/familia/datatype/types/string.rb', line 14
def empty?
char_count.zero?
end
|
#getbit(offset) ⇒ Object
84
85
86
|
# File 'lib/familia/datatype/types/string.rb', line 84
def getbit(offset)
dbclient.getbit dbkey, offset
end
|
#getrange(spoint, epoint) ⇒ Object
94
95
96
|
# File 'lib/familia/datatype/types/string.rb', line 94
def getrange(spoint, epoint)
dbclient.getrange dbkey, spoint, epoint
end
|
#getset(val) ⇒ Object
104
105
106
107
108
|
# File 'lib/familia/datatype/types/string.rb', line 104
def getset(val)
ret = dbclient.getset dbkey, val
update_expiration
ret
end
|
#increment ⇒ Object
Also known as:
incr
49
50
51
52
53
|
# File 'lib/familia/datatype/types/string.rb', line 49
def increment
ret = dbclient.incr(dbkey)
update_expiration
ret
end
|
#incrementby(val) ⇒ Object
Also known as:
incrby
56
57
58
59
60
|
# File 'lib/familia/datatype/types/string.rb', line 56
def incrementby(val)
ret = dbclient.incrby(dbkey, val.to_i)
update_expiration
ret
end
|
#init ⇒ Object
5
|
# File 'lib/familia/datatype/types/string.rb', line 5
def init; end
|
#nil? ⇒ Boolean
110
111
112
|
# File 'lib/familia/datatype/types/string.rb', line 110
def nil?
value.nil?
end
|
#setbit(offset, val) ⇒ Object
88
89
90
91
92
|
# File 'lib/familia/datatype/types/string.rb', line 88
def setbit(offset, val)
ret = dbclient.setbit dbkey, offset, val
update_expiration
ret
end
|
#setnx(val) ⇒ Object
43
44
45
46
47
|
# File 'lib/familia/datatype/types/string.rb', line 43
def setnx(val)
ret = dbclient.setnx(dbkey, serialize_value(val))
update_expiration
ret
end
|
#setrange(offset, val) ⇒ Object
98
99
100
101
102
|
# File 'lib/familia/datatype/types/string.rb', line 98
def setrange(offset, val)
ret = dbclient.setrange dbkey, offset, val
update_expiration
ret
end
|
#to_i ⇒ Object
31
32
33
|
# File 'lib/familia/datatype/types/string.rb', line 31
def to_i
value&.to_i || 0
end
|
#to_s ⇒ Object
26
27
28
29
|
# File 'lib/familia/datatype/types/string.rb', line 26
def to_s
return super if value.to_s.empty?
value.to_s
end
|
#value ⇒ Object
Also known as:
content, get
18
19
20
21
22
|
# File 'lib/familia/datatype/types/string.rb', line 18
def value
echo :value, caller(0..0) if Familia.debug
dbclient.setnx dbkey, @opts[:default] if @opts[:default]
deserialize_value dbclient.get(dbkey)
end
|
#value=(val) ⇒ Object
Also known as:
replace, set
35
36
37
38
39
|
# File 'lib/familia/datatype/types/string.rb', line 35
def value=(val)
ret = dbclient.set(dbkey, serialize_value(val))
update_expiration
ret
end
|