当前位置: 首页 > 工具软件 > redis-storage > 使用案例 >

redis----------redis-storage-------------pika

曹成双
2023-12-01

redis:内存级别

redis-storage:内存+磁盘   支持ds_set指令,将数据直接放入磁盘

pika:磁盘  

 

自定义redis-storage使用工具包,添加ds_set,ds_get方法,实质上是redis服务内部支持了DS_GET,DS_SET命令;

自行编写的相关源码参照jedis的源码进行增加了部分源码


CommonCodisPool.class--------------自己编写的class
public String ds_set(byte[] key, byte[] value) {
    Jedis jedis = null;
    try {
        jedis = pool.getResource();
        return jedis.ds_set(key, value);
    } catch (Exception ex) {
        LOGGER.error("Redis异常:{}", ExceptionUtils.getStackTrace(ex));
        throw new RedisException(100, "Redis异常", ex);
    } finally {
        returnResource(jedis);
    }
}
BinaryJedis.class------------参照jedis源码改写【添加部分源码】
public String ds_set(byte[] key, byte[] value) {
    this.checkIsInMultiOrPipeline();
    this.client.ds_set(key, value);
    return this.client.getStatusCodeReply();
}
BinaryClient.class---------参照jedis源码改写【添加部分源码】
public void ds_set(byte[] key, byte[] value) {
//增加DS_SET传输指令,用于直接存方于磁盘上
    this.sendCommand(Command.DS_SET, new byte[][]{key, value});
}
Connection.class
protected Connection sendCommand(Command cmd, byte[]... args) {
    try {
        this.connect();
        Protocol.sendCommand(this.outputStream, cmd, args);
        ++this.pipelinedCommands;
        return this;
    } catch (JedisConnectionException var6) {
        JedisConnectionException ex = var6;

        try {
            String errorMessage = Protocol.readErrorLineIfPossible(this.inputStream);
            if (errorMessage != null && errorMessage.length() > 0) {
                ex = new JedisConnectionException(errorMessage, ex.getCause());
            }
        } catch (Exception var5) {
            ;
        }

        this.broken = true;
        throw ex;
    }
}

 

 

 

 

 类似资料: