Class: Familia::UnsortedSet
- Defined in:
- lib/familia/data_type/types/unsorted_set.rb
Overview
Familia::UnsortedSet
Instance Attribute Summary collapse
-
#features_enabled ⇒ Object
included
from Features
readonly
Returns the value of attribute features_enabled.
- #logical_database(val = nil) ⇒ Object included from DataType::ClassMethods
-
#parent ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute parent.
-
#prefix ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute prefix.
-
#suffix ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute suffix.
-
#uri(val = nil) ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute uri.
Attributes included from Settings
#current_key_version, #default_expiration, #delim, #encryption_keys, #encryption_personalization, #logical_database, #prefix, #schema_path, #schema_validator, #schemas, #suffix, #transaction_mode
Instance Method Summary collapse
- #<<(v) ⇒ Object
- #add(*values) ⇒ Object (also: #add_element)
- #collect ⇒ Object
- #collectraw ⇒ Object
- #each ⇒ Object
- #each_with_index ⇒ Object
- #eachraw ⇒ Object
- #eachraw_with_index ⇒ Object
-
#element_count ⇒ Integer
(also: #size, #length, #count)
Returns the number of elements in the unsorted set.
- #empty? ⇒ Boolean
- #intersection(*setkeys) ⇒ Object
- #member?(val) ⇒ Boolean (also: #include?)
- #members ⇒ Object (also: #all, #to_a)
- #membersraw ⇒ Object
- #move(dstkey, val) ⇒ Object
- #pop ⇒ Object
-
#remove_element(value) ⇒ Integer
(also: #remove)
Removes a member from the set.
-
#sample(count = 1) ⇒ Array
Get one or more random members from the set.
-
#sampleraw(count = 1) ⇒ Array
(also: #random)
Get one or more random members from the set without deserialization.
- #select ⇒ Object
- #selectraw ⇒ Object
Methods included from Features::Autoloader
autoload_files, included, normalize_to_config_name
Methods included from DataType::Serialization
#deserialize_value, #deserialize_values, #deserialize_values_with_nil, #serialize_value
Methods included from DataType::DatabaseCommands
#current_expiration, #delete!, #echo, #exists?, #expire, #expireat, #persist, #rename, #renamenx, #type
Methods included from DataType::Connection
#dbclient, #dbkey, #direct_access, #uri
Methods included from Connection::Behavior
#connect, #create_dbclient, #multi, #normalize_uri, #pipeline, #pipelined, #transaction, #uri=, #url, #url=
Methods included from Settings
#configure, #default_suffix, #pipelined_mode, #pipelined_mode=
Methods included from Base
add_feature, #as_json, #expired?, #expires?, find_feature, #generate_id, #to_json, #to_s, #ttl, #update_expiration, #uuid
Constructor Details
This class inherits a constructor from Familia::DataType
Instance Attribute Details
#features_enabled ⇒ Object (readonly) Originally defined in module Features
Returns the value of attribute features_enabled.
#logical_database(val = nil) ⇒ Object Originally defined in module DataType::ClassMethods
#parent ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute parent.
#prefix ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute prefix.
#suffix ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute suffix.
#uri(val = nil) ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute uri.
Instance Method Details
#<<(v) ⇒ Object
29 30 31 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 29 def <<(v) add v end |
#add(*values) ⇒ Object Also known as: add_element
22 23 24 25 26 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 22 def add *values values.flatten.compact.each { |v| dbclient.sadd? dbkey, serialize_value(v) } update_expiration self end |
#collect ⇒ Object
53 54 55 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 53 def collect(&) members.collect(&) end |
#collectraw ⇒ Object
69 70 71 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 69 def collectraw(&) membersraw.collect(&) end |
#each ⇒ Object
45 46 47 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 45 def each(&) members.each(&) end |
#each_with_index ⇒ Object
49 50 51 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 49 def each_with_index(&) members.each_with_index(&) end |
#eachraw ⇒ Object
61 62 63 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 61 def eachraw(&) membersraw.each(&) end |
#eachraw_with_index ⇒ Object
65 66 67 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 65 def eachraw_with_index(&) membersraw.each_with_index(&) end |
#element_count ⇒ Integer Also known as: size, length, count
Returns the number of elements in the unsorted set
11 12 13 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 11 def element_count dbclient.scard dbkey end |
#empty? ⇒ Boolean
18 19 20 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 18 def empty? element_count.zero? end |
#intersection(*setkeys) ⇒ Object
90 91 92 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 90 def intersection *setkeys # TODO end |
#member?(val) ⇒ Boolean Also known as: include?
77 78 79 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 77 def member?(val) dbclient.sismember dbkey, serialize_value(val) end |
#members ⇒ Object Also known as: all, to_a
33 34 35 36 37 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 33 def members echo :members, Familia.pretty_stack(limit: 1) if Familia.debug elements = membersraw deserialize_values(*elements) end |
#membersraw ⇒ Object
41 42 43 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 41 def membersraw dbclient.smembers(dbkey) end |
#move(dstkey, val) ⇒ Object
98 99 100 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 98 def move(dstkey, val) dbclient.smove dbkey, dstkey, val end |
#pop ⇒ Object
94 95 96 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 94 def pop dbclient.spop dbkey end |
#remove_element(value) ⇒ Integer Also known as: remove
Removes a member from the set
85 86 87 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 85 def remove_element(value) dbclient.srem dbkey, serialize_value(value) end |
#sample(count = 1) ⇒ Array
Get one or more random members from the set
105 106 107 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 105 def sample(count = 1) deserialize_values(*sampleraw(count)) end |
#sampleraw(count = 1) ⇒ Array Also known as: random
Get one or more random members from the set without deserialization
113 114 115 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 113 def sampleraw(count = 1) dbclient.srandmember(dbkey, count) || [] end |
#select ⇒ Object
57 58 59 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 57 def select(&) members.select(&) end |
#selectraw ⇒ Object
73 74 75 |
# File 'lib/familia/data_type/types/unsorted_set.rb', line 73 def selectraw(&) membersraw.select(&) end |