41
41
import org .junit .ClassRule ;
42
42
import org .junit .Rule ;
43
43
import org .junit .Test ;
44
+
44
45
import org .springframework .dao .DataAccessException ;
45
46
import org .springframework .dao .InvalidDataAccessApiUsageException ;
46
47
import org .springframework .data .domain .Range .Bound ;
51
52
import org .springframework .data .redis .connection .ClusterConnectionTests ;
52
53
import org .springframework .data .redis .connection .ClusterSlotHashUtil ;
53
54
import org .springframework .data .redis .connection .DataType ;
54
- import org .springframework .data .redis .connection .ReturnType ;
55
55
import org .springframework .data .redis .connection .DefaultSortParameters ;
56
56
import org .springframework .data .redis .connection .DefaultTuple ;
57
57
import org .springframework .data .redis .connection .RedisClusterNode ;
63
63
import org .springframework .data .redis .connection .RedisStringCommands .SetOption ;
64
64
import org .springframework .data .redis .connection .RedisZSetCommands .Range ;
65
65
import org .springframework .data .redis .connection .RedisZSetCommands .Tuple ;
66
+ import org .springframework .data .redis .connection .ReturnType ;
66
67
import org .springframework .data .redis .connection .ValueEncoding .RedisValueEncoding ;
67
68
import org .springframework .data .redis .core .Cursor ;
68
69
import org .springframework .data .redis .core .ScanOptions ;
70
+ import org .springframework .data .redis .core .script .DigestUtils ;
69
71
import org .springframework .data .redis .core .types .Expiration ;
70
72
import org .springframework .data .redis .test .util .HexStringUtils ;
71
73
import org .springframework .data .redis .test .util .MinimumRedisVersionRule ;
72
74
import org .springframework .data .redis .test .util .RedisClusterRule ;
73
75
import org .springframework .test .annotation .IfProfileValue ;
74
- import org .springframework .data .redis .core .script .DigestUtils ;
75
76
76
77
/**
77
78
* @author Christoph Strobl
78
79
* @author Mark Paluch
80
+ * @author Pavel Khokhlov
79
81
*/
80
82
public class JedisClusterConnectionTests implements ClusterConnectionTests {
81
83
@@ -2368,10 +2370,8 @@ public void bitFieldSetShouldWorkCorrectly() {
2368
2370
@ IfProfileValue (name = "redisVersion" , value = "3.2+" )
2369
2371
public void bitFieldGetShouldWorkCorrectly () {
2370
2372
2371
- assertThat (
2372
- clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2373
- create ().get (INT_8 ).valueAt (offset (0L ))),
2374
- contains (0L ));
2373
+ assertThat (clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2374
+ create ().get (INT_8 ).valueAt (offset (0L ))), contains (0L ));
2375
2375
}
2376
2376
2377
2377
@ Test // DATAREDIS-562
@@ -2392,59 +2392,88 @@ public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
2392
2392
create ().incr (unsigned (2 )).valueAt (offset (102L )).overflow (FAIL ).by (1L )), contains (2L ));
2393
2393
assertThat (clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2394
2394
create ().incr (unsigned (2 )).valueAt (offset (102L )).overflow (FAIL ).by (1L )), contains (3L ));
2395
- assertThat (
2396
- clusterConnection .stringCommands ()
2397
- .bitField (JedisConverters .toBytes (KEY_1 ),
2398
- create ().incr (unsigned (2 )).valueAt (offset (102L )).overflow (FAIL ).by (1L ))
2399
- .get (0 ),
2400
- is (nullValue ()));
2395
+ assertThat (clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2396
+ create ().incr (unsigned (2 )).valueAt (offset (102L )).overflow (FAIL ).by (1L )).get (0 ), is (nullValue ()));
2401
2397
}
2402
2398
2403
2399
@ Test // DATAREDIS-562
2404
2400
@ IfProfileValue (name = "redisVersion" , value = "3.2+" )
2405
2401
public void bitfieldShouldAllowMultipleSubcommands () {
2406
2402
2407
- assertThat (
2408
- clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2409
- create ().incr (signed (5 )).valueAt (offset (100L )).by (1L ).get (unsigned (4 )).valueAt (0L )),
2410
- contains (1L , 0L ));
2403
+ assertThat (clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2404
+ create ().incr (signed (5 )).valueAt (offset (100L )).by (1L ).get (unsigned (4 )).valueAt (0L )), contains (1L , 0L ));
2411
2405
}
2412
2406
2413
2407
@ Test // DATAREDIS-562
2414
2408
@ IfProfileValue (name = "redisVersion" , value = "3.2+" )
2415
2409
public void bitfieldShouldWorkUsingNonZeroBasedOffset () {
2416
2410
2417
2411
assertThat (clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ),
2418
- create ().set (INT_8 ).valueAt (offset (0L ).multipliedByTypeLength ())
2419
- .to (100L ).set (INT_8 ).valueAt (offset (1L ).multipliedByTypeLength ()).to (200L )), contains (0L , 0L ));
2412
+ create ().set (INT_8 ).valueAt (offset (0L ).multipliedByTypeLength ()).to (100L ).set (INT_8 )
2413
+ .valueAt (offset (1L ).multipliedByTypeLength ()).to (200L )),
2414
+ contains (0L , 0L ));
2420
2415
assertThat (
2421
- clusterConnection .stringCommands ()
2422
- .bitField (JedisConverters .toBytes (KEY_1 ), create ().get (INT_8 )
2423
- .valueAt (offset (0L ).multipliedByTypeLength ())
2424
- .get (INT_8 ).valueAt (offset (1L ).multipliedByTypeLength ())), contains (100L , -56L ));
2416
+ clusterConnection .stringCommands ().bitField (JedisConverters .toBytes (KEY_1 ), create ().get (INT_8 )
2417
+ .valueAt (offset (0L ).multipliedByTypeLength ()).get (INT_8 ).valueAt (offset (1L ).multipliedByTypeLength ())),
2418
+ contains (100L , -56L ));
2425
2419
}
2426
2420
2427
2421
@ Test // DATAREDIS-1005
2428
2422
@ IfProfileValue (name = "redisVersion" , value = "2.6+" )
2429
- public void evalOK () {
2430
- byte [] keyAndArgs = JedisConverters .toBytes ("FOO" );
2423
+ public void evalShouldRunScript () {
2431
2424
2425
+ byte [] keyAndArgs = JedisConverters .toBytes ("FOO" );
2432
2426
String luaScript = "return redis.call(\" INCR\" , KEYS[1])" ;
2433
2427
byte [] luaScriptBin = JedisConverters .toBytes (luaScript );
2428
+
2434
2429
Long result = clusterConnection .scriptingCommands ().eval (luaScriptBin , ReturnType .VALUE , 1 , keyAndArgs );
2430
+
2435
2431
assertThat (result , is (1L ));
2436
2432
}
2437
2433
2438
2434
@ Test // DATAREDIS-1005
2439
2435
@ IfProfileValue (name = "redisVersion" , value = "2.6+" )
2440
- public void evalShaOK () {
2441
- byte [] keyAndArgs = JedisConverters .toBytes ("FOO" );
2436
+ public void scriptLoadShouldLoadScript () {
2442
2437
2443
2438
String luaScript = "return redis.call(\" INCR\" , KEYS[1])" ;
2444
2439
String digest = DigestUtils .sha1DigestAsHex (luaScript );
2445
- byte [] luaScriptBin = JedisConverters .toBytes (digest );
2446
- Long result = clusterConnection .scriptingCommands ().evalSha (luaScriptBin , ReturnType .VALUE , 1 , keyAndArgs );
2447
- assertThat (result , is (1L ));
2440
+ byte [] luaScriptBin = JedisConverters .toBytes (luaScript );
2441
+
2442
+ String result = clusterConnection .scriptingCommands ().scriptLoad (luaScriptBin );
2443
+
2444
+ assertThat (result , is (digest ));
2448
2445
}
2449
2446
2447
+ @ Test // DATAREDIS-1005
2448
+ @ IfProfileValue (name = "redisVersion" , value = "2.6+" )
2449
+ public void scriptFlushShouldRemoveScripts () {
2450
+
2451
+ byte [] keyAndArgs = JedisConverters .toBytes ("FOO" );
2452
+ String luaScript = "return redis.call(\" GET\" , KEYS[1])" ;
2453
+ byte [] luaScriptBin = JedisConverters .toBytes (luaScript );
2454
+
2455
+ clusterConnection .scriptingCommands ().scriptLoad (luaScriptBin );
2456
+ clusterConnection .scriptingCommands ().scriptFlush ();
2457
+
2458
+ try {
2459
+ clusterConnection .scriptingCommands ().evalSha (luaScriptBin , ReturnType .VALUE , 1 , keyAndArgs );
2460
+ fail ("expected InvalidDataAccessApiUsageException" );
2461
+ } catch (InvalidDataAccessApiUsageException e ) {
2462
+ assertThat (e .getMessage (), containsString ("NOSCRIPT" ));
2463
+ }
2464
+ }
2465
+
2466
+ @ Test // DATAREDIS-1005
2467
+ @ IfProfileValue (name = "redisVersion" , value = "2.6+" )
2468
+ public void evelShaShouldRunScript () {
2469
+
2470
+ byte [] keyAndArgs = JedisConverters .toBytes ("FOO" );
2471
+ String luaScript = "return redis.call(\" INCR\" , KEYS[1])" ;
2472
+ byte [] digest = JedisConverters .toBytes (DigestUtils .sha1DigestAsHex (luaScript ));
2473
+
2474
+ clusterConnection .scriptingCommands ().scriptLoad (JedisConverters .toBytes (luaScript ));
2475
+
2476
+ Long result = clusterConnection .scriptingCommands ().evalSha (digest , ReturnType .VALUE , 1 , keyAndArgs );
2477
+ assertThat (result , is (1L ));
2478
+ }
2450
2479
}
0 commit comments