http://my.oschina.net/OutOfMemory/blog/300173
当前使用的redis版本
1
2
|
#redis-cli -v
redis-cli
2.6
.
4
|
1
2
3
4
5
6
7
8
9
|
redis
192.168
.
1.53
:
6379
> multi
OK
redis
192.168
.
1.53
:
6379
> incr foo
QUEUED
redis
192.168
.
1.53
:
6379
> set t1
1
QUEUED
redis
192.168
.
1.53
:
6379
> exec
1
) (integer)
2
2
) OK
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
Jedis jedis =
new
Jedis(
"192.168.1.53"
,
6379
);
Transaction tx = jedis.multi();
tx.incr(
"foo"
);
tx.set(
"t1"
,
"2"
);
List
if
(result ==
null
|| result.isEmpty()) {
System. err.println(
"Transaction error..."
);
return
;
}
for
(Object rt : result) {
System. out.println(rt.toString());
}
|
1
2
3
4
5
6
7
8
|
redis
192.168
.
1.53
:
6379
> multi
OK
redis
192.168
.
1.53
:
6379
> incr foo
QUEUED
redis
192.168
.
1.53
:
6379
> set ff
11
22
(error) ERR wrong number of arguments
for
'set'
command
redis
192.168
.
1.53
:
6379
> exec
1
) (integer)
4
|
+++++++++++命令+++++++++++
1
2
3
4
5
6
7
8
9
|
redis
192.168
.
1.53
:
6379
> multi
OK
redis
192.168
.
1.53
:
6379
> set a
11
QUEUED
redis
192.168
.
1.53
:
6379
> lpop a
QUEUED
redis
192.168
.
1.53
:
6379
> exec
1
) OK
2
) (error) ERR Operation against a key holding the wrong kind of value
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
Jedis jedis =
new
Jedis(
"192.168.1.53"
,
6379
);
Transaction tx = jedis.multi();
tx.set(
"t1"
,
"2"
);
tx.lpop(
"t1"
);
List
if
(result ==
null
|| result.isEmpty()) {
System. err.println(
"Transaction error..."
);
return
;
}
for
(Object rt : result) {
System. out.println(rt.toString());
}
|
1
2
3
4
5
6
7
8
9
10
|
redis
192.168
.
1.53
:
6379
> set foo
1
OK
redis
192.168
.
1.53
:
6379
> multi
OK
redis
192.168
.
1.53
:
6379
> incr foo
QUEUED
redis
192.168
.
1.53
:
6379
> discard
OK
redis
192.168
.
1.53
:
6379
> get foo
"1"
|
1
2
3
4
5
6
7
8
|
redis
192.168
.
1.53
:
6379
> watch foo
OK
redis
192.168
.
1.53
:
6379
> set foo
5
OK
redis
192.168
.
1.53
:
6379
> multi
OK
redis
192.168
.
1.53
:
6379
> set foo
9
QUEUED
|
+++++++++++暂停(执行完第二条命令才执行下面的)+++++++++++
1
2
3
4
|
redis
192.168
.
1.53
:
6379
> exec
(nil)
redis
192.168
.
1.53
:
6379
> get foo
"8"
|
+++++++++++第二条命令+++++++++++
1
2
|
redis
192.168
.
1.53
:
6379
> set foo
8
OK
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Jedis jedis =
new
Jedis(
"192.168.1.53"
,
6379
);
jedis.watch(
"foo"
);
Transaction tx = jedis.multi();
tx.incr(
"foo"
);
List
//运行时在这边打断点,然后通过命令行改变foo的值
if
(result ==
null
|| result.isEmpty()) {
System. err.println(
"Transaction error..."
);
return
;
}
for
(Object rt : result) {
System. out.println(rt.toString());
}
|