Method: Redis::SortedSet#intersection
- Defined in:
- lib/redis/sorted_set.rb
#intersection(*sets) ⇒ Object Also known as: intersect, inter, &
Return the intersection with another set. Can pass it either another set object or set name. Also available as & which is a bit cleaner:
members_in_both = set1 & set2
If you want to specify multiple sets, you must use intersection:
members_in_all = set1.intersection(set2, set3, set4)
members_in_all = set1.inter(set2, set3, set4) # alias
Redis: SINTER
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/redis/sorted_set.rb', line 210 def intersection(*sets) result = nil temp_key = :"#{key}:intersection:#{Time.current.to_i + rand}" redis.multi do interstore(temp_key, *sets) redis.expire(temp_key, 1) result = redis.zrange(temp_key, 0, -1) end result.value end |