Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
640e40e4
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,发现更多精彩内容 >>
提交
640e40e4
编写于
12月 17, 2018
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed - RMapCache element expiration doesn't work with map size = 1 #1808
上级
3d3d24b2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
24 deletion
+41
-24
redisson/src/main/java/org/redisson/RedissonMapCache.java
redisson/src/main/java/org/redisson/RedissonMapCache.java
+27
-24
redisson/src/test/java/org/redisson/RedissonMapCacheTest.java
...sson/src/test/java/org/redisson/RedissonMapCacheTest.java
+14
-0
未找到文件。
redisson/src/main/java/org/redisson/RedissonMapCache.java
浏览文件 @
640e40e4
...
...
@@ -360,7 +360,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize >= maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[5]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -390,7 +390,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return val; "
+
"end; "
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
ttlTimeout
,
maxIdleTimeout
,
maxIdleDelta
,
encodeMapKey
(
key
),
encodeMapValue
(
value
));
if
(
hasNoWriter
())
{
return
future
;
...
...
@@ -448,7 +448,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return 0; "
+
"end"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getOptionsName
(
key
)),
getLastAccessTimeSetNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
),
encodeMapValue
(
value
));
}
...
...
@@ -482,7 +482,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" redis.call('zadd', KEYS[4], tonumber(ARGV[1]), ARGV[2]); "
+
"end; "
+
"return val; "
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getOptionsName
(
key
)),
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
));
}
...
...
@@ -526,7 +526,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then"
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1);"
+
" for index, lruItem in ipairs(lruItems) do"
+
" if lruItem then"
+
" if lruItem
and lruItem ~= ARGV[2]
then"
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem);"
+
" redis.call('hdel', KEYS[1], lruItem);"
+
" redis.call('zrem', KEYS[2], lruItem);"
+
...
...
@@ -555,7 +555,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
"redis.call('publish', KEYS[5], msg);"
+
"return val;"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
),
encodeMapValue
(
value
));
}
...
...
@@ -597,7 +597,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[2]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -617,7 +617,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"redis.call('publish', KEYS[4], msg); "
+
"return nil;"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
),
encodeMapValue
(
value
));
}
...
...
@@ -700,7 +700,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[2]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -718,7 +718,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return tostring(newValue); "
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
keyState
,
new
BigDecimal
(
value
.
toString
()).
toPlainString
());
}
...
...
@@ -834,7 +834,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize >= maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[5]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -862,7 +862,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return 0;"
+
"end;"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
ttlTimeout
,
maxIdleTimeout
,
maxIdleDelta
,
encodeMapKey
(
key
),
encodeMapValue
(
value
));
return
future
;
}
...
...
@@ -972,7 +972,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize >= maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[5]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -1004,7 +1004,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return val"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
ttlTimeout
,
maxIdleTimeout
,
maxIdleDelta
,
encodeMapKey
(
key
),
encodeMapValue
(
value
));
return
future
;
}
...
...
@@ -1086,7 +1086,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
return
suffixName
(
getName
(),
"redisson_options"
);
}
String
getOptionsName
(
Object
key
)
{
String
getOptionsName
(
String
name
)
{
return
suffixName
(
name
,
"redisson_options"
);
}
String
getOptionsNameByKey
(
Object
key
)
{
return
suffixName
(
getName
(
key
),
"redisson_options"
);
}
...
...
@@ -1336,7 +1340,6 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
return
(
RFuture
<
MapScanResult
<
Object
,
Object
>>)(
Object
)
f
;
}
@Override
protected
RFuture
<
Boolean
>
fastPutOperationAsync
(
K
key
,
V
value
)
{
return
commandExecutor
.
evalWriteAsync
(
getName
(
key
),
codec
,
RedisCommands
.
EVAL_BOOLEAN
,
...
...
@@ -1375,7 +1378,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[2]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -1402,7 +1405,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"return 0;"
+
"end;"
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getUpdatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
),
encodeMapValue
(
value
));
}
...
...
@@ -1427,7 +1430,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[2]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -1477,7 +1480,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
+
"redis.call('publish', KEYS[4], msg); "
+
"return 1; "
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
encodeMapKey
(
key
),
encodeMapValue
(
value
));
}
...
...
@@ -1573,7 +1576,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize >= maxSize then "
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize); "
+
" for index, lruItem in ipairs(lruItems) do "
+
" if lruItem then "
+
" if lruItem
and lruItem ~= ARGV[5]
then "
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem); "
+
" redis.call('hdel', KEYS[1], lruItem); "
+
" redis.call('zrem', KEYS[2], lruItem); "
+
...
...
@@ -1598,7 +1601,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" return 0; "
+
"end; "
,
Arrays
.<
Object
>
asList
(
getName
(
key
),
getTimeoutSetNameByKey
(
key
),
getIdleSetNameByKey
(
key
),
getCreatedChannelNameByKey
(
key
),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
(
key
)),
getLastAccessTimeSetNameByKey
(
key
),
getRemovedChannelNameByKey
(
key
),
getOptionsName
ByKey
(
key
)),
System
.
currentTimeMillis
(),
ttlTimeout
,
maxIdleTimeout
,
maxIdleDelta
,
encodeMapKey
(
key
),
encodeMapValue
(
value
));
if
(
hasNoWriter
())
{
return
future
;
...
...
@@ -1766,7 +1769,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then"
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1);"
+
" for index, lruItem in ipairs(lruItems) do"
+
" if lruItem then"
+
" if lruItem
and lruItem ~= key
then"
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem);"
+
" redis.call('hdel', KEYS[1], lruItem);"
+
" redis.call('zrem', KEYS[2], lruItem);"
+
...
...
@@ -1865,7 +1868,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
" if cacheSize > maxSize then"
+
" local lruItems = redis.call('zrange', lastAccessTimeSetName, 0, cacheSize - maxSize - 1);"
+
" for index, lruItem in ipairs(lruItems) do"
+
" if lruItem then"
+
" if lruItem
and lruItem ~= key
then"
+
" local lruItemValue = redis.call('hget', KEYS[1], lruItem);"
+
" redis.call('hdel', KEYS[1], lruItem);"
+
" redis.call('zrem', KEYS[2], lruItem);"
+
...
...
redisson/src/test/java/org/redisson/RedissonMapCacheTest.java
浏览文件 @
640e40e4
...
...
@@ -94,6 +94,19 @@ public class RedissonMapCacheTest extends BaseMapTest {
map
.
destroy
();
}
@Test
public
void
testFastPutTTL
()
throws
InterruptedException
{
RMapCache
<
SimpleKey
,
SimpleValue
>
map
=
redisson
.
getMapCache
(
"getAll"
);
map
.
trySetMaxSize
(
1
);
map
.
fastPut
(
new
SimpleKey
(
"1"
),
new
SimpleValue
(
"3"
),
5
,
TimeUnit
.
SECONDS
,
0
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
5000
);
assertThat
(
map
.
get
(
new
SimpleKey
(
"1"
))).
isNull
();
map
.
fastPut
(
new
SimpleKey
(
"1"
),
new
SimpleValue
(
"4"
),
5
,
TimeUnit
.
SECONDS
,
0
,
TimeUnit
.
SECONDS
);
Thread
.
sleep
(
10000
);
assertThat
(
map
.
get
(
new
SimpleKey
(
"1"
))).
isNull
();
}
@Test
public
void
testWriterPutIfAbsentTTL
()
{
Map
<
String
,
String
>
store
=
new
HashMap
<>();
...
...
@@ -179,6 +192,7 @@ public class RedissonMapCacheTest extends BaseMapTest {
assertThat
(
map
.
put
(
"03"
,
"00"
)).
isNull
();
assertThat
(
map
.
fastPutIfAbsent
(
"04"
,
"00"
,
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
map
.
fastPut
(
"1"
,
"11"
,
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
map
.
size
()).
isEqualTo
(
2
);
assertThat
(
map
.
fastPut
(
"2"
,
"22"
,
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
map
.
fastPut
(
"3"
,
"33"
,
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录