Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/java/com/fiftyonred/mock_jedis/MockJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ public String substr(String key, int start, int end) {

@Override
public Long rpush(String key, String... strings) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
return pipeline.rpush(key, strings).get();
}

@Override
public String ltrim(String key, long start, long end) {
Expand All @@ -830,8 +830,8 @@ public Long lrem(String key, long count, String value) {

@Override
public String rpop(String key) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
return pipeline.rpop(key).get();
}

@Override
public String rpoplpush(String srckey, String dstkey) {
Expand Down Expand Up @@ -905,7 +905,7 @@ public Double zscore(String key, String member) {

@Override
public String watch(String... keys) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
return "test";
}

@Override
Expand Down Expand Up @@ -1515,8 +1515,8 @@ public Double hincrByFloat(byte[] key, byte[] field, double value) {

@Override
public Long rpush(byte[] key, byte[]... strings) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
return pipeline.rpush(key, strings).get();
}

@Override
public String ltrim(byte[] key, long start, long end) {
Expand All @@ -1540,8 +1540,8 @@ public Long lrem(byte[] key, long count, byte[] value) {

@Override
public byte[] rpop(byte[] key) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
return pipeline.rpop(key).get();
}

@Override
public byte[] rpoplpush(byte[] srckey, byte[] dstkey) {
Expand Down Expand Up @@ -1615,7 +1615,7 @@ public Double zscore(byte[] key, byte[] member) {

@Override
public Transaction multi() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
return new MockTransaction(pipeline);
}

@Override
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/fiftyonred/mock_jedis/MockPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,20 @@ public Response<Long> lpush(final byte[] key, final byte[]... string) {
return response;
}

@Override
public Response<Long> rpush(final String key, final String... string) {
final Response<Long> response = new Response<Long>(BuilderFactory.LONG);
response.set((long) mockStorage.rpush(DataContainer.from(key), DataContainer.from(string)));
return response;
}

@Override
public Response<Long> rpush(final byte[] key, final byte[]... string) {
final Response<Long> response = new Response<Long>(BuilderFactory.LONG);
response.set((long) mockStorage.rpush(DataContainer.from(key), DataContainer.from(string)));
return response;
}

@Override
public Response<String> lpop(final String key) {
final Response<String> response = new Response<String>(BuilderFactory.STRING);
Expand All @@ -929,6 +943,22 @@ public Response<byte[]> lpop(final byte[] key) {
return response;
}

@Override
public Response<String> rpop(final String key) {
final Response<String> response = new Response<String>(BuilderFactory.STRING);
final DataContainer result = mockStorage.rpop(DataContainer.from(key));
response.set(result == null ? null : result.getBytes());
return response;
}

@Override
public Response<byte[]> rpop(final byte[] key) {
final Response<byte[]> response = new Response<byte[]>(BuilderFactory.BYTE_ARRAY);
final DataContainer result = mockStorage.rpop(DataContainer.from(key));
response.set(result == null ? null : result.getBytes());
return response;
}

@Override
public Response<Long> llen(final String key) {
final Response<Long> response = new Response<Long>(BuilderFactory.LONG);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/fiftyonred/mock_jedis/MockStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public synchronized long pttl(final DataContainer key) {

public synchronized boolean persist(final DataContainer key) {
final KeyInformation info = keys.get(key);
if (info.getTTL() == -1) {
if (info == null || info.getTTL() == -1) {
return false;
}
info.setExpiration(-1L);
Expand Down Expand Up @@ -555,11 +555,32 @@ public synchronized int lpush(final DataContainer key, final DataContainer... st
return list.size();
}

public synchronized int rpush(final DataContainer key, final DataContainer... string) {
List<DataContainer> list = getListFromStorage(key, true);
if (list == null) {
list = new ArrayList<DataContainer>();
listStorage.put(key, list);
}

List<DataContainer> elems = Arrays.asList(string);
for (int i = elems.size() -1; i > -1; i--) {
DataContainer elem = elems.get(i);
list.add(0, elem);
}

return list.size();
}

public synchronized DataContainer lpop(final DataContainer key) {
final List<DataContainer> list = getListFromStorage(key, true);
return list == null || list.isEmpty() ? null : list.remove(list.size() - 1);
}

public synchronized DataContainer rpop(final DataContainer key) {
final List<DataContainer> list = getListFromStorage(key, true);
return list == null || list.isEmpty() ? null : list.remove(0);
}

public synchronized int llen(final DataContainer key) {
final List<DataContainer> list = getListFromStorage(key, false);
return list == null ? 0 : list.size();
Expand Down
Loading