Giter VIP home page Giter VIP logo

jedis-mock's People

Contributors

andrewsoares15 avatar bilbo2 avatar bluecontainer avatar bmaggi avatar checkpoint20 avatar davidkus avatar demarna1 avatar dependabot[bot] avatar dev-hanz-ops avatar fppt avatar imanzano avatar inponomarev avatar laymain avatar leonisx avatar mattsheppard avatar mpetricek-corp avatar mwiede avatar patpod avatar randysecrist avatar rheamer avatar sebastien-guay avatar staketd avatar thecrashdown avatar youngasimov avatar zxl0714 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jedis-mock's Issues

Still Supported?

I noticed no commits in over a year. Is this library still supported?

Cluster support

The mock helped us a lot with verifying our new Redis code.
If it's possible to add a mock of Redis in cluster mote it'll help a lot- since we use clusters.
Thanks a lot for this amazing mock

Unsupport operation 'zremrangebyscore'

Hi, Really appreciate what you have done and it really helps me a lot on unit testing.

zrerangebyscore is a basic operation, especially usual for rate limiter.

Could you mind to add this? Thank you very much.

In case of RENAME delete the target key if already present

The current implementation of rename, doesn't delete the values from target key.
This will merge the map result in case of HMAP.
The target key should be delete before renaming

Here is an extract from the doc

If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation

INCR clears TTL

From the Redis docs:

EXPIRE key seconds
Available since 1.0.0.

Time complexity: O(1)

Set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.

The timeout will only be cleared by commands that delete or overwrite the contents of the key, including DEL, SET, GETSET and all the *STORE commands. This means that all the operations that conceptually alter the value stored at the key without replacing it with a new one will leave the timeout untouched. For instance, incrementing the value of a key with INCR, pushing a new value into a list with LPUSH, or altering the field value of a hash with HSET are all operations that will leave the timeout untouched.

Nevertheless, my tests are failing...

        redis = RedisServer.newRedisServer();  // bind to a random port
        redis.start();
        jedis = new Jedis(redis.getHost(), redis.getBindPort());
        jedis.set(REDIS_KEY, "1");
        jedis.expire(REDIS_KEY, REMAINING_TTL);
        assertEquals(REMAINING_TTL, jedis.ttl(REDIS_KEY)); // OK
        jedis.incr(REDIS_KEY);
        assertEquals(REMAINING_TTL, jedis.ttl(REDIS_KEY)); // Got -1

Am I misunderstanding something?

RO_zremrangebyscore#getStartScore does not work for negative scores

"-1".charAt(0) = '-'
AND
java.lang.Character#isDigit('-') = false
==>
ERROR com.github.fppt.jedismock.operations.RO_exec - ERROR during committing transaction
com.github.fppt.jedismock.exception.WrongValueTypeException: Valid start must be a number or start with '(' or be equal to '-inf'
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.getStartScore(RO_zremrangebyscore.java:79) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.response(RO_zremrangebyscore.java:36) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.AbstractRedisOperation.execute(AbstractRedisOperation.java:47) ~[jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.operations.RO_zremrangebyscore.execute(RO_zremrangebyscore.java:18) ~[jedis-mock-0.1.18.jar:?]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) ~[?:?]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[?:?]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[?:?]
at com.github.fppt.jedismock.operations.RO_exec.execute(RO_exec.java:25) [jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:36) [jedis-mock-0.1.18.jar:?]
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54) [jedis-mock-0.1.18.jar:?]

Unsupported operation hgetall/sinter

Hi,
Attempting to use this in a Spring JPA integration test. Seems like most commands are not supported by this mock server.

	at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:135) ~[jedis-mock-0.1.6.jar:na]
	at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:154) ~[jedis-mock-0.1.6.jar:na]
...
java.lang.UnsupportedOperationException: Unsupported operation 'sinter'
	at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:135) ~[jedis-mock-0.1.6.jar:na]
	at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:154) ~[jedis-mock-0.1.6.jar:na]

Unsupported operation 'hlen'

Version: 0.1.15

Sep 27, 2019 6:23:01 PM com.github.fppt.jedismock.server.RedisOperationExecutor execCommand
SEVERE: Malformed request
java.lang.UnsupportedOperationException: Unsupported operation 'hlen'
at com.github.fppt.jedismock.operations.OperationFactory.buildTxOperation(OperationFactory.java:89)
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:39)
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54)
at java.lang.Thread.run(Thread.java:748)

Unsupported operation 'srem'

Add support for srem
Unsupported operation 'srem'; nested exception is redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'srem'

Operation select not implemented.

Trying to migrate a current embedded-redis to jedis-mock and having the error:

redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'select'

Is something that can be added to jedis-mock?

`subscribe` never returns a result

I can break the mock by using subscribe It looks like this should be implemented?

class JedisMockTest {

    private lateinit var redisServer: RedisServer
    private val jedis by lazy { Jedis(redisServer.host, redisServer.bindPort) }

    @Before
    fun setUp() {
        redisServer = RedisServer.newRedisServer()
        redisServer.start()
    }

    @After
    fun tearDown() {
        redisServer.stop()
    }

    @Test
    fun `test redis ping`() {
        val result = jedis.ping("Hello")
        assertEquals("Hello", result)
    }

    @Test
    fun `test pub sub`() {
        val countDownLatch = CountDownLatch(1)
        jedis.subscribe(object : JedisPubSub() {
            override fun onMessage(channel: String?, message: String?) {
                countDownLatch.countDown()
            }
        }, "channel")

//        jedis.publish("channel", "Message")

//        countDownLatch.await()
    }
}

The test will hang forever as it never gets a result from the subscribe call.

Eval operation not supported

I'm using jedis-mock with Redisson. When I call bucket.getAndDelete(), the lib is throwing the following exception:

15:49:42.811 [Thread-41] ERROR c.g.f.j.c.RedisOperationExecutor - Malformed request
java.lang.UnsupportedOperationException: Unsupported operation 'eval'
	at com.github.fppt.jedismock.commands.RedisOperationExecutor.buildSimpleOperation(RedisOperationExecutor.java:148)
	at com.github.fppt.jedismock.commands.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:166)
	at com.github.fppt.jedismock.RedisClient.run(RedisClient.java:48)
	at java.lang.Thread.run(Thread.java:748)

Is eval already supported?

How can I make it work?

SimpleOperationsTest.sscanIterates is sometimes failing (flaky test)

When I try building the mock and running the test, one test case sometimes (in about 40% of the attempts) fails:

sscanIterates(com.github.fppt.jedismock.comparisontests.SimpleOperationsTest)  Time elapsed: 0.007 sec  <<< FAILURE!
org.junit.experimental.theories.internal.ParameterizedAssertionError: sscanIterates("redis.clients.jedis.Jedis@647e447" <from jedis[0]>)
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:834)
        at org.junit.Assert.assertEquals(Assert.java:645)
        at org.junit.Assert.assertEquals(Assert.java:631)
        at com.github.fppt.jedismock.comparisontests.SimpleOperationsTest.sscanIterates(SimpleOperationsTest.java:640)

When trying to use debugger, I found out that the test measures iterations in sscan, expecting it to take 5 iterations with 10 "page" size to fetch 45 elements.

However, sometimes I've seen in the debugger that higher amount of elements are returned per call (between 11 and 13 instead of 10), and as the sscan then completes in only 4 iterations instead of 5, it ends as assertion failure.

Possibly some race condition with other test case modifying default "page" size?

I am using OpenJDK 12 for the build.

Expire does not work as expected when data is set with hset()

Please note that I am not a Redis expert and that all the examples are in Kotlin.

In my application I got simple class to set hash which should expire after a given amount of time.

override fun method(key: String): String {
        return connectionPool.resource.use {
            it.hsetnx(key, HASH_CONST, UUID.randomUUID().toString())
            it.expire(key, EXPIRE_CONST)
            return it.hget(key, HASH_CONST)
        }
    }

I wrote a simple test which calls this method with given ID, then it waits more than the EXPIRE_CONST and then calls this method once again with same ID.

Result of this method should be different but it's the same.

After analyzing code of this library I saw that expire returns 0 instead of 1. I came to conclusion that the problem is Slice.reserved() call in ExpiringKeyValueStorage.java:87. When value is set using hset() the key2 value should be set to hash key value, not the "Reserved String In Jedis Mock".

One solution might be to iterate over hash keys and setting timeout for every one of them.

Cannot flush the db

Cannot flush the db with flushAll()

        Jedis jedis = jedisPool.getResource();
        jedis.flushAll();
        jedis.close();

Unsupported operation 'scard'

Actual:
Unsupported operation 'scard'; nested exception is redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'scard'

Expected:
"scard" operation expected to be work on jedis operation, which is available from redis version: 1.0.0

Incompatible with LettuceClient 6.x - Unsupported operation 'hello'

Hi,

We're attempting to upgrade from v5.3.3.RELEASE of the lettuce redis client to v6.0.1.RELEASE.

When running unit tests with jedis-mock, we have the following exception:

    11:03:02.189 [lettuce-nioEventLoop-40-1] DEBUG io.lettuce.core.AbstractRedisClient - Connecting to Redis at localhost:50385, initialization: localhost:50385
    java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: Unsupported operation 'hello'
        at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
        at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
        at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:943)
        at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
        at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
        at io.lettuce.core.RedisHandshake.lambda$tryHandshakeResp3$1(RedisHandshake.java:105)
        at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
        at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
        at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
        at io.lettuce.core.protocol.AsyncCommand.doCompleteExceptionally(AsyncCommand.java:139)
        at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
        at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
        at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:704)
        at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:639)
        at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:560)

Per readme, submitting an issue. Thanks!

Operation 'hsetnx' not implemented

Hello,

I get following error
Caused by: redis.clients.jedis.exceptions.JedisDataException: Unsupported operation 'hsetnx' at redis.clients.jedis.Protocol.processError(Protocol.java:127) at redis.clients.jedis.Protocol.process(Protocol.java:161) at redis.clients.jedis.Protocol.read(Protocol.java:215) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265) at redis.clients.jedis.BinaryJedis.hsetnx(BinaryJedis.java:870)

Greetings

Unsupported operation 'evalsha'

Caused by: io.lettuce.core.RedisCommandExecutionException: Unsupported operation 'evalsha'
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandWrapper.complete(CommandWrapper.java:59) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:654) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:614) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:565) ~[lettuce-core-5.3.0.RELEASE.jar:5.3.0.RELEASE]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.49.Final.jar:4.1.49.Final]
... 1 more

TTL parameter of SET -cmd is not supported

TTL -related parameters of Redis SET - command are not supported in the RO_set

I encountered this when updating my Spring Boot application to Spring Boot version 2.2.4. This application uses Redis Cache, which used separate Redis SET & EXPIRE commands when storing the item to the cache, but now at Spring Boot (& Spring Data) version 2.2.4 the storing is done using SET cmd with TTL parameter included. And now the jedis-mock can't serve so well in the testing of my microservice cache functionalities.

rpoplpush fails with ParseErrorException

Versions
jedis = 'redis.clients:jedis:3.0.1'
jedisMock = 'com.github.fppt:jedis-mock:0.1.14'

I do

jedis.rpoplpush(queueName, "processing")

I got

Exception in thread "Thread-4" com.github.fppt.jedismock.exception.ParseErrorException
at com.github.fppt.jedismock.server.SliceParser.consumeLong(SliceParser.java:51)
at com.github.fppt.jedismock.server.SliceParser.consumeParameter(SliceParser.java:114)
at com.github.fppt.jedismock.server.SliceParser.consumeParameter(SliceParser.java:127)
at com.github.fppt.jedismock.operations.RO_rpoplpush.response(RO_rpoplpush.java:22)
at com.github.fppt.jedismock.operations.AbstractRedisOperation.execute(AbstractRedisOperation.java:47)
at com.github.fppt.jedismock.server.RedisOperationExecutor.execCommand(RedisOperationExecutor.java:43)
at com.github.fppt.jedismock.server.RedisClient.run(RedisClient.java:54)
at java.lang.Thread.run(Thread.java:748)

java.net.SocketTimeoutException: Read timed out
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:205)
at redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:43)
at redis.clients.jedis.Protocol.process(Protocol.java:154)
at redis.clients.jedis.Protocol.read(Protocol.java:219)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:309)
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:255)
at redis.clients.jedis.Connection.getBulkReply(Connection.java:245)
at redis.clients.jedis.Jedis.rpoplpush(Jedis.java:1195)

debug output shows weird value from get()

Hi,
I'm using embedded redis server in a unit test that increments a counter, and then gets the value using the jedis.get(counterName) command.
All works fine, but the debug output from the jedismock is weird:

It correctly shows expected response from the incr() command (the new value of the counter)
but it prepends "$1" prefix tot he value returned fromt he get() command :) - see examples below:

In this case the correct value of the counter is "5":
10:02:23.126 [Thread-1] DEBUG com.github.fppt.jedismock.Response - Received command [incr] sending reply [:5]
10:02:23.127 [Thread-1] DEBUG com.github.fppt.jedismock.Response - Received command [get] sending reply [$15]

In this case the correct value of the counter is "1":
10:02:23.135 [Thread-3] DEBUG com.github.fppt.jedismock.Response - Received command [incr] sending reply [:1]
10:02:23.136 [Thread-3] DEBUG com.github.fppt.jedismock.Response - Received command [get] sending reply [$11]

Thank you!!!

ConcurrentModificationException when deleting hashes with more than one field

Deleting a hash with more than one field results in a java.util.ConcurrentModificationException.

This is due to the following piece of code in the class ExpiringKeyValueStorage:

public void delete(Slice key) {
        for (Slice key2 : values().row(key).keySet())
            delete(key, key2);
}

public void delete(Slice key1, Slice key2){
    Preconditions.checkNotNull(key1);
    Preconditions.checkNotNull(key2);
    values().remove(key1, key2);
    ttls().remove(key1, key2);
}

The iterator of the row's keySet complains because it is view of the values that get removed with values().remove(key1, key2).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.