Skip to content

mtpettyp/jdbc-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

jdbc-redis is an effort to implement the JDBC API for Redis.

Note

Redis isn't a relational database, so jdbc-redis doesn't implement all JDBC API functionality. If a function is not available a SQLFeatureNotSupportedException will be thrown.

Examples

Getting a connection:

Connection connection = DriverManager.getConnection("jdbc:redis://localhost");

The format of the JDBC URL is as follows:

jdbc:redis://<host>:<port>/<db_number>

Setting and Getting a value:

Statement statement = conn.createStatement();

statement.execute("SET my_first_key my_first_value");
statement.execute("GET my_first_key");

ResultSet r = statement.getResultSet();
while(r.next()) {
    System.out.println(">" + r.getString(0) +  "<");
}

conn.commit();
conn.close();

Using a PreparedStatement:

PreparedStatement statement = conn.prepareStatement("set ? ?");

statement.setString(1, "my_key");
statement.setInt(2, 1771);
statement.execute();

ResultSet r = statement.executeQuery("GET my_key");

while(r.next()) {
    System.out.println(">" + r.getString(0) +  "<");
}

r.close();
conn.close();

Compatibility

jdbc-redis is still in beta, and is current being tested against Redis v3.0.

The following is the list of currently supported statements:

Command Implemented
APPEND
AUTH
BGREWRITEAOF
BGSAVE
BITCOUNT
BITFIELD
BITOP
BITPOS
BLPOP
BRPOP
BRPOPLPUSH
CLIENT GETNAME
CLIENT KILL
CLIENT LIST
CLIENT PAUSE
CLIENT REPLY
CLIENT SETNAME
CLUSTER ADDSLOTS
CLUSTER COUNT-FAILURE-REPORTS
CLUSTER COUNTKEYSINSLOT
CLUSTER DELSLOTS
CLUSTER FAILOVER
CLUSTER FORGET
CLUSTER GETKEYSINSLOT
CLUSTER INFO
CLUSTER KEYSLOT
CLUSTER MEET
CLUSTER NODES
CLUSTER REPLICATE
CLUSTER RESET
CLUSTER SAVECONFIG
CLUSTER SET-CONFIG-EPOCH
CLUSTER SETSLOT
CLUSTER SLAVES
CLUSTER SLOTS
COMMAND
COMMAND COUNT
COMMAND GETKEYS
COMMAND INFO
CONFIG GET
CONFIG RESETSTAT
CONFIG REWRITE
CONFIG SET
DBSIZE
DEBUG OBJECT
DEBUG SEGFAULT
DECR
DECRBY
DEL
DISCARD
DUMP
ECHO
EVAL
EVALSHA
EXEC
EXISTS
EXPIRE
EXPIREAT
FLUSHALL
FLUSHDB
GEOADD
GEODIST
GEOHASH
GEOPOS
GEORADIUS
GEORADIUSBYMEMBER
GET
GETBIT
GETRANGE
GETSET
HDEL
HEXISTS
HGET
HGETALL
HINCRBY
HINCRBYFLOAT
HKEYS
HLEN
HMGET
HMSET
HSCAN
HSET
HSETNX
HSTRLEN
HVALS
INCR
INCRBY
INCRBYFLOAT
INFO
KEYS
LASTSAVE
LINDEX
LINSERT
LLEN
LPOP
LPUSH
LPUSHX
LRANGE
LREM
LSET
LTRIM
MGET
MIGRATE
MONITOR
MOVE
MSET
MSETNX
MULTI
OBJECT
PERSIST
PEXPIRE
PEXPIREAT
PFADD
PFCOUNT
PFMERGE
PING
PSETEX
PSUBSCRIBE
PTTL
PUBLISH
PUBSUB
PUNSUBSCRIBE
QUIT
RANDOMKEY
READONLY
READWRITE
RENAME
RENAMENX
RESTORE
ROLE
RPOP
RPOPLPUSH
RPUSH
RPUSHX
SADD
SAVE
SCAN
SCARD
SCRIPT DEBUG
SCRIPT EXISTS
SCRIPT FLUSH
SCRIPT KILL
SCRIPT LOAD
SDIFF
SDIFFSTORE
SELECT
SET
SETBIT
SETEX
SETNX
SETRANGE
SHUTDOWN
SINTER
SINTERSTORE
SISMEMBER
SLAVEOF
SLOWLOG
SMEMBERS
SMOVE
SORT
SPOP
SRANDMEMBER
SREM
SSCAN
STRLEN
SUBSCRIBE
SUNION
SUNIONSTORE
SYNC
TIME
TTL
TYPE
UNSUBSCRIBE
UNWATCH
WAIT
WATCH
ZADD
ZCARD
ZCOUNT
ZINCRBY
ZINTERSTORE
ZLEXCOUNT
ZRANGE
ZRANGEBYLEX
ZRANGEBYSCORE
ZRANK
ZREM
ZREMRANGEBYLEX
ZREMRANGEBYRANK
ZREMRANGEBYSCORE
ZREVRANGE
ZREVRANGEBYLEX
ZREVRANGEBYSCORE
ZREVRANK
ZSCAN
ZSCORE
ZUNIONSTORE

BUILDING

To build jdbc-redis run:

mvn install

To run the tests you should have a running Redis instance on port 6379.

NOTE: These tests should not mess with previous saved data, but it's highly recommended that your Redis instance is a a empty one.

In order to run the jdbc-redis tests against a dockerized version of redis, run

mvn test -Pdocker

COPYRIGHT/LICENSE

Copyright (c) 2009, Marco Valtas All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the JDBC-Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

JDBC driver for Redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages