24
24
import com .redis .om .spring .serialization .gson .GsonListOfType ;
25
25
import com .redis .om .spring .util .ObjectUtils ;
26
26
import com .redis .om .spring .vectorize .Embedder ;
27
+ import org .slf4j .Logger ;
28
+ import org .slf4j .LoggerFactory ;
27
29
import org .springframework .beans .BeanWrapper ;
28
30
import org .springframework .beans .BeanWrapperImpl ;
29
31
import org .springframework .beans .PropertyAccessor ;
51
53
import org .springframework .util .ReflectionUtils ;
52
54
import redis .clients .jedis .Jedis ;
53
55
import redis .clients .jedis .Pipeline ;
56
+ import redis .clients .jedis .exceptions .JedisDataException ;
54
57
import redis .clients .jedis .json .Path2 ;
55
58
import redis .clients .jedis .search .Query ;
56
59
import redis .clients .jedis .search .SearchResult ;
64
67
import java .nio .file .Paths ;
65
68
import java .util .*;
66
69
import java .util .concurrent .TimeUnit ;
70
+ import java .util .concurrent .atomic .AtomicInteger ;
67
71
import java .util .function .Function ;
68
72
import java .util .stream .Collectors ;
73
+ import java .util .stream .IntStream ;
69
74
import java .util .stream .StreamSupport ;
70
75
71
76
import static com .redis .om .spring .util .ObjectUtils .*;
74
79
public class SimpleRedisDocumentRepository <T , ID > extends SimpleKeyValueRepository <T , ID >
75
80
implements RedisDocumentRepository <T , ID > {
76
81
82
+ private final static Logger logger = LoggerFactory .getLogger (SimpleRedisDocumentRepository .class );
83
+
77
84
protected final RedisModulesOperations <String > modulesOperations ;
78
85
protected final EntityInformation <T , ID > metadata ;
79
86
protected final KeyValueOperations operations ;
@@ -172,6 +179,7 @@ public boolean setExpiration(ID id, Long expiration, TimeUnit timeUnit) {
172
179
public <S extends T > List <S > saveAll (Iterable <S > entities ) {
173
180
Assert .notNull (entities , "The given Iterable of entities must not be null!" );
174
181
List <S > saved = new ArrayList <>();
182
+ List <Object > entityIds = new ArrayList <>();
175
183
176
184
try (Jedis jedis = modulesOperations .client ().getJedis ().get ()) {
177
185
Pipeline pipeline = jedis .pipelined ();
@@ -188,6 +196,8 @@ public <S extends T> List<S> saveAll(Iterable<S> entities) {
188
196
.getProperty (Objects .requireNonNull (keyValueEntity .getIdProperty ()));
189
197
keyValueEntity .getPropertyAccessor (entity ).setProperty (keyValueEntity .getIdProperty (), id );
190
198
199
+ entityIds .add (id );
200
+
191
201
String keyspace = keyValueEntity .getKeySpace ();
192
202
byte [] objectKey = createKey (keyspace , Objects .requireNonNull (id ).toString ());
193
203
@@ -215,7 +225,22 @@ public <S extends T> List<S> saveAll(Iterable<S> entities) {
215
225
216
226
saved .add (entity );
217
227
}
218
- pipeline .sync ();
228
+
229
+ List <Object > responses = pipeline .syncAndReturnAll ();
230
+
231
+ // Process responses using streams to avoid iterator issues
232
+ if (responses != null && !responses .isEmpty ()) {
233
+ long failedCount = IntStream .range (0 , Math .min (responses .size (), entityIds .size ()))
234
+ .filter (i -> responses .get (i ) instanceof JedisDataException )
235
+ .peek (i -> logger .warn ("Failed JSON.SET command for entity with id: {} Error: {}" ,
236
+ entityIds .get (i ),
237
+ ((JedisDataException ) responses .get (i )).getMessage ()))
238
+ .count ();
239
+
240
+ if (failedCount > 0 ) {
241
+ logger .warn ("Total failed JSON.SET commands: {}" , failedCount );
242
+ }
243
+ }
219
244
}
220
245
221
246
return saved ;
0 commit comments