说明

配置文件参考:https://blog.csdn.net/qq_38428623/article/details/123217001?utm_source=app&app_version=5.1.1&code=app_1562916241&uLinkId=usr1mkqgl919blen

使用
package com.demo.redis.set;

import org.redisson.api.RBitSet;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * RedisBigSet
 *
 * @author 王思勤
 */
@Component
public class RedisBigSet {

    @Resource
    private RedissonClient redissonClient;

    /**
     * 获取 字符串 的 RSet
     *
     * @param name 名称
     * @return 返回 值
     */
    public RBitSet getBitSet(String name) {
        RBitSet bitSet = redissonClient.getBitSet(name);
        Assert.notNull(bitSet, "bitSet is null");
        return bitSet;
    }

    /**
     * 新增 set 数据
     *
     * @param name     名称
     * @param bitIndex bit的索引,值 1/true
     * @return 返回 是否新增成功
     */
    public boolean set(String name, long bitIndex) {
        return this.getBitSet(name).set(bitIndex);
    }

    /**
     * 新增 set 数据
     *
     * @param name      名称
     * @param fromIndex bit的索引,值 1/true
     * @param toIndex   bit的索引,值 1/true
     * @return 返回 是否新增成功
     */
    public void set(String name, long fromIndex, long toIndex) {
        this.getBitSet(name).set(fromIndex, toIndex);
    }

    /**
     * 新增 set 数据
     *
     * @param name      名称
     * @param fromIndex bit的索引
     * @param toIndex   bit的索引
     * @param value   值 1/true
     * @return 返回 是否新增成功
     */
    public void set(String name, long fromIndex, long toIndex, boolean value) {
        this.getBitSet(name).set(fromIndex, toIndex, value);
    }

    /**
     * 读取 set 的数据
     *
     * @param name 名称
     * @param bitIndex bit的索引,值 1/true
     * @return 返回 是否新增成功
     */
    public boolean get(String name, long bitIndex) {
        return this.getBitSet(name).get(bitIndex);
    }

    /**
     * 验证 是否包含
     *
     * @param name  名称
     * @param offset 偏移量
     * @param increment 自增的值
     * @return 返回 是否 包含
     */
    public long incrementAndGetLong(String name, long offset, long increment) {
        return this.getBitSet(name).incrementAndGetLong(offset, increment);
    }

    /**
     * 验证 是否包含
     *
     * @param name   名称
     * @param offset 偏移量
     * @return 返回 是否 包含
     */
    public long getLong(String name, long offset) {
        return this.getBitSet(name).getLong(offset);
    }
}
Logo

更多推荐