Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
cloudata-keyvalue/src/main/java/com/cloudata/keyvalue/redis/commands/IncrByCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cloudata.keyvalue.redis.commands; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.cloudata.keyvalue.btree.ByteBuffers; | ||
import com.cloudata.keyvalue.btree.operation.IncrementOperation; | ||
import com.cloudata.keyvalue.redis.RedisException; | ||
import com.cloudata.keyvalue.redis.RedisRequest; | ||
import com.cloudata.keyvalue.redis.RedisServer; | ||
import com.cloudata.keyvalue.redis.response.IntegerRedisResponse; | ||
import com.cloudata.keyvalue.redis.response.RedisResponse; | ||
|
||
public class IncrByCommand implements RedisCommand { | ||
private static final Logger log = LoggerFactory.getLogger(IncrByCommand.class); | ||
|
||
@Override | ||
public RedisResponse execute(RedisServer server, RedisRequest command) throws RedisException { | ||
byte[] delta = command.get(2); | ||
|
||
long deltaLong = ByteBuffers.parseLong(ByteBuffer.wrap(delta)); | ||
|
||
return execute(server, command, deltaLong); | ||
} | ||
|
||
protected IntegerRedisResponse execute(RedisServer server, RedisRequest command, long deltaLong) { | ||
byte[] key = command.get(1); | ||
|
||
IncrementOperation operation = new IncrementOperation(deltaLong); | ||
ByteBuffer value = (ByteBuffer) server.getKeyValueStore().doAction(ByteBuffer.wrap(key), operation); | ||
|
||
long v = ByteBuffers.parseLong(value); | ||
return new IntegerRedisResponse(v); | ||
} | ||
} |
16 changes: 2 additions & 14 deletions
16
cloudata-keyvalue/src/main/java/com/cloudata/keyvalue/redis/commands/IncrCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
package com.cloudata.keyvalue.redis.commands; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.cloudata.keyvalue.btree.ByteBuffers; | ||
import com.cloudata.keyvalue.btree.operation.IncrementOperation; | ||
import com.cloudata.keyvalue.btree.operation.KeyOperation; | ||
import com.cloudata.keyvalue.redis.RedisException; | ||
import com.cloudata.keyvalue.redis.RedisRequest; | ||
import com.cloudata.keyvalue.redis.RedisServer; | ||
import com.cloudata.keyvalue.redis.response.IntegerRedisResponse; | ||
import com.cloudata.keyvalue.redis.response.RedisResponse; | ||
|
||
public class IncrCommand implements RedisCommand { | ||
public class IncrCommand extends IncrByCommand { | ||
private static final Logger log = LoggerFactory.getLogger(IncrCommand.class); | ||
|
||
@Override | ||
public RedisResponse execute(RedisServer server, RedisRequest command) throws RedisException { | ||
byte[] key = command.get(1); | ||
|
||
KeyOperation operation = new IncrementOperation(1); | ||
ByteBuffer value = (ByteBuffer) server.getKeyValueStore().doAction(ByteBuffer.wrap(key), operation); | ||
|
||
long v = ByteBuffers.parseLong(value); | ||
return new IntegerRedisResponse(v); | ||
return execute(server, command, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters