Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
696a0005
R
redisson
项目概览
weixin_57962205
/
redisson
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redisson
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
696a0005
编写于
10月 26, 2020
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed - CROSSSLOT error when clearing a redis-spring-data cache #3153
上级
d54f31db
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
437 addition
and
5 deletion
+437
-5
redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-0
redisson-spring-data/redisson-spring-data-17/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java
...spring/data/connection/RedissonClusterConnectionTest.java
+11
-4
redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-1
redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-0
redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-0
redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-0
redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
...son/spring/data/connection/RedissonClusterConnection.java
+71
-0
未找到文件。
redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -27,9 +27,14 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -38,7 +43,10 @@ import org.redisson.client.protocol.RedisCommands;
import
org.redisson.client.protocol.RedisStrictCommand
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.RedisClusterConnection
;
...
...
@@ -440,4 +448,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Red
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
redisson-spring-data/redisson-spring-data-17/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java
浏览文件 @
696a0005
...
...
@@ -21,10 +21,7 @@ import org.springframework.data.redis.connection.RedisNode.NodeType;
import
org.springframework.data.redis.core.types.RedisClientInfo
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.*
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
static
org
.
redisson
.
connection
.
MasterSlaveConnectionManager
.
MAX_SLOT
;
...
...
@@ -181,6 +178,16 @@ public class RedissonClusterConnectionTest {
assertThat
(
info
.
size
()).
isGreaterThan
(
10
);
}
@Test
public
void
testDel
()
{
List
<
byte
[]>
keys
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
byte
[]
key
=
(
"test"
+
i
).
getBytes
();
keys
.
add
(
key
);
connection
.
set
(
key
,
(
"test"
+
i
).
getBytes
());
}
connection
.
del
(
keys
.
toArray
(
new
byte
[
0
][]));
}
@Test
public
void
testResetConfigStats
()
{
...
...
redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -27,9 +27,14 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -38,7 +43,10 @@ import org.redisson.client.protocol.RedisCommands;
import
org.redisson.client.protocol.RedisStrictCommand
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.RedisClusterConnection
;
...
...
@@ -380,7 +388,6 @@ public class RedissonClusterConnection extends RedissonConnection implements Red
@Override
public
void
rename
(
byte
[]
oldName
,
byte
[]
newName
)
{
if
(
isPipelined
())
{
throw
new
InvalidDataAccessResourceUsageException
(
"Clustered rename is not supported in a pipeline"
);
}
...
...
@@ -440,4 +447,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Red
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -26,9 +26,14 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -37,7 +42,10 @@ import org.redisson.client.protocol.RedisCommands;
import
org.redisson.client.protocol.RedisStrictCommand
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.RedisClusterConnection
;
...
...
@@ -444,4 +452,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Red
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -26,10 +26,15 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -39,7 +44,10 @@ import org.redisson.client.protocol.RedisStrictCommand;
import
org.redisson.client.protocol.decoder.ListScanResult
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.DefaultedRedisClusterConnection
;
...
...
@@ -493,4 +501,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Def
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -26,10 +26,15 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -39,7 +44,10 @@ import org.redisson.client.protocol.RedisStrictCommand;
import
org.redisson.client.protocol.decoder.ListScanResult
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.DefaultedRedisClusterConnection
;
...
...
@@ -493,4 +501,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Def
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java
浏览文件 @
696a0005
...
...
@@ -26,10 +26,15 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.BiConsumer
;
import
org.redisson.api.BatchResult
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.client.RedisClient
;
import
org.redisson.client.RedisException
;
import
org.redisson.client.codec.ByteArrayCodec
;
import
org.redisson.client.codec.LongCodec
;
import
org.redisson.client.codec.StringCodec
;
...
...
@@ -39,7 +44,10 @@ import org.redisson.client.protocol.RedisStrictCommand;
import
org.redisson.client.protocol.decoder.ListScanResult
;
import
org.redisson.client.protocol.decoder.ObjectListReplayDecoder
;
import
org.redisson.client.protocol.decoder.StringMapDataDecoder
;
import
org.redisson.command.CommandBatchService
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedissonPromise
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.DefaultedRedisClusterConnection
;
...
...
@@ -493,4 +501,67 @@ public class RedissonClusterConnection extends RedissonConnection implements Def
return
false
;
}
private
void
checkExecution
(
RPromise
<
Long
>
result
,
AtomicReference
<
Throwable
>
failed
,
AtomicLong
count
,
AtomicLong
executed
)
{
if
(
executed
.
decrementAndGet
()
==
0
)
{
if
(
failed
.
get
()
!=
null
)
{
if
(
count
.
get
()
>
0
)
{
RedisException
ex
=
new
RedisException
(
""
+
count
.
get
()
+
" keys has been deleted. But one or more nodes has an error"
,
failed
.
get
());
result
.
tryFailure
(
ex
);
}
else
{
result
.
tryFailure
(
failed
.
get
());
}
}
else
{
result
.
trySuccess
(
count
.
get
());
}
}
}
private
RFuture
<
Long
>
executeAsync
(
RedisStrictCommand
<
Long
>
command
,
byte
[]
...
keys
)
{
Map
<
MasterSlaveEntry
,
List
<
byte
[]>>
range2key
=
new
HashMap
<>();
for
(
byte
[]
key
:
keys
)
{
int
slot
=
executorService
.
getConnectionManager
().
calcSlot
(
key
);
MasterSlaveEntry
entry
=
executorService
.
getConnectionManager
().
getEntry
(
slot
);
List
<
byte
[]>
list
=
range2key
.
computeIfAbsent
(
entry
,
k
->
new
ArrayList
<>());
list
.
add
(
key
);
}
RPromise
<
Long
>
result
=
new
RedissonPromise
<>();
AtomicReference
<
Throwable
>
failed
=
new
AtomicReference
<>();
AtomicLong
count
=
new
AtomicLong
();
AtomicLong
executed
=
new
AtomicLong
(
range2key
.
size
());
BiConsumer
<
BatchResult
<?>,
Throwable
>
listener
=
(
r
,
u
)
->
{
if
(
u
==
null
)
{
List
<
Long
>
result1
=
(
List
<
Long
>)
r
.
getResponses
();
for
(
Long
res
:
result1
)
{
if
(
res
!=
null
)
{
count
.
addAndGet
(
res
);
}
}
}
else
{
failed
.
set
(
u
);
}
checkExecution
(
result
,
failed
,
count
,
executed
);
};
for
(
Entry
<
MasterSlaveEntry
,
List
<
byte
[]>>
entry
:
range2key
.
entrySet
())
{
CommandBatchService
es
=
new
CommandBatchService
(
executorService
.
getConnectionManager
());
for
(
byte
[]
key
:
entry
.
getValue
())
{
es
.
writeAsync
(
entry
.
getKey
(),
null
,
command
,
key
);
}
RFuture
<
BatchResult
<?>>
future
=
es
.
executeAsync
();
future
.
onComplete
(
listener
);
}
return
result
;
}
@Override
public
Long
del
(
byte
[]...
keys
)
{
RFuture
<
Long
>
f
=
executeAsync
(
RedisCommands
.
DEL
,
keys
);
return
sync
(
f
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录