1919import java .util .Iterator ;
2020import java .util .Set ;
2121
22+ import org .springframework .data .redis .core .RedisOperations ;
23+
2224/**
2325 * Redis extension for the {@link Set} contract. Supports {@link Set} specific operations backed by Redis operations.
2426 *
2527 * @author Costin Leau
2628 * @author Christoph Strobl
29+ * @author Mark Paluch
2730 */
2831public interface RedisSet <E > extends RedisCollection <E >, Set <E > {
2932
3033 /**
31- * Intersect this set and another {@link RedisSet}.
34+ * Constructs a new {@link RedisSet} instance.
35+ *
36+ * @param key Redis key of this set.
37+ * @param operations {@link RedisOperations} for the value type of this set.
38+ * @since 2.6
39+ */
40+ static <E > RedisSet <E > create (String key , RedisOperations <String , E > operations ) {
41+ return new DefaultRedisSet <>(key , operations );
42+ }
43+
44+ /**
45+ * Diff this set and another {@link RedisSet}.
3246 *
3347 * @param set must not be {@literal null}.
34- * @return a {@link Set} containing the intersecting values.
48+ * @return a {@link Set} containing the values that differ .
3549 * @since 1.0
3650 */
37- Set <E > intersect (RedisSet <?> set );
51+ Set <E > diff (RedisSet <?> set );
3852
3953 /**
40- * Intersect this set and other {@link RedisSet}s.
54+ * Diff this set and other {@link RedisSet}s.
4155 *
4256 * @param sets must not be {@literal null}.
43- * @return a {@link Set} containing the intersecting values.
57+ * @return a {@link Set} containing the values that differ .
4458 * @since 1.0
4559 */
46- Set <E > intersect (Collection <? extends RedisSet <?>> sets );
60+ Set <E > diff (Collection <? extends RedisSet <?>> sets );
4761
4862 /**
49- * Union this set and another {@link RedisSet}.
63+ * Create a new {@link RedisSet} by diffing this sorted set and {@link RedisSet} and store result in destination
64+ * {@code destKey}.
5065 *
5166 * @param set must not be {@literal null}.
52- * @return a {@link Set} containing the combined values.
53- * @since 2.6
67+ * @param destKey must not be {@literal null}.
68+ * @return a new {@link RedisSet} pointing at {@code destKey}.
69+ * @since 1.0
5470 */
55- Set <E > union (RedisSet <?> set );
71+ RedisSet <E > diffAndStore (RedisSet <?> set , String destKey );
5672
5773 /**
58- * Union this set and other {@link RedisSet}s.
74+ * Create a new {@link RedisSet} by diffing this sorted set and the collection {@link RedisSet} and store result in
75+ * destination {@code destKey}.
5976 *
6077 * @param sets must not be {@literal null}.
61- * @return a {@link Set} containing the combined values.
78+ * @param destKey must not be {@literal null}.
79+ * @return a new {@link RedisSet} pointing at {@code destKey}.
6280 * @since 1.0
6381 */
64- Set <E > union (Collection <? extends RedisSet <?>> sets );
82+ RedisSet <E > diffAndStore (Collection <? extends RedisSet <?>> sets , String destKey );
6583
6684 /**
67- * Diff this set and another {@link RedisSet}.
85+ * Intersect this set and another {@link RedisSet}.
6886 *
6987 * @param set must not be {@literal null}.
70- * @return a {@link Set} containing the values that differ .
88+ * @return a {@link Set} containing the intersecting values .
7189 * @since 1.0
7290 */
73- Set <E > diff (RedisSet <?> set );
91+ Set <E > intersect (RedisSet <?> set );
7492
7593 /**
76- * Diff this set and other {@link RedisSet}s.
94+ * Intersect this set and other {@link RedisSet}s.
7795 *
7896 * @param sets must not be {@literal null}.
79- * @return a {@link Set} containing the values that differ .
97+ * @return a {@link Set} containing the intersecting values .
8098 * @since 1.0
8199 */
82- Set <E > diff (Collection <? extends RedisSet <?>> sets );
100+ Set <E > intersect (Collection <? extends RedisSet <?>> sets );
83101
84102 /**
85103 * Create a new {@link RedisSet} by intersecting this sorted set and {@link RedisSet} and store result in destination
@@ -104,60 +122,56 @@ public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
104122 RedisSet <E > intersectAndStore (Collection <? extends RedisSet <?>> sets , String destKey );
105123
106124 /**
107- * Create a new {@link RedisSet} by union this sorted set and {@link RedisSet} and store result in destination
108- * {@code destKey}.
125+ * Get random element from the set.
109126 *
110- * @param set must not be {@literal null}.
111- * @param destKey must not be {@literal null}.
112- * @return a new {@link RedisSet} pointing at {@code destKey}.
113- * @since 1.0
127+ * @return
128+ * @since 2.6
114129 */
115- RedisSet < E > unionAndStore ( RedisSet <?> set , String destKey );
130+ E randomValue ( );
116131
117132 /**
118- * Create a new {@link RedisSet} by union this sorted set and the collection {@link RedisSet} and store result in
119- * destination {@code destKey}.
120- *
121- * @param sets must not be {@literal null}.
122- * @param destKey must not be {@literal null}.
123- * @return a new {@link RedisSet} pointing at {@code destKey}.
124- * @since 1.0
133+ * @since 1.4
134+ * @return
125135 */
126- RedisSet <E > unionAndStore ( Collection <? extends RedisSet <?>> sets , String destKey );
136+ Iterator <E > scan ( );
127137
128138 /**
129- * Get random element from the set .
139+ * Union this set and another {@link RedisSet} .
130140 *
131- * @return
141+ * @param set must not be {@literal null}.
142+ * @return a {@link Set} containing the combined values.
132143 * @since 2.6
133144 */
134- E randomValue ( );
145+ Set < E > union ( RedisSet <?> set );
135146
136147 /**
137- * Create a new {@link RedisSet} by diffing this sorted set and {@link RedisSet} and store result in destination
148+ * Union this set and other {@link RedisSet}s.
149+ *
150+ * @param sets must not be {@literal null}.
151+ * @return a {@link Set} containing the combined values.
152+ * @since 1.0
153+ */
154+ Set <E > union (Collection <? extends RedisSet <?>> sets );
155+
156+ /**
157+ * Create a new {@link RedisSet} by union this sorted set and {@link RedisSet} and store result in destination
138158 * {@code destKey}.
139159 *
140160 * @param set must not be {@literal null}.
141161 * @param destKey must not be {@literal null}.
142162 * @return a new {@link RedisSet} pointing at {@code destKey}.
143163 * @since 1.0
144164 */
145- RedisSet <E > diffAndStore (RedisSet <?> set , String destKey );
165+ RedisSet <E > unionAndStore (RedisSet <?> set , String destKey );
146166
147167 /**
148- * Create a new {@link RedisSet} by diffing this sorted set and the collection {@link RedisSet} and store result in
168+ * Create a new {@link RedisSet} by union this sorted set and the collection {@link RedisSet} and store result in
149169 * destination {@code destKey}.
150170 *
151171 * @param sets must not be {@literal null}.
152172 * @param destKey must not be {@literal null}.
153173 * @return a new {@link RedisSet} pointing at {@code destKey}.
154174 * @since 1.0
155175 */
156- RedisSet <E > diffAndStore (Collection <? extends RedisSet <?>> sets , String destKey );
157-
158- /**
159- * @since 1.4
160- * @return
161- */
162- Iterator <E > scan ();
176+ RedisSet <E > unionAndStore (Collection <? extends RedisSet <?>> sets , String destKey );
163177}
0 commit comments