xsequence分布式序列号生成组件1.1版本发布

1、历史版本

v1.0   支持DB方式生成序列号

文档:https://my.oschina.net/u/1271235/blog/1808103

===========================================================

2、新版本特性说明

v1.1   支持redis方式生成序列号

3、使用教程

(1)API使用方式

public class RedisTest_Api {

    private com.xuanner.seq.sequence.Sequence userSeq;

    @Before
    public void setup() {

        //利用Redis获取区间管理器
        RedisSeqRangeMgr redisSeqRangeMgr = new RedisSeqRangeMgr();
        redisSeqRangeMgr.setIp("xxx");//IP[必选]
        redisSeqRangeMgr.setPort(1234);//PORT[必选]
        redisSeqRangeMgr.setAuth("xxx");//密码[可选]看你的redis服务端配置是否需要密码
        redisSeqRangeMgr.setStep(10);//每次取数步长[可选] 默认:1000
        redisSeqRangeMgr.init();
        //构建序列号生成器
        DefaultRangeSequence defaultRangeSequence = new DefaultRangeSequence();
        defaultRangeSequence.setName("user");
        defaultRangeSequence.setSeqRangeMgr(redisSeqRangeMgr);
        userSeq = defaultRangeSequence;
    }

    @Test
    public void test() {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            System.out.println("++++++++++id:" + userSeq.nextValue());
        }
        System.out.println("interval time:" + (System.currentTimeMillis() - start));
    }

(2)Spring使用方式

xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd" default-autowire="byName"
       default-lazy-init="false">

    <!-- 序列号步长管理器 -->
    <bean id="redisSeqRangeMgr" class="com.xuanner.seq.range.impl.redis.RedisSeqRangeMgr" init-method="init">
        <!-- IP[必选] -->
        <property name="ip" value="xxx"/>
        <!-- PORT[必选]-->
        <property name="port" value="1234"/>
        <!-- 密码[可选]看你的redis服务端配置是否需要密码-->
        <property name="auth" value="xxx"/>
        <!-- 每次取数步长[可选] 默认:1000-->
        <property name="step" value="10"/>
    </bean>

    <!-- 具体使用demo -->
    <bean id="userSeq" class="com.xuanner.seq.sequence.impl.DefaultRangeSequence">
        <property name="seqRangeMgr" ref="redisSeqRangeMgr"/>
        <property name="name" value="user"/>
    </bean>
</beans>

代码使用

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:redis-test.xml" })
public class RedisTest_Spring {

    @Autowired
    private Sequence userSeq;

    @Test
    public void test() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("++++++++++id:" + userSeq.nextValue());
        }
    }

}

转载于:https://my.oschina.net/u/1271235/blog/1809437

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值