@@ -84,8 +84,10 @@ public void testExecuteLongResult() {
84
84
this .template = new StringRedisTemplate ();
85
85
template .setConnectionFactory (connFactory );
86
86
template .afterPropertiesSet ();
87
- RedisScript <Long > script = new DefaultRedisScript <Long >(new ClassPathResource (
88
- "org/springframework/data/redis/core/script/increment.lua" ), Long .class );
87
+ DefaultRedisScript <Long > script = new DefaultRedisScript <Long >();
88
+ script .setLocation (new ClassPathResource (
89
+ "org/springframework/data/redis/core/script/increment.lua" ));
90
+ script .setResultType (Long .class );
89
91
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
90
92
Long result = scriptExecutor .execute (script , Collections .singletonList ("mykey" ));
91
93
assertNull (result );
@@ -102,8 +104,10 @@ public void testExecuteBooleanResult() {
102
104
template .setValueSerializer (new GenericToStringSerializer <Long >(Long .class ));
103
105
template .setConnectionFactory (connFactory );
104
106
template .afterPropertiesSet ();
105
- RedisScript <Boolean > script = new DefaultRedisScript <Boolean >(new ClassPathResource (
106
- "org/springframework/data/redis/core/script/cas.lua" ), Boolean .class );
107
+ DefaultRedisScript <Boolean > script = new DefaultRedisScript <Boolean >();
108
+ script .setLocation (new ClassPathResource (
109
+ "org/springframework/data/redis/core/script/cas.lua" ));
110
+ script .setResultType (Boolean .class );
107
111
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
108
112
template .boundValueOps ("counter" ).set (0l );
109
113
Boolean valueSet = scriptExecutor .execute (script , Collections .singletonList ("counter" ), 0 ,
@@ -119,8 +123,10 @@ public void testExecuteListResultCustomArgsSerializer() {
119
123
template .setConnectionFactory (connFactory );
120
124
template .afterPropertiesSet ();
121
125
template .boundListOps ("mylist" ).leftPushAll ("a" , "b" , "c" , "d" );
122
- RedisScript <List <String >> script = new DefaultRedisScript (new ClassPathResource (
123
- "org/springframework/data/redis/core/script/bulkpop.lua" ), List .class );
126
+ DefaultRedisScript <List > script = new DefaultRedisScript <List >();
127
+ script .setLocation (new ClassPathResource (
128
+ "org/springframework/data/redis/core/script/bulkpop.lua" ));
129
+ script .setResultType (List .class );
124
130
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
125
131
List <String > result = scriptExecutor
126
132
.execute (script , new GenericToStringSerializer <Long >(Long .class ),
@@ -134,8 +140,9 @@ public void testExecuteMixedListResult() {
134
140
this .template = new StringRedisTemplate ();
135
141
template .setConnectionFactory (connFactory );
136
142
template .afterPropertiesSet ();
137
- RedisScript <List <Object >> script = new DefaultRedisScript (new ClassPathResource (
138
- "org/springframework/data/redis/core/script/popandlength.lua" ), List .class );
143
+ DefaultRedisScript <List > script = new DefaultRedisScript <List >();
144
+ script .setLocation (new ClassPathResource ("org/springframework/data/redis/core/script/popandlength.lua" ));
145
+ script .setResultType (List .class );
139
146
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
140
147
List <Object > results = scriptExecutor .execute (script , Collections .singletonList ("mylist" ));
141
148
assertEquals (Arrays .asList (new Object [] { null , 0l }), results );
@@ -150,8 +157,9 @@ public void testExecuteValueResult() {
150
157
this .template = new StringRedisTemplate ();
151
158
template .setConnectionFactory (connFactory );
152
159
template .afterPropertiesSet ();
153
- RedisScript <String > script = new DefaultRedisScript <String >(new StaticScriptSource (
154
- "return redis.call('GET',KEYS[1])" ), String .class );
160
+ DefaultRedisScript <String > script = new DefaultRedisScript <String >();
161
+ script .setScriptText ("return redis.call('GET',KEYS[1])" );
162
+ script .setResultType (String .class );
155
163
template .opsForValue ().set ("foo" , "bar" );
156
164
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
157
165
assertEquals ("bar" , scriptExecutor .execute (script , Collections .singletonList ("foo" )));
@@ -165,8 +173,8 @@ public void testExecuteStatusResult() {
165
173
template .setValueSerializer (new GenericToStringSerializer <Long >(Long .class ));
166
174
template .setConnectionFactory (connFactory );
167
175
template .afterPropertiesSet ();
168
- RedisScript script = new DefaultRedisScript (new StaticScriptSource (
169
- "return redis.call('SET',KEYS[1], ARGV[1])" ), null );
176
+ DefaultRedisScript script = new DefaultRedisScript ();
177
+ script . setScriptText ( "return redis.call('SET',KEYS[1], ARGV[1])" );
170
178
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
171
179
assertNull (scriptExecutor .execute (script , Collections .singletonList ("foo" ), 3l ));
172
180
assertEquals (Long .valueOf (3 ), template .opsForValue ().get ("foo" ));
@@ -182,8 +190,10 @@ public void testExecuteCustomResultSerializer() {
182
190
template .setValueSerializer (personSerializer );
183
191
template .setConnectionFactory (connFactory );
184
192
template .afterPropertiesSet ();
185
- RedisScript <String > script = new DefaultRedisScript <String >(new StaticScriptSource (
186
- "redis.call('SET',KEYS[1], ARGV[1])\n return 'FOO'" ), String .class );
193
+ DefaultRedisScript <String > script = new DefaultRedisScript <String >();
194
+ script .setScriptSource (new StaticScriptSource (
195
+ "redis.call('SET',KEYS[1], ARGV[1])\n return 'FOO'" ));
196
+ script .setResultType (String .class );
187
197
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
188
198
Person joe = new Person ("Joe" , "Schmoe" , 23 );
189
199
String result = scriptExecutor .execute (script , personSerializer ,
@@ -198,8 +208,9 @@ public void testExecutePipelined() {
198
208
this .template = new StringRedisTemplate ();
199
209
template .setConnectionFactory (connFactory );
200
210
template .afterPropertiesSet ();
201
- final RedisScript <String > script = new DefaultRedisScript <String >(new StaticScriptSource (
202
- "return KEYS[1]" ), String .class );
211
+ final DefaultRedisScript <String > script = new DefaultRedisScript <String >();
212
+ script .setScriptText ("return KEYS[1]" );
213
+ script .setResultType (String .class );
203
214
List <Object > results = template .executePipelined (new SessionCallback <String >() {
204
215
@ SuppressWarnings ("rawtypes" )
205
216
public String execute (RedisOperations operations ) throws DataAccessException {
@@ -217,8 +228,9 @@ public void testExecuteTx() {
217
228
this .template = new StringRedisTemplate ();
218
229
template .setConnectionFactory (connFactory );
219
230
template .afterPropertiesSet ();
220
- final RedisScript <String > script = new DefaultRedisScript <String >(new StaticScriptSource (
221
- "return 'bar'..KEYS[1]" ), String .class );
231
+ final DefaultRedisScript <String > script = new DefaultRedisScript <String >();
232
+ script .setScriptText ("return 'bar'..KEYS[1]" );
233
+ script .setResultType (String .class );
222
234
List <Object > results = (List <Object >) template .execute (new SessionCallback <List <Object >>() {
223
235
@ SuppressWarnings ("rawtypes" )
224
236
public List <Object > execute (RedisOperations operations ) throws DataAccessException {
@@ -238,8 +250,9 @@ public void testExecuteCachedNullKeys() {
238
250
this .template = new StringRedisTemplate ();
239
251
template .setConnectionFactory (connFactory );
240
252
template .afterPropertiesSet ();
241
- final RedisScript <String > script = new DefaultRedisScript <String >(new StaticScriptSource (
242
- "return 'HELLO'" ), String .class );
253
+ final DefaultRedisScript <String > script = new DefaultRedisScript <String >();
254
+ script .setScriptText ("return 'HELLO'" );
255
+ script .setResultType (String .class );
243
256
ScriptExecutor <String > scriptExecutor = new DefaultScriptExecutor <String >(template );
244
257
// Execute script twice, second time should be from cache
245
258
assertEquals ("HELLO" , scriptExecutor .execute (script , null ));
0 commit comments