zoukankan      html  css  js  c++  java
  • redis事务(Transactions)

    redis的事务很简单,他主要目的是保障,一个client发起的事务中的命令可以连续的执行,而中间不会插入其他client的命令。

    看下面例子:

    @Test
    public void test2Trans() {
        Jedis jedis = new Jedis("localhost");
        long start = System.currentTimeMillis();
        Transaction tx = jedis.multi();
        for (int i = 0; i < 100000; i++) {
            tx.set("t" + i, "t" + i);
        }
        List<Object> results = tx.exec();
        long end = System.currentTimeMillis();
        System.out.println("Transaction SET: " + ((end - start)/1000.0) + " seconds");
        jedis.disconnect();
    }

    我们调用jedis.watch(…)方法来监控key,如果调用后key值发生变化,则整个事务会执行失败。另外,事务中某个操作失败,并不会回滚其他操作(好奇怪)。这一点需要注意。还有,我们可以使用discard()方法来取消事务。

  • 相关阅读:
    PHP获取当前页面完整URL的方法
    PHP中常见的提示对照表
    PHP语言中使用JSON和将json还原成数组
    PHP中被定义为false的
    yum
    PHP中计划任务
    command shell 的知识整理
    js的包管理工具bower安装
    Shell脚本
    liunx中计算机壳层
  • 原文地址:https://www.cnblogs.com/lnas01/p/5928077.html
Copyright © 2011-2022 走看看