@@ -80,6 +80,15 @@ class Cm_Cache_Backend_Redis extends Zend_Cache_Backend implements Zend_Cache_Ba
80
80
/** @var string */
81
81
protected $ _compressionLib ;
82
82
83
+ /**
84
+ * On large data sets SUNION slows down considerably when used with too many arguments
85
+ * so this is used to chunk the SUNION into a few commands where the number of set ids
86
+ * exceeds this setting.
87
+ *
88
+ * @var int
89
+ */
90
+ protected $ _sunionChunkSize = 500 ;
91
+
83
92
/** @var bool */
84
93
protected $ _useLua = false ;
85
94
@@ -177,6 +186,10 @@ public function __construct($options = array())
177
186
}
178
187
$ this ->_compressPrefix = substr ($ this ->_compressionLib ,0 ,2 ).self ::COMPRESS_PREFIX ;
179
188
189
+ if ( isset ($ options ['sunion_chunk_size ' ]) && $ options ['sunion_chunk_size ' ] > 0 ) {
190
+ $ this ->_sunionChunkSize = (int ) $ options ['sunion_chunk_size ' ];
191
+ }
192
+
180
193
if (isset ($ options ['use_lua ' ])) {
181
194
$ this ->_useLua = (bool ) $ options ['use_lua ' ];
182
195
}
@@ -757,10 +770,15 @@ public function getIdsNotMatchingTags($tags = array())
757
770
*/
758
771
public function getIdsMatchingAnyTags ($ tags = array ())
759
772
{
773
+ $ result = array ();
760
774
if ($ tags ) {
761
- return (array ) $ this ->_redis ->sUnion ( $ this ->_preprocessTagIds ($ tags ));
775
+ $ chunks = array_chunk ($ tags , $ this ->_sunionChunkSize );
776
+ foreach ($ chunks as $ chunk ) {
777
+ $ result = array_merge ($ result , (array ) $ this ->_redis ->sUnion ( $ this ->_preprocessTagIds ($ chunk )));
778
+ }
779
+ $ result = array_unique ($ result ); // since we are chunking requests, we must de-duplicate member names
762
780
}
763
- return array () ;
781
+ return $ result ;
764
782
}
765
783
766
784
/**
0 commit comments