Coder Social home page Coder Social logo

s3naid / jedis-mock-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microwww/redis-mock

0.0 0.0 0.0 330 KB

redis server for java, java redis mock

Home Page: https://github.com/microwww/jedis-mock

License: Apache License 2.0

Java 100.00%

jedis-mock-1's Introduction

Redis-server

Pure Java implementation redis-server. Embedded redis service when unit testing. You no longer need to Mock redis apis. Support redis api 2.8

jedis-3.0+ api is changed, so you must update it to 0.1.0-3.0 if you are using the latest api

version 0.2.0 , will remove jedis dependence, There is no need for any external dependencies.

maven dependency

<dependency>
    <groupId>com.github.microwww</groupId>
    <artifactId>redis-server</artifactId>
    <version>0.1.0-3.0</version>
    <scope>test</scope>
</dependency>

Using

    RedisServer server = new RedisServer();
    server.listener("127.0.0.1", 6379); // Redis runs in the background
    InetSocketAddress address = (InetSocketAddress) server.getServerSocket().getLocalSocketAddress();
    logger.info("Redis start :: [{}:{}]", address.getHostName(), address.getPort());

You can set port to 0, server will bind at random port, you can get it by server.getLocalSocketAddress

if you are using spring boot, you can start like this :

    @Bean
    public RedisServer mockRedisServer(RedisProperties redisProperties) throws IOException {
        RedisServer server = new RedisServer();
        server.listener(redisProperties.getHost(), redisProperties.getPort());
        InetSocketAddress address = (InetSocketAddress) server.getServerSocket().getLocalSocketAddress();
        logger.info("Mocker Redis start :: [{}:{}], set 'server.redis.host' to match it", address.getHostName(), address.getPort());
        return server;
    }

server will run with spring config : spring.redis.host, spring.redis.port

Supported commands

Supported redis commands :

ConnectionOperation

AUTH, ECHO, PING, QUIT, SELECT,

HashOperation

HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HLEN, HMGET, HMSET, HSCAN, HSET, HSETNX, HVALS,

KeyOperation

DEL, EXISTS, EXPIRE, EXPIREAT, KEYS, MOVE, PERSIST, PEXPIRE, PEXPIREAT, PTTL, RANDOMKEY, RENAME, RENAMENX, SCAN, SORT, TTL, TYPE, UNLINK<4.0.0+>,

ListOperation

BLPOP, BRPOP, LINDEX, LINSERT, LLEN, LPOP, LPUSH, LPUSHX, LRANGE, LREM, LSET, LTRIM, RPOP, RPOPLPUSH, RPUSH, RPUSHX,

PubSubOperation

ScriptOperation

ServerOperation

DBSIZE, FLUSHALL<ASYNC, 4.0.0+>, FLUSHDB<ASYNC, 4.0.0+>, TIME, 0.0.2+, CLIENT GETNAME, CLIENT KILL, CLIENT LIST, CLIENT SETNAME,

SetOperation

SADD, SCARD, SDIFF, SDIFFSTORE, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SPOP, SRANDMEMBER, SREM, SSCAN, SUNION, SUNIONSTORE,

SortedSetOperation

ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTERSTORE, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNIONSTORE,

StringOperation

APPEND, BITCOUNT, BITOP, DECR, DECRBY, GET, GETBIT, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, MGET, MSET, MSETNX, PSETEX, SET, SETBIT, SETEX, SETNX, SETRANGE, STRLEN,

TransactionOperation

0.0.2+, DISCARD, EXEC, MULTI, UNWATCH, WATCH

Unsupported

If you find unsupported operation, you can add it by yourself, you must implements AbstractOperation add it to server :

server.configScheme(16, new YourOperation1(), ...)

You can add a method, Method signature like this: public void name(RedisRequest request) throws IOException Method name is same as your command, and Method names are all lowercase.

In RedisRequest , you can get RedisServer -> Scheme -> database and so on !

You can create an issue also, I will add it as much as I can.

Good luck !

jedis-mock-1's People

Contributors

lichangshu avatar

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.