Class: RedisObj::Set
- Inherits:
-
Base
- Object
- Base
- RedisObj::Set
show all
- Includes:
- Enumerable
- Defined in:
- lib/redis_obj/set.rb
Instance Attribute Summary
Attributes inherited from Base
#key, #redis
Instance Method Summary
collapse
-
#add(val) ⇒ Object
(also: #<<)
-
#add?(val) ⇒ Boolean
-
#delete_if(&blk) ⇒ Object
-
#each(&blk) ⇒ Object
-
#empty? ⇒ Boolean
-
#method_missing(method, *arguments, &blk) ⇒ Object
Allow for non prefixed versions of the commands to be sent as well as making future proof for new versions of redis.
-
#pop ⇒ Object
-
#remove(val) ⇒ Object
-
#remove?(val) ⇒ Boolean
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#scard ⇒ Object
(also: #length, #size, #count)
-
#sdiff(*keys) ⇒ Object
(also: #-, #difference)
-
#sdiffstore(destination, *keys, &blk) ⇒ Object
-
#sinter(*keys) ⇒ Object
(also: #&, #intersection)
-
#sinterstore(destination, *keys, &blk) ⇒ Object
-
#sismember(val) ⇒ Object
(also: #include?)
-
#smembers ⇒ Object
(also: #to_a)
-
#srandmember(num = 1) ⇒ Object
(also: #sample)
-
#sunion(*keys) ⇒ Object
(also: #|, #+)
-
#sunionstore(destination, *keys, &blk) ⇒ Object
Methods inherited from Base
#==, #clear, #del_key, #get_keys, #initialize
Constructor Details
This class inherits a constructor from RedisObj::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &blk) ⇒ Object
Allow for non prefixed versions of the commands to be sent as well as making future proof for new versions of redis
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/redis_obj/set.rb', line 95
def method_missing method, *arguments, &blk
if redis.respond_to?(method)
redis.__send__(method,key,*arguments,&blk)
else
if method.to_s[0] != 's' && (new_method = "s#{method}") && redis.respond_to?(new_method)
self.send(new_method,*arguments,&blk)
else
super
end
end
end
|
Instance Method Details
#add(val) ⇒ Object
Also known as:
<<
52
53
54
55
|
# File 'lib/redis_obj/set.rb', line 52
def add val
redis.sadd(key,val)
self
end
|
#add?(val) ⇒ Boolean
58
59
60
|
# File 'lib/redis_obj/set.rb', line 58
def add? val
redis.sadd(key,val) ? self : nil
end
|
#delete_if(&blk) ⇒ Object
87
88
89
90
91
|
# File 'lib/redis_obj/set.rb', line 87
def delete_if(&blk)
vals_to_delete = select(&blk)
redis.srem(key,vals_to_delete)
vals_to_delete
end
|
#each(&blk) ⇒ Object
9
10
11
|
# File 'lib/redis_obj/set.rb', line 9
def each &blk
to_a.each(&blk)
end
|
#empty? ⇒ Boolean
83
84
85
|
# File 'lib/redis_obj/set.rb', line 83
def empty?
scard == 0
end
|
#pop ⇒ Object
48
49
50
|
# File 'lib/redis_obj/set.rb', line 48
def pop
redis.pop(key)
end
|
#remove(val) ⇒ Object
62
63
64
65
|
# File 'lib/redis_obj/set.rb', line 62
def remove(val)
srem(val)
self
end
|
#remove?(val) ⇒ Boolean
67
68
69
|
# File 'lib/redis_obj/set.rb', line 67
def remove?(val)
srem(val) ? self : nil
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
110
111
112
113
114
|
# File 'lib/redis_obj/set.rb', line 110
def respond_to_missing?(method, include_private = false)
return true if redis.respond_to?(method)
method = method.to_s
method[0] != 's' && redis.respond_to?("s#{method}") or super
end
|
#scard ⇒ Object
Also known as:
length, size, count
76
77
78
|
# File 'lib/redis_obj/set.rb', line 76
def scard
redis.scard(key)
end
|
#sdiff(*keys) ⇒ Object
Also known as:
-, difference
28
29
30
|
# File 'lib/redis_obj/set.rb', line 28
def sdiff *keys
redis.sdiff(key,*get_keys(keys))
end
|
#sdiffstore(destination, *keys, &blk) ⇒ Object
34
35
36
|
# File 'lib/redis_obj/set.rb', line 34
def sdiffstore destination, *keys, &blk
store_block_syntax(:sdiffstore,destination,keys,&blk)
end
|
#sinter(*keys) ⇒ Object
Also known as:
&, intersection
18
19
20
|
# File 'lib/redis_obj/set.rb', line 18
def sinter *keys
redis.sinter(key,*get_keys(keys))
end
|
#sinterstore(destination, *keys, &blk) ⇒ Object
24
25
26
|
# File 'lib/redis_obj/set.rb', line 24
def sinterstore destination, *keys, &blk
store_block_syntax(:sinterstore,destination,keys,&blk)
end
|
#sismember(val) ⇒ Object
Also known as:
include?
13
14
15
|
# File 'lib/redis_obj/set.rb', line 13
def sismember val
redis.sismember(key,val)
end
|
#smembers ⇒ Object
Also known as:
to_a
4
5
6
|
# File 'lib/redis_obj/set.rb', line 4
def smembers
redis.smembers(key)
end
|
#srandmember(num = 1) ⇒ Object
Also known as:
sample
71
72
73
|
# File 'lib/redis_obj/set.rb', line 71
def srandmember num=1
redis.srandmember(key,num)
end
|
#sunion(*keys) ⇒ Object
Also known as:
|, +
38
39
40
|
# File 'lib/redis_obj/set.rb', line 38
def sunion *keys
redis.sunion(key,*get_keys(keys))
end
|
#sunionstore(destination, *keys, &blk) ⇒ Object
44
45
46
|
# File 'lib/redis_obj/set.rb', line 44
def sunionstore destination, *keys, &blk
store_block_syntax(:sunionstore,destination,keys,&blk)
end
|