1
2
3
4
5 |
List<Integer> list = redisson.getList( "list" ); list.add( 1 ); list.add( 2 ); list.add( 3 ); list.add( 4 ); |
2.支持存储pojo对象,比如要存储一个TestObject,代码是这样的:
1
2 |
List<TestObject> list = redisson.getList( "list" ); list.add( new
TestObject()); |
3.是线程安全的,这也是redisson特别强调的,看一下List的存储逻辑,使用watch,muti,exec保证了数据的一致性。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
public V set( int
index, V element) { checkIndex(index); RedisConnection<String, Object> conn = connectionManager.connection(); try
{ while
( true ) { conn.watch(getName()); V prev = (V) conn.lindex(getName(), index); conn.multi(); conn.lset(getName(), index, element); if
(conn.exec().size() == 1 ) { return
prev; } } } finally
{ connectionManager.release(conn); } } |
缺点:
redisson client 介绍及优缺点,布布扣,bubuko.com
原文:http://www.cnblogs.com/herui/p/3631247.html