Merge remote-tracking branch 'mindwind/master'
Conflicts: src/main/java/redis/clients/jedis/BinaryClient.java
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,6 +1,11 @@
|
||||
.classpath
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.project
|
||||
.settings/
|
||||
.gradle/
|
||||
target/
|
||||
build/
|
||||
bin/
|
||||
tags
|
||||
|
||||
42
Makefile
Normal file
42
Makefile
Normal file
@@ -0,0 +1,42 @@
|
||||
define REDIS1_CONF
|
||||
daemonize yes
|
||||
port 6379
|
||||
requirepass foobared
|
||||
pidfile /tmp/redis1.pid
|
||||
endef
|
||||
|
||||
define REDIS2_CONF
|
||||
daemonize yes
|
||||
port 6380
|
||||
requirepass foobared
|
||||
pidfile /tmp/redis2.pid
|
||||
endef
|
||||
|
||||
|
||||
define REDIS_SENTINEL1
|
||||
port 26379
|
||||
daemonize yes
|
||||
sentinel monitor mymaster 127.0.0.1 6379 2
|
||||
sentinel auth-pass mymaster foobared
|
||||
sentinel down-after-milliseconds mymaster 5000
|
||||
sentinel failover-timeout mymaster 900000
|
||||
sentinel can-failover mymaster yes
|
||||
sentinel parallel-syncs mymaster 1
|
||||
pidfile /tmp/sentinel1.pid
|
||||
endef
|
||||
|
||||
export REDIS1_CONF
|
||||
export REDIS2_CONF
|
||||
export REDIS_SENTINEL1
|
||||
test:
|
||||
echo "$$REDIS1_CONF" | redis-server -
|
||||
echo "$$REDIS2_CONF" | redis-server -
|
||||
echo "$$REDIS_SENTINEL1" | redis-sentinel -
|
||||
|
||||
mvn clean compile test
|
||||
|
||||
kill `cat /tmp/redis1.pid`
|
||||
kill `cat /tmp/redis2.pid`
|
||||
kill `cat /tmp/sentinel1.pid`
|
||||
|
||||
.PHONY: test
|
||||
27
README.md
27
README.md
@@ -48,20 +48,23 @@ You can download the latest build at:
|
||||
|
||||
Or use it as a maven dependency:
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
To use it just:
|
||||
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
jedis.set("foo", "bar");
|
||||
String value = jedis.get("foo");
|
||||
```java
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
jedis.set("foo", "bar");
|
||||
String value = jedis.get("foo");
|
||||
```
|
||||
|
||||
For more usage examples check the tests.
|
||||
|
||||
@@ -77,7 +80,7 @@ To run the tests:
|
||||
|
||||
- Use the latest redis master branch.
|
||||
|
||||
- Run 2 instances of redis [using conf files in conf folder](https://github.com/xetorthio/jedis/wiki). For the tests we use 2 redis servers, one on default port (6379) and the other one on (6380). Both have authentication enabled with default password (foobared). This way we can test both sharding and auth command.
|
||||
- Run ```make test```. This will run 2 instances of redis. We use 2 redis servers, one on default port (6379) and the other one on (6380). Both have authentication enabled with default password (foobared). This way we can test both sharding and auth command.
|
||||
|
||||
Thanks for helping!
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
group = 'com.googlecode.jedis'
|
||||
archiveBaseName = 'jedis'
|
||||
@@ -25,3 +26,8 @@ uploadArchives {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
task createWrapper(type: Wrapper) {
|
||||
gradleVersion = '1.0-milestone-6'
|
||||
}
|
||||
|
||||
|
||||
332
conf/redis.conf
332
conf/redis.conf
@@ -1,332 +0,0 @@
|
||||
# Redis configuration file example
|
||||
|
||||
# Note on units: when memory size is needed, it is possible to specifiy
|
||||
# it in the usual form of 1k 5GB 4M and so forth:
|
||||
#
|
||||
# 1k => 1000 bytes
|
||||
# 1kb => 1024 bytes
|
||||
# 1m => 1000000 bytes
|
||||
# 1mb => 1024*1024 bytes
|
||||
# 1g => 1000000000 bytes
|
||||
# 1gb => 1024*1024*1024 bytes
|
||||
#
|
||||
# units are case insensitive so 1GB 1Gb 1gB are all the same.
|
||||
|
||||
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
||||
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
||||
daemonize no
|
||||
|
||||
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
|
||||
# default. You can specify a custom pid file location here.
|
||||
pidfile /var/run/redis.pid
|
||||
|
||||
# Accept connections on the specified port, default is 6379
|
||||
port 6379
|
||||
|
||||
# If you want you can bind a single interface, if the bind option is not
|
||||
# specified all the interfaces will listen for incoming connections.
|
||||
#
|
||||
# bind 127.0.0.1
|
||||
|
||||
# Close the connection after a client is idle for N seconds (0 to disable)
|
||||
timeout 300
|
||||
|
||||
# Set server verbosity to 'debug'
|
||||
# it can be one of:
|
||||
# debug (a lot of information, useful for development/testing)
|
||||
# verbose (many rarely useful info, but not a mess like the debug level)
|
||||
# notice (moderately verbose, what you want in production probably)
|
||||
# warning (only very important / critical messages are logged)
|
||||
loglevel verbose
|
||||
|
||||
# Specify the log file name. Also 'stdout' can be used to force
|
||||
# Redis to log on the standard output. Note that if you use standard
|
||||
# output for logging but daemonize, logs will be sent to /dev/null
|
||||
logfile stdout
|
||||
|
||||
# Set the number of databases. The default database is DB 0, you can select
|
||||
# a different one on a per-connection basis using SELECT <dbid> where
|
||||
# dbid is a number between 0 and 'databases'-1
|
||||
databases 16
|
||||
|
||||
################################ SNAPSHOTTING #################################
|
||||
#
|
||||
# Save the DB on disk:
|
||||
#
|
||||
# save <seconds> <changes>
|
||||
#
|
||||
# Will save the DB if both the given number of seconds and the given
|
||||
# number of write operations against the DB occurred.
|
||||
#
|
||||
# In the example below the behaviour will be to save:
|
||||
# after 900 sec (15 min) if at least 1 key changed
|
||||
# after 300 sec (5 min) if at least 10 keys changed
|
||||
# after 60 sec if at least 10000 keys changed
|
||||
#
|
||||
# Note: you can disable saving at all commenting all the "save" lines.
|
||||
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
|
||||
# Compress string objects using LZF when dump .rdb databases?
|
||||
# For default that's set to 'yes' as it's almost always a win.
|
||||
# If you want to save some CPU in the saving child set it to 'no' but
|
||||
# the dataset will likely be bigger if you have compressible values or keys.
|
||||
rdbcompression yes
|
||||
|
||||
# The filename where to dump the DB
|
||||
dbfilename dump.rdb
|
||||
|
||||
# The working directory.
|
||||
#
|
||||
# The DB will be written inside this directory, with the filename specified
|
||||
# above using the 'dbfilename' configuration directive.
|
||||
#
|
||||
# Also the Append Only File will be created inside this directory.
|
||||
#
|
||||
# Note that you must specify a directory here, not a file name.
|
||||
dir ./
|
||||
|
||||
################################# REPLICATION #################################
|
||||
|
||||
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
|
||||
# another Redis server. Note that the configuration is local to the slave
|
||||
# so for example it is possible to configure the slave to save the DB with a
|
||||
# different interval, or to listen to another port, and so on.
|
||||
#
|
||||
# slaveof <masterip> <masterport>
|
||||
|
||||
# If the master is password protected (using the "requirepass" configuration
|
||||
# directive below) it is possible to tell the slave to authenticate before
|
||||
# starting the replication synchronization process, otherwise the master will
|
||||
# refuse the slave request.
|
||||
#
|
||||
# masterauth <master-password>
|
||||
|
||||
################################## SECURITY ###################################
|
||||
|
||||
# Require clients to issue AUTH <PASSWORD> before processing any other
|
||||
# commands. This might be useful in environments in which you do not trust
|
||||
# others with access to the host running redis-server.
|
||||
#
|
||||
# This should stay commented out for backward compatibility and because most
|
||||
# people do not need auth (e.g. they run their own servers).
|
||||
#
|
||||
# Warning: since Redis is pretty fast an outside user can try up to
|
||||
# 150k passwords per second against a good box. This means that you should
|
||||
# use a very strong password otherwise it will be very easy to break.
|
||||
#
|
||||
requirepass foobared
|
||||
|
||||
################################### LIMITS ####################################
|
||||
|
||||
# Set the max number of connected clients at the same time. By default there
|
||||
# is no limit, and it's up to the number of file descriptors the Redis process
|
||||
# is able to open. The special value '0' means no limits.
|
||||
# Once the limit is reached Redis will close all the new connections sending
|
||||
# an error 'max number of clients reached'.
|
||||
#
|
||||
# maxclients 128
|
||||
|
||||
# Don't use more memory than the specified amount of bytes.
|
||||
# When the memory limit is reached Redis will try to remove keys with an
|
||||
# EXPIRE set. It will try to start freeing keys that are going to expire
|
||||
# in little time and preserve keys with a longer time to live.
|
||||
# Redis will also try to remove objects from free lists if possible.
|
||||
#
|
||||
# If all this fails, Redis will start to reply with errors to commands
|
||||
# that will use more memory, like SET, LPUSH, and so on, and will continue
|
||||
# to reply to most read-only commands like GET.
|
||||
#
|
||||
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
|
||||
# 'state' server or cache, not as a real DB. When Redis is used as a real
|
||||
# database the memory usage will grow over the weeks, it will be obvious if
|
||||
# it is going to use too much memory in the long run, and you'll have the time
|
||||
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
||||
# errors for write operations, and this may even lead to DB inconsistency.
|
||||
#
|
||||
# maxmemory <bytes>
|
||||
|
||||
############################## APPEND ONLY MODE ###############################
|
||||
|
||||
# By default Redis asynchronously dumps the dataset on disk. If you can live
|
||||
# with the idea that the latest records will be lost if something like a crash
|
||||
# happens this is the preferred way to run Redis. If instead you care a lot
|
||||
# about your data and don't want to that a single record can get lost you should
|
||||
# enable the append only mode: when this mode is enabled Redis will append
|
||||
# every write operation received in the file appendonly.aof. This file will
|
||||
# be read on startup in order to rebuild the full dataset in memory.
|
||||
#
|
||||
# Note that you can have both the async dumps and the append only file if you
|
||||
# like (you have to comment the "save" statements above to disable the dumps).
|
||||
# Still if append only mode is enabled Redis will load the data from the
|
||||
# log file at startup ignoring the dump.rdb file.
|
||||
#
|
||||
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
|
||||
# log file in background when it gets too big.
|
||||
|
||||
appendonly no
|
||||
|
||||
# The name of the append only file (default: "appendonly.aof")
|
||||
# appendfilename appendonly.aof
|
||||
|
||||
# The fsync() call tells the Operating System to actually write data on disk
|
||||
# instead to wait for more data in the output buffer. Some OS will really flush
|
||||
# data on disk, some other OS will just try to do it ASAP.
|
||||
#
|
||||
# Redis supports three different modes:
|
||||
#
|
||||
# no: don't fsync, just let the OS flush the data when it wants. Faster.
|
||||
# always: fsync after every write to the append only log . Slow, Safest.
|
||||
# everysec: fsync only if one second passed since the last fsync. Compromise.
|
||||
#
|
||||
# The default is "everysec" that's usually the right compromise between
|
||||
# speed and data safety. It's up to you to understand if you can relax this to
|
||||
# "no" that will will let the operating system flush the output buffer when
|
||||
# it wants, for better performances (but if you can live with the idea of
|
||||
# some data loss consider the default persistence mode that's snapshotting),
|
||||
# or on the contrary, use "always" that's very slow but a bit safer than
|
||||
# everysec.
|
||||
#
|
||||
# If unsure, use "everysec".
|
||||
|
||||
# appendfsync always
|
||||
appendfsync everysec
|
||||
# appendfsync no
|
||||
|
||||
# When the AOF fsync policy is set to always or everysec, and a background
|
||||
# saving process (a background save or AOF log background rewriting) is
|
||||
# performing a lot of I/O against the disk, in some Linux configurations
|
||||
# Redis may block too long on the fsync() call. Note that there is no fix for
|
||||
# this currently, as even performing fsync in a different thread will block
|
||||
# our synchronous write(2) call.
|
||||
#
|
||||
# In order to mitigate this problem it's possible to use the following option
|
||||
# that will prevent fsync() from being called in the main process while a
|
||||
# BGSAVE or BGREWRITEAOF is in progress.
|
||||
#
|
||||
# This means that while another child is saving the durability of Redis is
|
||||
# the same as "appendfsync none", that in pratical terms means that it is
|
||||
# possible to lost up to 30 seconds of log in the worst scenario (with the
|
||||
# default Linux settings).
|
||||
#
|
||||
# If you have latency problems turn this to "yes". Otherwise leave it as
|
||||
# "no" that is the safest pick from the point of view of durability.
|
||||
no-appendfsync-on-rewrite no
|
||||
|
||||
################################ VIRTUAL MEMORY ###############################
|
||||
|
||||
# Virtual Memory allows Redis to work with datasets bigger than the actual
|
||||
# amount of RAM needed to hold the whole dataset in memory.
|
||||
# In order to do so very used keys are taken in memory while the other keys
|
||||
# are swapped into a swap file, similarly to what operating systems do
|
||||
# with memory pages.
|
||||
#
|
||||
# To enable VM just set 'vm-enabled' to yes, and set the following three
|
||||
# VM parameters accordingly to your needs.
|
||||
|
||||
vm-enabled no
|
||||
# vm-enabled yes
|
||||
|
||||
# This is the path of the Redis swap file. As you can guess, swap files
|
||||
# can't be shared by different Redis instances, so make sure to use a swap
|
||||
# file for every redis process you are running. Redis will complain if the
|
||||
# swap file is already in use.
|
||||
#
|
||||
# The best kind of storage for the Redis swap file (that's accessed at random)
|
||||
# is a Solid State Disk (SSD).
|
||||
#
|
||||
# *** WARNING *** if you are using a shared hosting the default of putting
|
||||
# the swap file under /tmp is not secure. Create a dir with access granted
|
||||
# only to Redis user and configure Redis to create the swap file there.
|
||||
vm-swap-file /tmp/redis.swap
|
||||
|
||||
# vm-max-memory configures the VM to use at max the specified amount of
|
||||
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
|
||||
# is, if there is still enough contiguous space in the swap file.
|
||||
#
|
||||
# With vm-max-memory 0 the system will swap everything it can. Not a good
|
||||
# default, just specify the max amount of RAM you can in bytes, but it's
|
||||
# better to leave some margin. For instance specify an amount of RAM
|
||||
# that's more or less between 60 and 80% of your free RAM.
|
||||
vm-max-memory 0
|
||||
|
||||
# Redis swap files is split into pages. An object can be saved using multiple
|
||||
# contiguous pages, but pages can't be shared between different objects.
|
||||
# So if your page is too big, small objects swapped out on disk will waste
|
||||
# a lot of space. If you page is too small, there is less space in the swap
|
||||
# file (assuming you configured the same number of total swap file pages).
|
||||
#
|
||||
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
|
||||
# If you use a lot of big objects, use a bigger page size.
|
||||
# If unsure, use the default :)
|
||||
vm-page-size 32
|
||||
|
||||
# Number of total memory pages in the swap file.
|
||||
# Given that the page table (a bitmap of free/used pages) is taken in memory,
|
||||
# every 8 pages on disk will consume 1 byte of RAM.
|
||||
#
|
||||
# The total swap size is vm-page-size * vm-pages
|
||||
#
|
||||
# With the default of 32-bytes memory pages and 134217728 pages Redis will
|
||||
# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
|
||||
#
|
||||
# It's better to use the smallest acceptable value for your application,
|
||||
# but the default is large in order to work in most conditions.
|
||||
vm-pages 134217728
|
||||
|
||||
# Max number of VM I/O threads running at the same time.
|
||||
# This threads are used to read/write data from/to swap file, since they
|
||||
# also encode and decode objects from disk to memory or the reverse, a bigger
|
||||
# number of threads can help with big objects even if they can't help with
|
||||
# I/O itself as the physical device may not be able to couple with many
|
||||
# reads/writes operations at the same time.
|
||||
#
|
||||
# The special value of 0 turn off threaded I/O and enables the blocking
|
||||
# Virtual Memory implementation.
|
||||
vm-max-threads 4
|
||||
|
||||
############################### ADVANCED CONFIG ###############################
|
||||
|
||||
# Glue small output buffers together in order to send small replies in a
|
||||
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
||||
# in terms of number of queries per second. Use 'yes' if unsure.
|
||||
glueoutputbuf yes
|
||||
|
||||
# Hashes are encoded in a special way (much more memory efficient) when they
|
||||
# have at max a given numer of elements, and the biggest element does not
|
||||
# exceed a given threshold. You can configure this limits with the following
|
||||
# configuration directives.
|
||||
hash-max-zipmap-entries 64
|
||||
hash-max-zipmap-value 512
|
||||
|
||||
# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
|
||||
# order to help rehashing the main Redis hash table (the one mapping top-level
|
||||
# keys to values). The hash table implementation redis uses (see dict.c)
|
||||
# performs a lazy rehashing: the more operation you run into an hash table
|
||||
# that is rhashing, the more rehashing "steps" are performed, so if the
|
||||
# server is idle the rehashing is never complete and some more memory is used
|
||||
# by the hash table.
|
||||
#
|
||||
# The default is to use this millisecond 10 times every second in order to
|
||||
# active rehashing the main dictionaries, freeing memory when possible.
|
||||
#
|
||||
# If unsure:
|
||||
# use "activerehashing no" if you have hard latency requirements and it is
|
||||
# not a good thing in your environment that Redis can reply form time to time
|
||||
# to queries with 2 milliseconds delay.
|
||||
#
|
||||
# use "activerehashing yes" if you don't have such hard requirements but
|
||||
# want to free memory asap when possible.
|
||||
activerehashing yes
|
||||
|
||||
################################## INCLUDES ###################################
|
||||
|
||||
# Include one or more other config files here. This is useful if you
|
||||
# have a standard template that goes to all redis server but also need
|
||||
# to customize a few per-server settings. Include files can include
|
||||
# other files, so use this wisely.
|
||||
#
|
||||
# include /path/to/local.conf
|
||||
# include /path/to/other.conf
|
||||
332
conf/redis2.conf
332
conf/redis2.conf
@@ -1,332 +0,0 @@
|
||||
# Redis configuration file example
|
||||
|
||||
# Note on units: when memory size is needed, it is possible to specifiy
|
||||
# it in the usual form of 1k 5GB 4M and so forth:
|
||||
#
|
||||
# 1k => 1000 bytes
|
||||
# 1kb => 1024 bytes
|
||||
# 1m => 1000000 bytes
|
||||
# 1mb => 1024*1024 bytes
|
||||
# 1g => 1000000000 bytes
|
||||
# 1gb => 1024*1024*1024 bytes
|
||||
#
|
||||
# units are case insensitive so 1GB 1Gb 1gB are all the same.
|
||||
|
||||
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
||||
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
||||
daemonize no
|
||||
|
||||
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
|
||||
# default. You can specify a custom pid file location here.
|
||||
pidfile /var/run/redis.pid
|
||||
|
||||
# Accept connections on the specified port, default is 6379
|
||||
port 6380
|
||||
|
||||
# If you want you can bind a single interface, if the bind option is not
|
||||
# specified all the interfaces will listen for incoming connections.
|
||||
#
|
||||
# bind 127.0.0.1
|
||||
|
||||
# Close the connection after a client is idle for N seconds (0 to disable)
|
||||
timeout 300
|
||||
|
||||
# Set server verbosity to 'debug'
|
||||
# it can be one of:
|
||||
# debug (a lot of information, useful for development/testing)
|
||||
# verbose (many rarely useful info, but not a mess like the debug level)
|
||||
# notice (moderately verbose, what you want in production probably)
|
||||
# warning (only very important / critical messages are logged)
|
||||
loglevel verbose
|
||||
|
||||
# Specify the log file name. Also 'stdout' can be used to force
|
||||
# Redis to log on the standard output. Note that if you use standard
|
||||
# output for logging but daemonize, logs will be sent to /dev/null
|
||||
logfile stdout
|
||||
|
||||
# Set the number of databases. The default database is DB 0, you can select
|
||||
# a different one on a per-connection basis using SELECT <dbid> where
|
||||
# dbid is a number between 0 and 'databases'-1
|
||||
databases 16
|
||||
|
||||
################################ SNAPSHOTTING #################################
|
||||
#
|
||||
# Save the DB on disk:
|
||||
#
|
||||
# save <seconds> <changes>
|
||||
#
|
||||
# Will save the DB if both the given number of seconds and the given
|
||||
# number of write operations against the DB occurred.
|
||||
#
|
||||
# In the example below the behaviour will be to save:
|
||||
# after 900 sec (15 min) if at least 1 key changed
|
||||
# after 300 sec (5 min) if at least 10 keys changed
|
||||
# after 60 sec if at least 10000 keys changed
|
||||
#
|
||||
# Note: you can disable saving at all commenting all the "save" lines.
|
||||
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
|
||||
# Compress string objects using LZF when dump .rdb databases?
|
||||
# For default that's set to 'yes' as it's almost always a win.
|
||||
# If you want to save some CPU in the saving child set it to 'no' but
|
||||
# the dataset will likely be bigger if you have compressible values or keys.
|
||||
rdbcompression yes
|
||||
|
||||
# The filename where to dump the DB
|
||||
dbfilename dump.rdb
|
||||
|
||||
# The working directory.
|
||||
#
|
||||
# The DB will be written inside this directory, with the filename specified
|
||||
# above using the 'dbfilename' configuration directive.
|
||||
#
|
||||
# Also the Append Only File will be created inside this directory.
|
||||
#
|
||||
# Note that you must specify a directory here, not a file name.
|
||||
dir ./
|
||||
|
||||
################################# REPLICATION #################################
|
||||
|
||||
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
|
||||
# another Redis server. Note that the configuration is local to the slave
|
||||
# so for example it is possible to configure the slave to save the DB with a
|
||||
# different interval, or to listen to another port, and so on.
|
||||
#
|
||||
# slaveof <masterip> <masterport>
|
||||
|
||||
# If the master is password protected (using the "requirepass" configuration
|
||||
# directive below) it is possible to tell the slave to authenticate before
|
||||
# starting the replication synchronization process, otherwise the master will
|
||||
# refuse the slave request.
|
||||
#
|
||||
# masterauth <master-password>
|
||||
|
||||
################################## SECURITY ###################################
|
||||
|
||||
# Require clients to issue AUTH <PASSWORD> before processing any other
|
||||
# commands. This might be useful in environments in which you do not trust
|
||||
# others with access to the host running redis-server.
|
||||
#
|
||||
# This should stay commented out for backward compatibility and because most
|
||||
# people do not need auth (e.g. they run their own servers).
|
||||
#
|
||||
# Warning: since Redis is pretty fast an outside user can try up to
|
||||
# 150k passwords per second against a good box. This means that you should
|
||||
# use a very strong password otherwise it will be very easy to break.
|
||||
#
|
||||
requirepass foobared
|
||||
|
||||
################################### LIMITS ####################################
|
||||
|
||||
# Set the max number of connected clients at the same time. By default there
|
||||
# is no limit, and it's up to the number of file descriptors the Redis process
|
||||
# is able to open. The special value '0' means no limits.
|
||||
# Once the limit is reached Redis will close all the new connections sending
|
||||
# an error 'max number of clients reached'.
|
||||
#
|
||||
# maxclients 128
|
||||
|
||||
# Don't use more memory than the specified amount of bytes.
|
||||
# When the memory limit is reached Redis will try to remove keys with an
|
||||
# EXPIRE set. It will try to start freeing keys that are going to expire
|
||||
# in little time and preserve keys with a longer time to live.
|
||||
# Redis will also try to remove objects from free lists if possible.
|
||||
#
|
||||
# If all this fails, Redis will start to reply with errors to commands
|
||||
# that will use more memory, like SET, LPUSH, and so on, and will continue
|
||||
# to reply to most read-only commands like GET.
|
||||
#
|
||||
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
|
||||
# 'state' server or cache, not as a real DB. When Redis is used as a real
|
||||
# database the memory usage will grow over the weeks, it will be obvious if
|
||||
# it is going to use too much memory in the long run, and you'll have the time
|
||||
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
||||
# errors for write operations, and this may even lead to DB inconsistency.
|
||||
#
|
||||
# maxmemory <bytes>
|
||||
|
||||
############################## APPEND ONLY MODE ###############################
|
||||
|
||||
# By default Redis asynchronously dumps the dataset on disk. If you can live
|
||||
# with the idea that the latest records will be lost if something like a crash
|
||||
# happens this is the preferred way to run Redis. If instead you care a lot
|
||||
# about your data and don't want to that a single record can get lost you should
|
||||
# enable the append only mode: when this mode is enabled Redis will append
|
||||
# every write operation received in the file appendonly.aof. This file will
|
||||
# be read on startup in order to rebuild the full dataset in memory.
|
||||
#
|
||||
# Note that you can have both the async dumps and the append only file if you
|
||||
# like (you have to comment the "save" statements above to disable the dumps).
|
||||
# Still if append only mode is enabled Redis will load the data from the
|
||||
# log file at startup ignoring the dump.rdb file.
|
||||
#
|
||||
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
|
||||
# log file in background when it gets too big.
|
||||
|
||||
appendonly no
|
||||
|
||||
# The name of the append only file (default: "appendonly.aof")
|
||||
# appendfilename appendonly.aof
|
||||
|
||||
# The fsync() call tells the Operating System to actually write data on disk
|
||||
# instead to wait for more data in the output buffer. Some OS will really flush
|
||||
# data on disk, some other OS will just try to do it ASAP.
|
||||
#
|
||||
# Redis supports three different modes:
|
||||
#
|
||||
# no: don't fsync, just let the OS flush the data when it wants. Faster.
|
||||
# always: fsync after every write to the append only log . Slow, Safest.
|
||||
# everysec: fsync only if one second passed since the last fsync. Compromise.
|
||||
#
|
||||
# The default is "everysec" that's usually the right compromise between
|
||||
# speed and data safety. It's up to you to understand if you can relax this to
|
||||
# "no" that will will let the operating system flush the output buffer when
|
||||
# it wants, for better performances (but if you can live with the idea of
|
||||
# some data loss consider the default persistence mode that's snapshotting),
|
||||
# or on the contrary, use "always" that's very slow but a bit safer than
|
||||
# everysec.
|
||||
#
|
||||
# If unsure, use "everysec".
|
||||
|
||||
# appendfsync always
|
||||
appendfsync everysec
|
||||
# appendfsync no
|
||||
|
||||
# When the AOF fsync policy is set to always or everysec, and a background
|
||||
# saving process (a background save or AOF log background rewriting) is
|
||||
# performing a lot of I/O against the disk, in some Linux configurations
|
||||
# Redis may block too long on the fsync() call. Note that there is no fix for
|
||||
# this currently, as even performing fsync in a different thread will block
|
||||
# our synchronous write(2) call.
|
||||
#
|
||||
# In order to mitigate this problem it's possible to use the following option
|
||||
# that will prevent fsync() from being called in the main process while a
|
||||
# BGSAVE or BGREWRITEAOF is in progress.
|
||||
#
|
||||
# This means that while another child is saving the durability of Redis is
|
||||
# the same as "appendfsync none", that in pratical terms means that it is
|
||||
# possible to lost up to 30 seconds of log in the worst scenario (with the
|
||||
# default Linux settings).
|
||||
#
|
||||
# If you have latency problems turn this to "yes". Otherwise leave it as
|
||||
# "no" that is the safest pick from the point of view of durability.
|
||||
no-appendfsync-on-rewrite no
|
||||
|
||||
################################ VIRTUAL MEMORY ###############################
|
||||
|
||||
# Virtual Memory allows Redis to work with datasets bigger than the actual
|
||||
# amount of RAM needed to hold the whole dataset in memory.
|
||||
# In order to do so very used keys are taken in memory while the other keys
|
||||
# are swapped into a swap file, similarly to what operating systems do
|
||||
# with memory pages.
|
||||
#
|
||||
# To enable VM just set 'vm-enabled' to yes, and set the following three
|
||||
# VM parameters accordingly to your needs.
|
||||
|
||||
vm-enabled no
|
||||
# vm-enabled yes
|
||||
|
||||
# This is the path of the Redis swap file. As you can guess, swap files
|
||||
# can't be shared by different Redis instances, so make sure to use a swap
|
||||
# file for every redis process you are running. Redis will complain if the
|
||||
# swap file is already in use.
|
||||
#
|
||||
# The best kind of storage for the Redis swap file (that's accessed at random)
|
||||
# is a Solid State Disk (SSD).
|
||||
#
|
||||
# *** WARNING *** if you are using a shared hosting the default of putting
|
||||
# the swap file under /tmp is not secure. Create a dir with access granted
|
||||
# only to Redis user and configure Redis to create the swap file there.
|
||||
vm-swap-file /tmp/redis.swap
|
||||
|
||||
# vm-max-memory configures the VM to use at max the specified amount of
|
||||
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
|
||||
# is, if there is still enough contiguous space in the swap file.
|
||||
#
|
||||
# With vm-max-memory 0 the system will swap everything it can. Not a good
|
||||
# default, just specify the max amount of RAM you can in bytes, but it's
|
||||
# better to leave some margin. For instance specify an amount of RAM
|
||||
# that's more or less between 60 and 80% of your free RAM.
|
||||
vm-max-memory 0
|
||||
|
||||
# Redis swap files is split into pages. An object can be saved using multiple
|
||||
# contiguous pages, but pages can't be shared between different objects.
|
||||
# So if your page is too big, small objects swapped out on disk will waste
|
||||
# a lot of space. If you page is too small, there is less space in the swap
|
||||
# file (assuming you configured the same number of total swap file pages).
|
||||
#
|
||||
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
|
||||
# If you use a lot of big objects, use a bigger page size.
|
||||
# If unsure, use the default :)
|
||||
vm-page-size 32
|
||||
|
||||
# Number of total memory pages in the swap file.
|
||||
# Given that the page table (a bitmap of free/used pages) is taken in memory,
|
||||
# every 8 pages on disk will consume 1 byte of RAM.
|
||||
#
|
||||
# The total swap size is vm-page-size * vm-pages
|
||||
#
|
||||
# With the default of 32-bytes memory pages and 134217728 pages Redis will
|
||||
# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
|
||||
#
|
||||
# It's better to use the smallest acceptable value for your application,
|
||||
# but the default is large in order to work in most conditions.
|
||||
vm-pages 134217728
|
||||
|
||||
# Max number of VM I/O threads running at the same time.
|
||||
# This threads are used to read/write data from/to swap file, since they
|
||||
# also encode and decode objects from disk to memory or the reverse, a bigger
|
||||
# number of threads can help with big objects even if they can't help with
|
||||
# I/O itself as the physical device may not be able to couple with many
|
||||
# reads/writes operations at the same time.
|
||||
#
|
||||
# The special value of 0 turn off threaded I/O and enables the blocking
|
||||
# Virtual Memory implementation.
|
||||
vm-max-threads 4
|
||||
|
||||
############################### ADVANCED CONFIG ###############################
|
||||
|
||||
# Glue small output buffers together in order to send small replies in a
|
||||
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
||||
# in terms of number of queries per second. Use 'yes' if unsure.
|
||||
glueoutputbuf yes
|
||||
|
||||
# Hashes are encoded in a special way (much more memory efficient) when they
|
||||
# have at max a given numer of elements, and the biggest element does not
|
||||
# exceed a given threshold. You can configure this limits with the following
|
||||
# configuration directives.
|
||||
hash-max-zipmap-entries 64
|
||||
hash-max-zipmap-value 512
|
||||
|
||||
# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
|
||||
# order to help rehashing the main Redis hash table (the one mapping top-level
|
||||
# keys to values). The hash table implementation redis uses (see dict.c)
|
||||
# performs a lazy rehashing: the more operation you run into an hash table
|
||||
# that is rhashing, the more rehashing "steps" are performed, so if the
|
||||
# server is idle the rehashing is never complete and some more memory is used
|
||||
# by the hash table.
|
||||
#
|
||||
# The default is to use this millisecond 10 times every second in order to
|
||||
# active rehashing the main dictionaries, freeing memory when possible.
|
||||
#
|
||||
# If unsure:
|
||||
# use "activerehashing no" if you have hard latency requirements and it is
|
||||
# not a good thing in your environment that Redis can reply form time to time
|
||||
# to queries with 2 milliseconds delay.
|
||||
#
|
||||
# use "activerehashing yes" if you don't have such hard requirements but
|
||||
# want to free memory asap when possible.
|
||||
activerehashing yes
|
||||
|
||||
################################## INCLUDES ###################################
|
||||
|
||||
# Include one or more other config files here. This is useful if you
|
||||
# have a standard template that goes to all redis server but also need
|
||||
# to customize a few per-server settings. Include files can include
|
||||
# other files, so use this wisely.
|
||||
#
|
||||
# include /path/to/local.conf
|
||||
# include /path/to/other.conf
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
7
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,9 +1,6 @@
|
||||
#Mon Jan 18 09:35:53 CET 2010
|
||||
#Fri Dec 23 12:54:50 CST 2011
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
distributionVersion=0.9-preview-3
|
||||
zipStorePath=wrapper/dists
|
||||
urlRoot=http\://dist.codehaus.org/gradle/
|
||||
distributionName=gradle
|
||||
distributionClassifier=bin
|
||||
distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-6-bin.zip
|
||||
|
||||
40
gradlew
vendored
40
gradlew
vendored
@@ -7,21 +7,25 @@
|
||||
##############################################################################
|
||||
|
||||
# Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
|
||||
GRADLE_OPTS="$GRADLE_OPTS -Xmx1024m"
|
||||
# JAVA_OPTS="$JAVA_OPTS -Xmx512"
|
||||
# GRADLE_OPTS="$GRADLE_OPTS -Xmx512m"
|
||||
# JAVA_OPTS="$JAVA_OPTS -Xmx512m"
|
||||
|
||||
GRADLE_APP_NAME=Gradle
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "${PROGNAME}: $*"
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
warn "$*"
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
@@ -79,12 +83,31 @@ if [ -z "$JAVACMD" ] ; then
|
||||
fi
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "JAVA_HOME is not defined correctly, can not execute: $JAVACMD"
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
warn "JAVA_HOME environment variable is not set"
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add GRADLE_APP_NAME to the JAVA_OPTS as -Xdock:name
|
||||
if $darwin; then
|
||||
JAVA_OPTS="$JAVA_OPTS -Xdock:name=$GRADLE_APP_NAME"
|
||||
@@ -135,8 +158,11 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
"$JAVACMD" $JAVA_OPTS $GRADLE_OPTS \
|
||||
GRADLE_APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
exec "$JAVACMD" $JAVA_OPTS $GRADLE_OPTS \
|
||||
-classpath "$CLASSPATH" \
|
||||
-Dorg.gradle.appname="$GRADLE_APP_BASE_NAME" \
|
||||
-Dorg.gradle.wrapper.properties="$WRAPPER_PROPERTIES" \
|
||||
$STARTER_MAIN_CLASS \
|
||||
"$@"
|
||||
|
||||
64
gradlew.bat
vendored
64
gradlew.bat
vendored
@@ -5,83 +5,39 @@
|
||||
@rem ##
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem
|
||||
@rem $Revision: 10602 $ $Date: 2008-01-25 02:49:54 +0100 (ven., 25 janv. 2008) $
|
||||
@rem
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
|
||||
@rem set GRADLE_OPTS=%GRADLE_OPTS% -Xmx512
|
||||
@rem set JAVA_OPTS=%JAVA_OPTS% -Xmx512
|
||||
@rem set GRADLE_OPTS=%GRADLE_OPTS% -Xmx512m
|
||||
@rem set JAVA_OPTS=%JAVA_OPTS% -Xmx512m
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.\
|
||||
|
||||
@rem Determine the command interpreter to execute the "CD" later
|
||||
set COMMAND_COM="cmd.exe"
|
||||
if exist "%SystemRoot%\system32\cmd.exe" set COMMAND_COM="%SystemRoot%\system32\cmd.exe"
|
||||
if exist "%SystemRoot%\command.com" set COMMAND_COM="%SystemRoot%\command.com"
|
||||
@rem Find java.exe
|
||||
set JAVA_EXE=java.exe
|
||||
if not defined JAVA_HOME goto init
|
||||
|
||||
@rem Use explicit find.exe to prevent cygwin and others find.exe from being used
|
||||
set FIND_EXE="find.exe"
|
||||
if exist "%SystemRoot%\system32\find.exe" set FIND_EXE="%SystemRoot%\system32\find.exe"
|
||||
if exist "%SystemRoot%\command\find.exe" set FIND_EXE="%SystemRoot%\command\find.exe"
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
:check_JAVA_HOME
|
||||
@rem Make sure we have a valid JAVA_HOME
|
||||
if not "%JAVA_HOME%" == "" goto have_JAVA_HOME
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: Environment variable JAVA_HOME has not been set.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo.
|
||||
goto end
|
||||
|
||||
:have_JAVA_HOME
|
||||
@rem Validate JAVA_HOME
|
||||
%COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul
|
||||
if not errorlevel 1 goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME might be set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation if there are problems.
|
||||
echo.
|
||||
|
||||
:init
|
||||
@rem get name of script to launch with full path
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
SET _marker=%JAVA_HOME: =%
|
||||
@rem IF NOT "%_marker%" == "%JAVA_HOME%" ECHO JAVA_HOME "%JAVA_HOME%" contains spaces. Please change to a location without spaces if this causes problems.
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
IF "%_marker%" == "%JAVA_HOME%" goto :win9xME_args
|
||||
|
||||
set _FIXPATH=
|
||||
call :fixpath "%JAVA_HOME%"
|
||||
set JAVA_HOME=%_FIXPATH:~1%
|
||||
|
||||
goto win9xME_args
|
||||
|
||||
:fixpath
|
||||
if not %1.==. (
|
||||
for /f "tokens=1* delims=;" %%a in (%1) do (
|
||||
call :shortfilename "%%a" & call :fixpath "%%b"
|
||||
)
|
||||
)
|
||||
goto :EOF
|
||||
:shortfilename
|
||||
for %%i in (%1) do set _FIXPATH=%_FIXPATH%;%%~fsi
|
||||
goto :EOF
|
||||
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
@@ -103,10 +59,10 @@ set CMD_LINE_ARGS=%$
|
||||
set STARTER_MAIN_CLASS=org.gradle.wrapper.GradleWrapperMain
|
||||
set CLASSPATH=%DIRNAME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set WRAPPER_PROPERTIES=%DIRNAME%\gradle\wrapper\gradle-wrapper.properties
|
||||
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
|
||||
|
||||
set GRADLE_OPTS=%JAVA_OPTS% %GRADLE_OPTS% -Dorg.gradle.wrapper.properties="%WRAPPER_PROPERTIES%"
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %GRADLE_OPTS% -classpath "%CLASSPATH%" %STARTER_MAIN_CLASS% %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
|
||||
23
pom.xml
23
pom.xml
@@ -3,17 +3,17 @@
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>5</version>
|
||||
<version>7</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
<name>Jedis</name>
|
||||
<description>Jedis is a blazingly small and sane Redis java client.</description>
|
||||
<url>http://code.google.com/p/jedis/</url>
|
||||
<url>https://github.com/xetorthio/jedis</url>
|
||||
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Jedis License</name>
|
||||
<name>MIT</name>
|
||||
<url>http://github.com/xetorthio/jedis/raw/master/LICENSE.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
@@ -38,11 +38,11 @@
|
||||
<url>http://github.com/xetorthio/jedis/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<scm>
|
||||
<url>http://github.com/xetorthio/jedis</url>
|
||||
<connection>scm:git:git@github.com:xetorthio/jedis.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:xetorthio/jedis.git</developerConnection>
|
||||
</scm>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:xetorthio/jedis.git</connection>
|
||||
<url>scm:git:git@github.com:xetorthio/jedis.git</url>
|
||||
<developerConnection>scm:git:git@github.com:xetorthio/jedis.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<redis-hosts>localhost:6379,localhost:6380</redis-hosts>
|
||||
@@ -102,6 +102,11 @@
|
||||
<aggregate>true</aggregate>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.0-beta-9</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdvancedBinaryJedisCommands {
|
||||
|
||||
List<byte[]> configGet(byte[] pattern);
|
||||
|
||||
byte[] configSet(byte[] parameter, byte[] value);
|
||||
|
||||
String slowlogReset();
|
||||
|
||||
Long slowlogLen();
|
||||
|
||||
List<byte[]> slowlogGetBinary();
|
||||
|
||||
List<byte[]> slowlogGetBinary(long entries);
|
||||
|
||||
Long objectRefcount(byte[] key);
|
||||
|
||||
byte[] objectEncoding(byte[] key);
|
||||
|
||||
Long objectIdletime(byte[] key);
|
||||
}
|
||||
26
src/main/java/redis/clients/jedis/AdvancedJedisCommands.java
Normal file
26
src/main/java/redis/clients/jedis/AdvancedJedisCommands.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface AdvancedJedisCommands {
|
||||
List<String> configGet(String pattern);
|
||||
|
||||
String configSet(String parameter, String value);
|
||||
|
||||
String slowlogReset();
|
||||
|
||||
Long slowlogLen();
|
||||
|
||||
List<Slowlog> slowlogGet();
|
||||
|
||||
List<Slowlog> slowlogGet(long entries);
|
||||
|
||||
Long objectRefcount(String string);
|
||||
|
||||
String objectEncoding(String string);
|
||||
|
||||
Long objectIdletime(String string);
|
||||
}
|
||||
42
src/main/java/redis/clients/jedis/BasicCommands.java
Normal file
42
src/main/java/redis/clients/jedis/BasicCommands.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public interface BasicCommands {
|
||||
|
||||
String ping();
|
||||
|
||||
String quit();
|
||||
|
||||
String flushDB();
|
||||
|
||||
Long dbSize();
|
||||
|
||||
String select(int index);
|
||||
|
||||
String flushAll();
|
||||
|
||||
String auth(String password);
|
||||
|
||||
String save();
|
||||
|
||||
String bgsave();
|
||||
|
||||
String bgrewriteaof();
|
||||
|
||||
Long lastsave();
|
||||
|
||||
String shutdown();
|
||||
|
||||
String info();
|
||||
|
||||
String info(String section);
|
||||
|
||||
String slaveof(String host, int port);
|
||||
|
||||
String slaveofNoOne();
|
||||
|
||||
Long getDB();
|
||||
|
||||
String debug(DebugParams params);
|
||||
|
||||
String configResetStat();
|
||||
}
|
||||
38
src/main/java/redis/clients/jedis/BasicRedisPipeline.java
Normal file
38
src/main/java/redis/clients/jedis/BasicRedisPipeline.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Pipelined responses for all of the low level, non key related commands
|
||||
*/
|
||||
public interface BasicRedisPipeline {
|
||||
|
||||
Response<String> bgrewriteaof();
|
||||
|
||||
Response<String> bgsave();
|
||||
|
||||
Response<String> configGet(String pattern);
|
||||
|
||||
Response<String> configSet(String parameter, String value);
|
||||
|
||||
Response<String> configResetStat();
|
||||
|
||||
Response<String> save();
|
||||
|
||||
Response<Long> lastsave();
|
||||
|
||||
Response<String> flushDB();
|
||||
|
||||
Response<String> flushAll();
|
||||
|
||||
Response<String> info();
|
||||
|
||||
Response<Long> dbSize();
|
||||
|
||||
Response<String> shutdown();
|
||||
|
||||
Response<String> ping();
|
||||
|
||||
Response<String> select(int index);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,8 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Boolean exists(byte[] key);
|
||||
|
||||
Long persist(byte[] key);
|
||||
|
||||
String type(byte[] key);
|
||||
|
||||
Long expire(byte[] key, int seconds);
|
||||
@@ -25,6 +27,16 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Long ttl(byte[] key);
|
||||
|
||||
Boolean setbit(byte[] key, long offset, boolean value);
|
||||
|
||||
Boolean setbit(byte[] key, long offset, byte[] value);
|
||||
|
||||
Boolean getbit(byte[] key, long offset);
|
||||
|
||||
Long setrange(byte[] key, long offset, byte[] value);
|
||||
|
||||
byte[] getrange(byte[] key, long startOffset, long endOffset);
|
||||
|
||||
byte[] getSet(byte[] key, byte[] value);
|
||||
|
||||
Long setnx(byte[] key, byte[] value);
|
||||
@@ -57,7 +69,7 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Boolean hexists(byte[] key, byte[] field);
|
||||
|
||||
Long hdel(byte[] key, byte[] field);
|
||||
Long hdel(byte[] key, byte[]... field);
|
||||
|
||||
Long hlen(byte[] key);
|
||||
|
||||
@@ -67,31 +79,31 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Map<byte[], byte[]> hgetAll(byte[] key);
|
||||
|
||||
Long rpush(byte[] key, byte[] string);
|
||||
Long rpush(byte[] key, byte[]... args);
|
||||
|
||||
Long lpush(byte[] key, byte[] string);
|
||||
Long lpush(byte[] key, byte[]... args);
|
||||
|
||||
Long llen(byte[] key);
|
||||
|
||||
List<byte[]> lrange(byte[] key, int start, int end);
|
||||
List<byte[]> lrange(byte[] key, long start, long end);
|
||||
|
||||
String ltrim(byte[] key, int start, int end);
|
||||
String ltrim(byte[] key, long start, long end);
|
||||
|
||||
byte[] lindex(byte[] key, int index);
|
||||
byte[] lindex(byte[] key, long index);
|
||||
|
||||
String lset(byte[] key, int index, byte[] value);
|
||||
String lset(byte[] key, long index, byte[] value);
|
||||
|
||||
Long lrem(byte[] key, int count, byte[] value);
|
||||
Long lrem(byte[] key, long count, byte[] value);
|
||||
|
||||
byte[] lpop(byte[] key);
|
||||
|
||||
byte[] rpop(byte[] key);
|
||||
|
||||
Long sadd(byte[] key, byte[] member);
|
||||
Long sadd(byte[] key, byte[]... member);
|
||||
|
||||
Set<byte[]> smembers(byte[] key);
|
||||
|
||||
Long srem(byte[] key, byte[] member);
|
||||
Long srem(byte[] key, byte[]... member);
|
||||
|
||||
byte[] spop(byte[] key);
|
||||
|
||||
@@ -101,11 +113,15 @@ public interface BinaryJedisCommands {
|
||||
|
||||
byte[] srandmember(byte[] key);
|
||||
|
||||
Long strlen(byte[] key);
|
||||
|
||||
Long zadd(byte[] key, double score, byte[] member);
|
||||
|
||||
Long zadd(byte[] key, Map<Double, byte[]> scoreMembers);
|
||||
|
||||
Set<byte[]> zrange(byte[] key, int start, int end);
|
||||
Set<byte[]> zrange(byte[] key, long start, long end);
|
||||
|
||||
Long zrem(byte[] key, byte[] member);
|
||||
Long zrem(byte[] key, byte[]... member);
|
||||
|
||||
Double zincrby(byte[] key, double score, byte[] member);
|
||||
|
||||
@@ -113,11 +129,11 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Long zrevrank(byte[] key, byte[] member);
|
||||
|
||||
Set<byte[]> zrevrange(byte[] key, int start, int end);
|
||||
Set<byte[]> zrevrange(byte[] key, long start, long end);
|
||||
|
||||
Set<Tuple> zrangeWithScores(byte[] key, int start, int end);
|
||||
Set<Tuple> zrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end);
|
||||
Set<Tuple> zrevrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
Long zcard(byte[] key);
|
||||
|
||||
@@ -129,29 +145,72 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Long zcount(byte[] key, double min, double max);
|
||||
|
||||
Long zcount(byte[] key, byte[] min, byte[] max);
|
||||
|
||||
Set<byte[]> zrangeByScore(byte[] key, double min, double max);
|
||||
|
||||
Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
|
||||
int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
|
||||
int offset, int count);
|
||||
Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset,
|
||||
Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
|
||||
int count);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min);
|
||||
|
||||
Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset,
|
||||
int count);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
|
||||
int offset, int count);
|
||||
|
||||
Long zremrangeByRank(byte[] key, int start, int end);
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min,
|
||||
int offset, int count);
|
||||
|
||||
Long zremrangeByRank(byte[] key, long start, long end);
|
||||
|
||||
Long zremrangeByScore(byte[] key, double start, double end);
|
||||
|
||||
Long zremrangeByScore(byte[] key, byte[] start, byte[] end);
|
||||
|
||||
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
|
||||
Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot,
|
||||
byte[] value);
|
||||
|
||||
Long lpushx(byte[] key, byte[]... arg);
|
||||
|
||||
Long rpushx(byte[] key, byte[]... arg);
|
||||
|
||||
List<byte[]> blpop(byte[] arg);
|
||||
|
||||
List<byte[]> brpop(byte[] arg);
|
||||
|
||||
Long del(byte[] key);
|
||||
|
||||
byte[] echo(byte[] arg);
|
||||
|
||||
Long move(byte[] key, int dbIndex);
|
||||
|
||||
Long bitcount(final byte[] key);
|
||||
|
||||
Long bitcount(final byte[] key, long start, long end);
|
||||
}
|
||||
|
||||
219
src/main/java/redis/clients/jedis/BinaryRedisPipeline.java
Normal file
219
src/main/java/redis/clients/jedis/BinaryRedisPipeline.java
Normal file
@@ -0,0 +1,219 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author guy
|
||||
*/
|
||||
public interface BinaryRedisPipeline {
|
||||
Response<Long> append(byte[] key, byte[] value);
|
||||
|
||||
Response<List<byte[]>> blpop(byte[] arg);
|
||||
|
||||
Response<List<byte[]>> brpop(byte[] arg);
|
||||
|
||||
Response<Long> decr(byte[] key);
|
||||
|
||||
Response<Long> decrBy(byte[] key, long integer);
|
||||
|
||||
Response<Long> del(byte[] keys);
|
||||
|
||||
Response<byte[]> echo(byte[] string);
|
||||
|
||||
Response<Boolean> exists(byte[] key);
|
||||
|
||||
Response<Long> expire(byte[] key, int seconds);
|
||||
|
||||
Response<Long> expireAt(byte[] key, long unixTime);
|
||||
|
||||
Response<byte[]> get(byte[] key);
|
||||
|
||||
Response<Boolean> getbit(byte[] key, long offset);
|
||||
|
||||
Response<byte[]> getSet(byte[] key, byte[] value);
|
||||
|
||||
Response<Long> getrange(byte[] key, long startOffset, long endOffset);
|
||||
|
||||
Response<Long> hdel(byte[] key, byte[]... field);
|
||||
|
||||
Response<Boolean> hexists(byte[] key, byte[] field);
|
||||
|
||||
Response<byte[]> hget(byte[] key, byte[] field);
|
||||
|
||||
Response<Map<byte[], byte[]>> hgetAll(byte[] key);
|
||||
|
||||
Response<Long> hincrBy(byte[] key, byte[] field, long value);
|
||||
|
||||
Response<Set<byte[]>> hkeys(byte[] key);
|
||||
|
||||
Response<Long> hlen(byte[] key);
|
||||
|
||||
Response<List<byte[]>> hmget(byte[] key, byte[]... fields);
|
||||
|
||||
Response<String> hmset(byte[] key, Map<byte[], byte[]> hash);
|
||||
|
||||
Response<Long> hset(byte[] key, byte[] field, byte[] value);
|
||||
|
||||
Response<Long> hsetnx(byte[] key, byte[] field, byte[] value);
|
||||
|
||||
Response<List<byte[]>> hvals(byte[] key);
|
||||
|
||||
Response<Long> incr(byte[] key);
|
||||
|
||||
Response<Long> incrBy(byte[] key, long integer);
|
||||
|
||||
Response<byte[]> lindex(byte[] key, long index);
|
||||
|
||||
Response<Long> linsert(byte[] key, BinaryClient.LIST_POSITION where,
|
||||
byte[] pivot, byte[] value);
|
||||
|
||||
Response<Long> llen(byte[] key);
|
||||
|
||||
Response<byte[]> lpop(byte[] key);
|
||||
|
||||
Response<Long> lpush(byte[] key, byte[]... string);
|
||||
|
||||
Response<Long> lpushx(byte[] key, byte[]... bytes);
|
||||
|
||||
Response<List<byte[]>> lrange(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> lrem(byte[] key, long count, byte[] value);
|
||||
|
||||
Response<String> lset(byte[] key, long index, byte[] value);
|
||||
|
||||
Response<String> ltrim(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> move(byte[] key, int dbIndex);
|
||||
|
||||
Response<Long> persist(byte[] key);
|
||||
|
||||
Response<byte[]> rpop(byte[] key);
|
||||
|
||||
Response<Long> rpush(byte[] key, byte[]... string);
|
||||
|
||||
Response<Long> rpushx(byte[] key, byte[]... string);
|
||||
|
||||
Response<Long> sadd(byte[] key, byte[]... member);
|
||||
|
||||
Response<Long> scard(byte[] key);
|
||||
|
||||
Response<String> set(byte[] key, byte[] value);
|
||||
|
||||
Response<Boolean> setbit(byte[] key, long offset, byte[] value);
|
||||
|
||||
Response<Long> setrange(byte[] key, long offset, byte[] value);
|
||||
|
||||
Response<String> setex(byte[] key, int seconds, byte[] value);
|
||||
|
||||
Response<Long> setnx(byte[] key, byte[] value);
|
||||
|
||||
Response<Long> setrange(String key, long offset, String value);
|
||||
|
||||
Response<Set<byte[]>> smembers(byte[] key);
|
||||
|
||||
Response<Boolean> sismember(byte[] key, byte[] member);
|
||||
|
||||
Response<List<byte[]>> sort(byte[] key);
|
||||
|
||||
Response<List<byte[]>> sort(byte[] key,
|
||||
SortingParams sortingParameters);
|
||||
|
||||
Response<byte[]> spop(byte[] key);
|
||||
|
||||
Response<byte[]> srandmember(byte[] key);
|
||||
|
||||
Response<Long> srem(byte[] key, byte[]... member);
|
||||
|
||||
Response<Long> strlen(byte[] key);
|
||||
|
||||
Response<String> substr(byte[] key, int start, int end);
|
||||
|
||||
Response<Long> ttl(byte[] key);
|
||||
|
||||
Response<String> type(byte[] key);
|
||||
|
||||
Response<Long> zadd(byte[] key, double score, byte[] member);
|
||||
|
||||
Response<Long> zcard(byte[] key);
|
||||
|
||||
Response<Long> zcount(byte[] key, double min, double max);
|
||||
|
||||
Response<Double> zincrby(byte[] key, double score, byte[] member);
|
||||
|
||||
Response<Set<byte[]>> zrange(byte[] key, long start, long end);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
byte[] max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
byte[] min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
byte[] min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
byte[] max, byte[] min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
byte[] max, byte[] min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> zrank(byte[] key, byte[] member);
|
||||
|
||||
Response<Long> zrem(byte[] key, byte[]... member);
|
||||
|
||||
Response<Long> zremrangeByRank(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> zremrangeByScore(byte[] key, double start, double end);
|
||||
|
||||
Response<Long> zremrangeByScore(byte[] key, byte[] start, byte[] end);
|
||||
|
||||
Response<Set<byte[]>> zrevrange(byte[] key, long start, long end);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeWithScores(byte[] key, long start,
|
||||
long end);
|
||||
|
||||
Response<Long> zrevrank(byte[] key, byte[] member);
|
||||
|
||||
Response<Double> zscore(byte[] key, byte[] member);
|
||||
|
||||
Response<Long> bitcount(byte[] key);
|
||||
|
||||
Response<Long> bitcount(byte[] key, long start, long end);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BinaryScriptingCommands {
|
||||
|
||||
Object eval(byte[] script, byte[] keyCount, byte[]... params);
|
||||
|
||||
Object eval(byte[] script, int keyCount, byte[]... params);
|
||||
|
||||
Object eval(byte[] script, List<byte[]> keys, List<byte[]> args);
|
||||
|
||||
Object eval(byte[] script);
|
||||
|
||||
Object evalsha(byte[] script);
|
||||
|
||||
Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args);
|
||||
|
||||
Object evalsha(byte[] sha1, int keyCount, byte[]... params);
|
||||
|
||||
// TODO: should be Boolean, add singular version
|
||||
List<Long> scriptExists(byte[]... sha1);
|
||||
|
||||
byte[] scriptLoad(byte[] script);
|
||||
|
||||
String scriptFlush();
|
||||
|
||||
String scriptKill();
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -7,397 +11,556 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
implements BinaryJedisCommands {
|
||||
implements BinaryJedisCommands {
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards) {
|
||||
super(shards);
|
||||
super(shards);
|
||||
}
|
||||
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
|
||||
super(shards, algo);
|
||||
super(shards, algo);
|
||||
}
|
||||
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
|
||||
super(shards, keyTagPattern);
|
||||
super(shards, keyTagPattern);
|
||||
}
|
||||
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo,
|
||||
Pattern keyTagPattern) {
|
||||
super(shards, algo, keyTagPattern);
|
||||
Pattern keyTagPattern) {
|
||||
super(shards, algo, keyTagPattern);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
for (Jedis jedis : getAllShards()) {
|
||||
jedis.disconnect();
|
||||
}
|
||||
public void disconnect() {
|
||||
for (Jedis jedis : getAllShards()) {
|
||||
jedis.quit();
|
||||
jedis.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
protected Jedis create(JedisShardInfo shard) {
|
||||
return new Jedis(shard);
|
||||
return new Jedis(shard);
|
||||
}
|
||||
|
||||
public String set(byte[] key, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.set(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.set(key, value);
|
||||
}
|
||||
|
||||
public byte[] get(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.get(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.get(key);
|
||||
}
|
||||
|
||||
public Boolean exists(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.exists(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.exists(key);
|
||||
}
|
||||
|
||||
public String type(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.type(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.type(key);
|
||||
}
|
||||
|
||||
public Long expire(byte[] key, int seconds) {
|
||||
Jedis j = getShard(key);
|
||||
return j.expire(key, seconds);
|
||||
Jedis j = getShard(key);
|
||||
return j.expire(key, seconds);
|
||||
}
|
||||
|
||||
public Long expireAt(byte[] key, long unixTime) {
|
||||
Jedis j = getShard(key);
|
||||
return j.expireAt(key, unixTime);
|
||||
Jedis j = getShard(key);
|
||||
return j.expireAt(key, unixTime);
|
||||
}
|
||||
|
||||
public Long ttl(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.ttl(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.ttl(key);
|
||||
}
|
||||
|
||||
public byte[] getSet(byte[] key, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getSet(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.getSet(key, value);
|
||||
}
|
||||
|
||||
public Long setnx(byte[] key, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setnx(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.setnx(key, value);
|
||||
}
|
||||
|
||||
public String setex(byte[] key, int seconds, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setex(key, seconds, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.setex(key, seconds, value);
|
||||
}
|
||||
|
||||
public Long decrBy(byte[] key, long integer) {
|
||||
Jedis j = getShard(key);
|
||||
return j.decrBy(key, integer);
|
||||
Jedis j = getShard(key);
|
||||
return j.decrBy(key, integer);
|
||||
}
|
||||
|
||||
public Long decr(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.decr(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.decr(key);
|
||||
}
|
||||
|
||||
public Long incrBy(byte[] key, long integer) {
|
||||
public Long del(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.incrBy(key, integer);
|
||||
return j.del(key);
|
||||
}
|
||||
|
||||
public Long incrBy(byte[] key, long integer) {
|
||||
Jedis j = getShard(key);
|
||||
return j.incrBy(key, integer);
|
||||
}
|
||||
|
||||
public Long incr(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.incr(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.incr(key);
|
||||
}
|
||||
|
||||
public Long append(byte[] key, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.append(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.append(key, value);
|
||||
}
|
||||
|
||||
public byte[] substr(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.substr(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.substr(key, start, end);
|
||||
}
|
||||
|
||||
public Long hset(byte[] key, byte[] field, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hset(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hset(key, field, value);
|
||||
}
|
||||
|
||||
public byte[] hget(byte[] key, byte[] field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hget(key, field);
|
||||
Jedis j = getShard(key);
|
||||
return j.hget(key, field);
|
||||
}
|
||||
|
||||
public Long hsetnx(byte[] key, byte[] field, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hsetnx(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hsetnx(key, field, value);
|
||||
}
|
||||
|
||||
public String hmset(byte[] key, Map<byte[], byte[]> hash) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hmset(key, hash);
|
||||
Jedis j = getShard(key);
|
||||
return j.hmset(key, hash);
|
||||
}
|
||||
|
||||
public List<byte[]> hmget(byte[] key, byte[]... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hmget(key, fields);
|
||||
Jedis j = getShard(key);
|
||||
return j.hmget(key, fields);
|
||||
}
|
||||
|
||||
public Long hincrBy(byte[] key, byte[] field, long value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hincrBy(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hincrBy(key, field, value);
|
||||
}
|
||||
|
||||
public Boolean hexists(byte[] key, byte[] field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hexists(key, field);
|
||||
Jedis j = getShard(key);
|
||||
return j.hexists(key, field);
|
||||
}
|
||||
|
||||
public Long hdel(byte[] key, byte[] field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, field);
|
||||
public Long hdel(byte[] key, byte[]... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, fields);
|
||||
}
|
||||
|
||||
public Long hlen(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hlen(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hlen(key);
|
||||
}
|
||||
|
||||
public Set<byte[]> hkeys(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public Collection<byte[]> hvals(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
public Map<byte[], byte[]> hgetAll(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hgetAll(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hgetAll(key);
|
||||
}
|
||||
|
||||
public Long rpush(byte[] key, byte[] string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, string);
|
||||
public Long rpush(byte[] key, byte[]... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, strings);
|
||||
}
|
||||
|
||||
public Long lpush(byte[] key, byte[] string) {
|
||||
public Long lpush(byte[] key, byte[]... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, strings);
|
||||
}
|
||||
|
||||
public Long strlen(final byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.strlen(key);
|
||||
}
|
||||
|
||||
public Long lpushx(byte[] key, byte[]... string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, string);
|
||||
return j.lpushx(key, string);
|
||||
}
|
||||
|
||||
public Long persist(final byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.persist(key);
|
||||
}
|
||||
|
||||
public Long rpushx(byte[] key, byte[]... string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpushx(key, string);
|
||||
}
|
||||
|
||||
public Long llen(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.llen(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.llen(key);
|
||||
}
|
||||
|
||||
public List<byte[]> lrange(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrange(key, start, end);
|
||||
public List<byte[]> lrange(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrange(key, start, end);
|
||||
}
|
||||
|
||||
public String ltrim(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.ltrim(key, start, end);
|
||||
public String ltrim(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.ltrim(key, start, end);
|
||||
}
|
||||
|
||||
public byte[] lindex(byte[] key, int index) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lindex(key, index);
|
||||
public byte[] lindex(byte[] key, long index) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lindex(key, index);
|
||||
}
|
||||
|
||||
public String lset(byte[] key, int index, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lset(key, index, value);
|
||||
public String lset(byte[] key, long index, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lset(key, index, value);
|
||||
}
|
||||
|
||||
public Long lrem(byte[] key, int count, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrem(key, count, value);
|
||||
public Long lrem(byte[] key, long count, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrem(key, count, value);
|
||||
}
|
||||
|
||||
public byte[] lpop(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.lpop(key);
|
||||
}
|
||||
|
||||
public byte[] rpop(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.rpop(key);
|
||||
}
|
||||
|
||||
public Long sadd(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, member);
|
||||
public Long sadd(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, members);
|
||||
}
|
||||
|
||||
public Set<byte[]> smembers(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.smembers(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.smembers(key);
|
||||
}
|
||||
|
||||
public Long srem(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, member);
|
||||
public Long srem(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, members);
|
||||
}
|
||||
|
||||
public byte[] spop(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.spop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.spop(key);
|
||||
}
|
||||
|
||||
public Long scard(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.scard(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.scard(key);
|
||||
}
|
||||
|
||||
public Boolean sismember(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sismember(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.sismember(key, member);
|
||||
}
|
||||
|
||||
public byte[] srandmember(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srandmember(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.srandmember(key);
|
||||
}
|
||||
|
||||
public Long zadd(byte[] key, double score, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, score, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, score, member);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrange(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
public Long zadd(byte[] key, Map<Double, byte[]> scoreMembers) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, scoreMembers);
|
||||
}
|
||||
|
||||
public Long zrem(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, member);
|
||||
public Set<byte[]> zrange(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
}
|
||||
|
||||
public Long zrem(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, members);
|
||||
}
|
||||
|
||||
public Double zincrby(byte[] key, double score, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zincrby(key, score, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zincrby(key, score, member);
|
||||
}
|
||||
|
||||
public Long zrank(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrank(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrank(key, member);
|
||||
}
|
||||
|
||||
public Long zrevrank(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrank(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrank(key, member);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrange(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrange(key, start, end);
|
||||
public Set<byte[]> zrevrange(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrange(key, start, end);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeWithScores(key, start, end);
|
||||
public Set<Tuple> zrangeWithScores(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeWithScores(key, start, end);
|
||||
public Set<Tuple> zrevrangeWithScores(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Long zcard(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcard(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.zcard(key);
|
||||
}
|
||||
|
||||
public Double zscore(byte[] key, byte[] member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zscore(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zscore(key, member);
|
||||
}
|
||||
|
||||
public List<byte[]> sort(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key);
|
||||
}
|
||||
|
||||
public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key, sortingParameters);
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key, sortingParameters);
|
||||
}
|
||||
|
||||
public Long zcount(byte[] key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
}
|
||||
|
||||
public Long zcount(byte[] key, byte[] min, byte[] max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, double min, double max,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, double min, double max,
|
||||
int offset, int count) {
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public Long zremrangeByRank(byte[] key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByRank(key, start, end);
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max,
|
||||
byte[] min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max,
|
||||
byte[] min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Long zremrangeByRank(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByRank(key, start, end);
|
||||
}
|
||||
|
||||
public Long zremrangeByScore(byte[] key, double start, double end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
}
|
||||
|
||||
public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
}
|
||||
|
||||
public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot,
|
||||
byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.linsert(key, where, pivot, value);
|
||||
byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.linsert(key, where, pivot, value);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
|
||||
shardedJedisPipeline.setShardedJedis(this);
|
||||
shardedJedisPipeline.execute();
|
||||
return shardedJedisPipeline.getResults();
|
||||
shardedJedisPipeline.setShardedJedis(this);
|
||||
shardedJedisPipeline.execute();
|
||||
return shardedJedisPipeline.getResults();
|
||||
}
|
||||
|
||||
public ShardedJedisPipeline pipelined() {
|
||||
ShardedJedisPipeline pipeline = new ShardedJedisPipeline();
|
||||
pipeline.setShardedJedis(this);
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
public Long objectRefcount(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.objectRefcount(key);
|
||||
}
|
||||
|
||||
public byte[] objectEncoding(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.objectEncoding(key);
|
||||
}
|
||||
|
||||
public Long objectIdletime(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.objectIdletime(key);
|
||||
}
|
||||
|
||||
public Boolean setbit(byte[] key, long offset, boolean value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
}
|
||||
|
||||
public Boolean setbit(byte[] key, long offset, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
}
|
||||
|
||||
public Boolean getbit(byte[] key, long offset) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getbit(key, offset);
|
||||
}
|
||||
|
||||
public Long setrange(byte[] key, long offset, byte[] value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setrange(key, offset, value);
|
||||
}
|
||||
|
||||
public byte[] getrange(byte[] key, long startOffset, long endOffset) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getrange(key, startOffset, endOffset);
|
||||
}
|
||||
|
||||
public Long move(byte[] key, int dbIndex) {
|
||||
Jedis j = getShard(key);
|
||||
return j.move(key, dbIndex);
|
||||
}
|
||||
|
||||
public byte[] echo(byte[] arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.echo(arg);
|
||||
}
|
||||
|
||||
public List<byte[]> brpop(byte[] arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.brpop(arg);
|
||||
}
|
||||
|
||||
public List<byte[]> blpop(byte[] arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.blpop(arg);
|
||||
}
|
||||
|
||||
public Long bitcount(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.bitcount(key);
|
||||
}
|
||||
|
||||
public Long bitcount(byte[] key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.bitcount(key, start, end);
|
||||
}
|
||||
}
|
||||
@@ -1,546 +0,0 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
public class BinaryTransaction extends Queable {
|
||||
protected Client client = null;
|
||||
protected boolean inTransaction = true;
|
||||
|
||||
public BinaryTransaction() {
|
||||
}
|
||||
|
||||
public BinaryTransaction(final Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public List<Object> exec() {
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Object o : unformatted) {
|
||||
formatted.add(generateResponse(o).get());
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public String discard() {
|
||||
client.discard();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
inTransaction = false;
|
||||
clean();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Response<Long> append(byte[] key, byte[] value) {
|
||||
client.append(key, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(byte[]... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> brpop(byte[]... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> decr(byte[] key) {
|
||||
client.decr(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> decrBy(byte[] key, long integer) {
|
||||
client.decrBy(key, integer);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> del(byte[]... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> echo(byte[] string) {
|
||||
client.echo(string);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Boolean> exists(byte[] key) {
|
||||
client.exists(key);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<Long> expire(byte[] key, int seconds) {
|
||||
client.expire(key, seconds);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> expireAt(byte[] key, long unixTime) {
|
||||
client.expireAt(key, unixTime);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<byte[]> get(byte[] key) {
|
||||
client.get(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> getSet(byte[] key, byte[] value) {
|
||||
client.getSet(key, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> hdel(byte[] key, byte[] field) {
|
||||
client.hdel(key, field);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Boolean> hexists(byte[] key, byte[] field) {
|
||||
client.hexists(key, field);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<byte[]> hget(byte[] key, byte[] field) {
|
||||
client.hget(key, field);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Map<String, String>> hgetAll(byte[] key) {
|
||||
client.hgetAll(key);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<Long> hincrBy(byte[] key, byte[] field, long value) {
|
||||
client.hincrBy(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> hkeys(byte[] key) {
|
||||
client.hkeys(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> hlen(byte[] key) {
|
||||
client.hlen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> hmget(byte[] key, byte[]... fields) {
|
||||
client.hmget(key, fields);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<byte[]> hmset(byte[] key, Map<byte[], byte[]> hash) {
|
||||
client.hmset(key, hash);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Long> hset(byte[] key, byte[] field, byte[] value) {
|
||||
client.hset(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> hsetnx(byte[] key, byte[] field, byte[] value) {
|
||||
client.hsetnx(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> hvals(byte[] key) {
|
||||
client.hvals(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> incr(byte[] key) {
|
||||
client.incr(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> incrBy(byte[] key, long integer) {
|
||||
client.incrBy(key, integer);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> keys(byte[] pattern) {
|
||||
client.keys(pattern);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<byte[]> lindex(byte[] key, long index) {
|
||||
client.lindex(key, index);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Long> linsert(byte[] key, LIST_POSITION where,
|
||||
byte[] pivot, byte[] value) {
|
||||
client.linsert(key, where, pivot, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> llen(byte[] key) {
|
||||
client.llen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<byte[]> lpop(byte[] key) {
|
||||
client.lpop(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Long> lpush(byte[] key, byte[] string) {
|
||||
client.lpush(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> lpushx(byte[] key, byte[] bytes) {
|
||||
client.lpushx(key, bytes);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> lrange(byte[] key, long start, long end) {
|
||||
client.lrange(key, start, end);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> lrem(byte[] key, long count, byte[] value) {
|
||||
client.lrem(key, count, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> lset(byte[] key, long index, byte[] value) {
|
||||
client.lset(key, index, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> ltrim(byte[] key, long start, long end) {
|
||||
client.ltrim(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> mget(byte[]... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> move(byte[] key, int dbIndex) {
|
||||
client.move(key, dbIndex);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> mset(byte[]... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(byte[]... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> persist(byte[] key) {
|
||||
client.persist(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rename(byte[] oldkey, byte[] newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(byte[] oldkey, byte[] newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<byte[]> rpop(byte[] key) {
|
||||
client.rpop(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<byte[]> rpoplpush(byte[] srckey, byte[] dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Long> rpush(byte[] key, byte[] string) {
|
||||
client.rpush(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> rpushx(byte[] key, byte[] string) {
|
||||
client.rpushx(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sadd(byte[] key, byte[] member) {
|
||||
client.sadd(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> scard(byte[] key) {
|
||||
client.scard(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sdiff(byte[]... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<byte[]> set(byte[] key, byte[] value) {
|
||||
client.set(key, value);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Boolean> setbit(String key, long offset, boolean value) {
|
||||
client.setbit(key, offset, value);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<String> setex(byte[] key, int seconds, byte[] value) {
|
||||
client.setex(key, seconds, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> setnx(byte[] key, byte[] value) {
|
||||
client.setnx(key, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sinter(byte[]... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Boolean> sismember(byte[] key, byte[] member) {
|
||||
client.sismember(key, member);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> smembers(byte[] key) {
|
||||
client.smembers(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> smove(byte[] srckey, byte[] dstkey, byte[] member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> sort(byte[] key) {
|
||||
client.sort(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> sort(byte[] key,
|
||||
SortingParams sortingParameters) {
|
||||
client.sort(key, sortingParameters);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> sort(byte[] key,
|
||||
SortingParams sortingParameters, byte[] dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> sort(byte[] key, byte[] dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<byte[]> spop(byte[] key) {
|
||||
client.spop(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<byte[]> srandmember(byte[] key) {
|
||||
client.srandmember(key);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Long> srem(byte[] key, byte[] member) {
|
||||
client.srem(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> strlen(byte[] key) {
|
||||
client.strlen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> substr(byte[] key, int start, int end) { // what's
|
||||
// that?
|
||||
client.substr(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sunion(byte[]... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> ttl(byte[] key) {
|
||||
client.ttl(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> type(byte[] key) {
|
||||
client.type(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> zadd(byte[] key, double score, byte[] member) {
|
||||
client.zadd(key, score, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zcard(byte[] key) {
|
||||
client.zcard(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zcount(byte[] key, double min, double max) {
|
||||
client.zcount(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Double> zincrby(byte[] key, double score, byte[] member) {
|
||||
client.zincrby(key, score, member);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrange(byte[] key, int start, int end) {
|
||||
client.zrange(key, start, end);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max) {
|
||||
client.zrangeByScore(key, min, max);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
byte[] max) {
|
||||
client.zrangeByScore(key, min, max);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
client.zrangeByScore(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max) {
|
||||
client.zrangeByScoreWithScores(key, min, max);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeWithScores(byte[] key, int start, int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
public Response<Long> zrank(byte[] key, byte[] member) {
|
||||
client.zrank(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zrem(byte[] key, byte[] member) {
|
||||
client.zrem(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zremrangeByRank(byte[] key, int start, int end) {
|
||||
client.zremrangeByRank(key, start, end);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zremrangeByScore(byte[] key, double start, double end) {
|
||||
client.zremrangeByScore(key, start, end);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrevrange(byte[] key, int start, int end) {
|
||||
client.zrevrange(key, start, end);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrevrangeWithScores(byte[] key, int start,
|
||||
int end) {
|
||||
client.zrevrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
public Response<Long> zrevrank(byte[] key, byte[] member) {
|
||||
client.zrevrank(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Double> zscore(byte[] key, byte[] member) {
|
||||
client.zscore(key, member);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<byte[]> brpoplpush(byte[] source, byte[] destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
}
|
||||
8
src/main/java/redis/clients/jedis/BitOP.java
Normal file
8
src/main/java/redis/clients/jedis/BitOP.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public enum BitOP {
|
||||
AND,
|
||||
OR,
|
||||
XOR,
|
||||
NOT;
|
||||
}
|
||||
28
src/main/java/redis/clients/jedis/BuilderFactory.java
Normal file → Executable file
28
src/main/java/redis/clients/jedis/BuilderFactory.java
Normal file → Executable file
@@ -7,7 +7,8 @@ import java.util.*;
|
||||
public class BuilderFactory {
|
||||
public static final Builder<Double> DOUBLE = new Builder<Double>() {
|
||||
public Double build(Object data) {
|
||||
return Double.valueOf(STRING.build(data));
|
||||
String asString = STRING.build(data);
|
||||
return asString == null ? null : Double.valueOf(asString);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -143,6 +144,13 @@ public class BuilderFactory {
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<byte[]> result = new LinkedHashSet<byte[]>(l);
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(barray);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -150,6 +158,24 @@ public class BuilderFactory {
|
||||
return "ZSet<byte[]>";
|
||||
}
|
||||
};
|
||||
public static final Builder<Map<byte[], byte[]>> BYTE_ARRAY_MAP = new Builder<Map<byte[], byte[]>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<byte[], byte[]> build(Object data) {
|
||||
final List<byte[]> flatHash = (List<byte[]>) data;
|
||||
final Map<byte[], byte[]> hash = new HashMap<byte[], byte[]>();
|
||||
final Iterator<byte[]> iterator = flatHash.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
hash.put(iterator.next(), iterator.next());
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Map<byte[], byte[]>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<Set<String>> STRING_ZSET = new Builder<Set<String>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,8 @@ public interface Commands {
|
||||
|
||||
public void setbit(String key, long offset, boolean value);
|
||||
|
||||
public void setbit(String key, long offset, String value);
|
||||
|
||||
public void getbit(String key, long offset);
|
||||
|
||||
public void setrange(String key, long offset, String value);
|
||||
@@ -76,7 +78,7 @@ public interface Commands {
|
||||
|
||||
public void hexists(final String key, final String field);
|
||||
|
||||
public void hdel(final String key, final String field);
|
||||
public void hdel(final String key, final String... fields);
|
||||
|
||||
public void hlen(final String key);
|
||||
|
||||
@@ -86,9 +88,9 @@ public interface Commands {
|
||||
|
||||
public void hgetAll(final String key);
|
||||
|
||||
public void rpush(final String key, final String string);
|
||||
public void rpush(final String key, final String... strings);
|
||||
|
||||
public void lpush(final String key, final String string);
|
||||
public void lpush(final String key, final String... strings);
|
||||
|
||||
public void llen(final String key);
|
||||
|
||||
@@ -108,16 +110,16 @@ public interface Commands {
|
||||
|
||||
public void rpoplpush(final String srckey, final String dstkey);
|
||||
|
||||
public void sadd(final String key, final String member);
|
||||
public void sadd(final String key, final String... members);
|
||||
|
||||
public void smembers(final String key);
|
||||
|
||||
public void srem(final String key, final String member);
|
||||
public void srem(final String key, final String... member);
|
||||
|
||||
public void spop(final String key);
|
||||
|
||||
public void smove(final String srckey, final String dstkey,
|
||||
final String member);
|
||||
final String member);
|
||||
|
||||
public void scard(final String key);
|
||||
|
||||
@@ -139,24 +141,26 @@ public interface Commands {
|
||||
|
||||
public void zadd(final String key, final double score, final String member);
|
||||
|
||||
public void zrange(final String key, final int start, final int end);
|
||||
public void zadd(final String key, final Map<Double, String> scoreMembers);
|
||||
|
||||
public void zrem(final String key, final String member);
|
||||
public void zrange(final String key, final long start, final long end);
|
||||
|
||||
public void zrem(final String key, final String... members);
|
||||
|
||||
public void zincrby(final String key, final double score,
|
||||
final String member);
|
||||
final String member);
|
||||
|
||||
public void zrank(final String key, final String member);
|
||||
|
||||
public void zrevrank(final String key, final String member);
|
||||
|
||||
public void zrevrange(final String key, final int start, final int end);
|
||||
public void zrevrange(final String key, final long start, final long end);
|
||||
|
||||
public void zrangeWithScores(final String key, final int start,
|
||||
final int end);
|
||||
public void zrangeWithScores(final String key, final long start,
|
||||
final long end);
|
||||
|
||||
public void zrevrangeWithScores(final String key, final int start,
|
||||
final int end);
|
||||
public void zrevrangeWithScores(final String key, final long start,
|
||||
final long end);
|
||||
|
||||
public void zcard(final String key);
|
||||
|
||||
@@ -171,74 +175,92 @@ public interface Commands {
|
||||
public void blpop(final String[] args);
|
||||
|
||||
public void sort(final String key, final SortingParams sortingParameters,
|
||||
final String dstkey);
|
||||
final String dstkey);
|
||||
|
||||
public void sort(final String key, final String dstkey);
|
||||
|
||||
public void brpop(final String[] args);
|
||||
|
||||
public void brpoplpush(final String source, final String destination,
|
||||
final int timeout);
|
||||
final int timeout);
|
||||
|
||||
public void zcount(final String key, final double min, final double max);
|
||||
|
||||
public void zcount(final String key, final String min, final String max);
|
||||
|
||||
public void zrangeByScore(final String key, final double min,
|
||||
final double max);
|
||||
final double max);
|
||||
|
||||
public void zrangeByScore(final String key, final String min,
|
||||
final String max);
|
||||
final String max);
|
||||
|
||||
public void zrangeByScore(final String key, final double min,
|
||||
final double max, final int offset, int count);
|
||||
final double max, final int offset, int count);
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final double min,
|
||||
final double max);
|
||||
final double max);
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final double min,
|
||||
final double max, final int offset, final int count);
|
||||
final double max, final int offset, final int count);
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final String min,
|
||||
final String max);
|
||||
|
||||
public void zrangeByScoreWithScores(final String key, final String min,
|
||||
final String max, final int offset, final int count);
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min);
|
||||
final double min);
|
||||
|
||||
public void zrevrangeByScore(final String key, final String max,
|
||||
final String min);
|
||||
final String min);
|
||||
|
||||
public void zrevrangeByScore(final String key, final double max,
|
||||
final double min, final int offset, int count);
|
||||
final double min, final int offset, int count);
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min);
|
||||
final double min);
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final double max,
|
||||
final double min, final int offset, final int count);
|
||||
final double min, final int offset, final int count);
|
||||
|
||||
public void zremrangeByRank(final String key, final int start, final int end);
|
||||
public void zrevrangeByScoreWithScores(final String key, final String max,
|
||||
final String min);
|
||||
|
||||
public void zrevrangeByScoreWithScores(final String key, final String max,
|
||||
final String min, final int offset, final int count);
|
||||
|
||||
public void zremrangeByRank(final String key, final long start,
|
||||
final long end);
|
||||
|
||||
public void zremrangeByScore(final String key, final double start,
|
||||
final double end);
|
||||
final double end);
|
||||
|
||||
public void zremrangeByScore(final String key, final String start,
|
||||
final String end);
|
||||
|
||||
public void zunionstore(final String dstkey, final String... sets);
|
||||
|
||||
public void zunionstore(final String dstkey, final ZParams params,
|
||||
final String... sets);
|
||||
final String... sets);
|
||||
|
||||
public void zinterstore(final String dstkey, final String... sets);
|
||||
|
||||
public void zinterstore(final String dstkey, final ZParams params,
|
||||
final String... sets);
|
||||
final String... sets);
|
||||
|
||||
public void strlen(final String key);
|
||||
|
||||
public void lpushx(final String key, final String string);
|
||||
public void lpushx(final String key, final String... string);
|
||||
|
||||
public void persist(final String key);
|
||||
|
||||
public void rpushx(final String key, final String string);
|
||||
public void rpushx(final String key, final String... string);
|
||||
|
||||
public void echo(final String string);
|
||||
|
||||
public void linsert(final String key, final LIST_POSITION where,
|
||||
final String pivot, final String value);
|
||||
final String pivot, final String value);
|
||||
|
||||
public void bgrewriteaof();
|
||||
|
||||
@@ -259,4 +281,16 @@ public interface Commands {
|
||||
public void exec();
|
||||
|
||||
public void discard();
|
||||
}
|
||||
|
||||
public void objectRefcount(String key);
|
||||
|
||||
public void objectIdletime(String key);
|
||||
|
||||
public void objectEncoding(String key);
|
||||
|
||||
public void bitcount(final String key);
|
||||
|
||||
public void bitcount(final String key, long start, long end);
|
||||
|
||||
public void bitop(BitOP op, final String destKey, String... srcKeys);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
|
||||
import redis.clients.jedis.Protocol.Command;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
@@ -18,7 +19,6 @@ public class Connection {
|
||||
private String host;
|
||||
private int port = Protocol.DEFAULT_PORT;
|
||||
private Socket socket;
|
||||
private Protocol protocol = new Protocol();
|
||||
private RedisOutputStream outputStream;
|
||||
private RedisInputStream inputStream;
|
||||
private int pipelinedCommands = 0;
|
||||
@@ -38,6 +38,10 @@ public class Connection {
|
||||
|
||||
public void setTimeoutInfinite() {
|
||||
try {
|
||||
if(!isConnected()) {
|
||||
connect();
|
||||
}
|
||||
socket.setKeepAlive(true);
|
||||
socket.setSoTimeout(0);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
@@ -47,6 +51,7 @@ public class Connection {
|
||||
public void rollbackTimeout() {
|
||||
try {
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.setKeepAlive(false);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
@@ -75,14 +80,14 @@ public class Connection {
|
||||
|
||||
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||
connect();
|
||||
protocol.sendCommand(outputStream, cmd, args);
|
||||
Protocol.sendCommand(outputStream, cmd, args);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected Connection sendCommand(final Command cmd) {
|
||||
connect();
|
||||
protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||
Protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
}
|
||||
@@ -110,12 +115,20 @@ public class Connection {
|
||||
}
|
||||
|
||||
public Connection() {
|
||||
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (!isConnected()) {
|
||||
try {
|
||||
socket = new Socket();
|
||||
//->@wjw_add
|
||||
socket.setReuseAddress(true);
|
||||
socket.setKeepAlive(true); //Will monitor the TCP connection is valid
|
||||
socket.setTcpNoDelay(true); //Socket buffer Whetherclosed, to ensure timely delivery of data
|
||||
socket.setSoLinger(true,0); //Control calls close () method, the underlying socket is closed immediately
|
||||
//<-@wjw_add
|
||||
|
||||
socket.connect(new InetSocketAddress(host, port), timeout);
|
||||
socket.setSoTimeout(timeout);
|
||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||
@@ -149,7 +162,7 @@ public class Connection {
|
||||
protected String getStatusCodeReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
final byte[] resp = (byte[]) protocol.read(inputStream);
|
||||
final byte[] resp = (byte[]) Protocol.read(inputStream);
|
||||
if (null == resp) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -169,13 +182,13 @@ public class Connection {
|
||||
public byte[] getBinaryBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (byte[]) protocol.read(inputStream);
|
||||
return (byte[]) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public Long getIntegerReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (Long) protocol.read(inputStream);
|
||||
return (Long) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public List<String> getMultiBulkReply() {
|
||||
@@ -186,14 +199,21 @@ public class Connection {
|
||||
public List<byte[]> getBinaryMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<byte[]>) protocol.read(inputStream);
|
||||
return (List<byte[]>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getObjectMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<Object>) protocol.read(inputStream);
|
||||
return (List<Object>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Long> getIntegerMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<Long>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public List<Object> getAll() {
|
||||
@@ -204,7 +224,11 @@ public class Connection {
|
||||
List<Object> all = new ArrayList<Object>();
|
||||
flush();
|
||||
while (pipelinedCommands > except) {
|
||||
all.add(protocol.read(inputStream));
|
||||
try{
|
||||
all.add(Protocol.read(inputStream));
|
||||
}catch(JedisDataException e){
|
||||
all.add(e);
|
||||
}
|
||||
pipelinedCommands--;
|
||||
}
|
||||
return all;
|
||||
@@ -213,6 +237,6 @@ public class Connection {
|
||||
public Object getOne() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return protocol.read(inputStream);
|
||||
return Protocol.read(inputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,8 @@ public interface JedisCommands {
|
||||
|
||||
Boolean exists(String key);
|
||||
|
||||
Long persist(String key);
|
||||
|
||||
String type(String key);
|
||||
|
||||
Long expire(String key, int seconds);
|
||||
@@ -22,11 +24,13 @@ public interface JedisCommands {
|
||||
|
||||
Long ttl(String key);
|
||||
|
||||
boolean setbit(String key, long offset, boolean value);
|
||||
Boolean setbit(String key, long offset, boolean value);
|
||||
|
||||
boolean getbit(String key, long offset);
|
||||
Boolean setbit(String key, long offset, String value);
|
||||
|
||||
long setrange(String key, long offset, String value);
|
||||
Boolean getbit(String key, long offset);
|
||||
|
||||
Long setrange(String key, long offset, String value);
|
||||
|
||||
String getrange(String key, long startOffset, long endOffset);
|
||||
|
||||
@@ -62,7 +66,7 @@ public interface JedisCommands {
|
||||
|
||||
Boolean hexists(String key, String field);
|
||||
|
||||
Long hdel(String key, String field);
|
||||
Long hdel(String key, String... field);
|
||||
|
||||
Long hlen(String key);
|
||||
|
||||
@@ -72,9 +76,9 @@ public interface JedisCommands {
|
||||
|
||||
Map<String, String> hgetAll(String key);
|
||||
|
||||
Long rpush(String key, String string);
|
||||
Long rpush(String key, String... string);
|
||||
|
||||
Long lpush(String key, String string);
|
||||
Long lpush(String key, String... string);
|
||||
|
||||
Long llen(String key);
|
||||
|
||||
@@ -92,11 +96,11 @@ public interface JedisCommands {
|
||||
|
||||
String rpop(String key);
|
||||
|
||||
Long sadd(String key, String member);
|
||||
Long sadd(String key, String... member);
|
||||
|
||||
Set<String> smembers(String key);
|
||||
|
||||
Long srem(String key, String member);
|
||||
Long srem(String key, String... member);
|
||||
|
||||
String spop(String key);
|
||||
|
||||
@@ -106,11 +110,15 @@ public interface JedisCommands {
|
||||
|
||||
String srandmember(String key);
|
||||
|
||||
Long strlen(String key);
|
||||
|
||||
Long zadd(String key, double score, String member);
|
||||
|
||||
Long zadd(String key, Map<Double, String> scoreMembers);
|
||||
|
||||
Set<String> zrange(String key, int start, int end);
|
||||
Set<String> zrange(String key, long start, long end);
|
||||
|
||||
Long zrem(String key, String member);
|
||||
Long zrem(String key, String... member);
|
||||
|
||||
Double zincrby(String key, double score, String member);
|
||||
|
||||
@@ -118,11 +126,11 @@ public interface JedisCommands {
|
||||
|
||||
Long zrevrank(String key, String member);
|
||||
|
||||
Set<String> zrevrange(String key, int start, int end);
|
||||
Set<String> zrevrange(String key, long start, long end);
|
||||
|
||||
Set<Tuple> zrangeWithScores(String key, int start, int end);
|
||||
Set<Tuple> zrangeWithScores(String key, long start, long end);
|
||||
|
||||
Set<Tuple> zrevrangeWithScores(String key, int start, int end);
|
||||
Set<Tuple> zrevrangeWithScores(String key, long start, long end);
|
||||
|
||||
Long zcard(String key);
|
||||
|
||||
@@ -134,13 +142,22 @@ public interface JedisCommands {
|
||||
|
||||
Long zcount(String key, double min, double max);
|
||||
|
||||
Long zcount(String key, String min, String max);
|
||||
|
||||
Set<String> zrangeByScore(String key, double min, double max);
|
||||
|
||||
Set<String> zrangeByScore(String key, String min, String max);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, double max, double min);
|
||||
|
||||
Set<String> zrangeByScore(String key, double min, double max, int offset,
|
||||
int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, String max, String min);
|
||||
|
||||
Set<String> zrangeByScore(String key, String min, String max, int offset,
|
||||
int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
@@ -150,14 +167,47 @@ public interface JedisCommands {
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, String max, String min,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min,
|
||||
int offset, int count);
|
||||
|
||||
Long zremrangeByRank(String key, int start, int end);
|
||||
Long zremrangeByRank(String key, long start, long end);
|
||||
|
||||
Long zremrangeByScore(String key, double start, double end);
|
||||
|
||||
Long zremrangeByScore(String key, String start, String end);
|
||||
|
||||
Long linsert(String key, Client.LIST_POSITION where, String pivot,
|
||||
String value);
|
||||
|
||||
Long lpushx(String key, String... string);
|
||||
|
||||
Long rpushx(String key, String... string);
|
||||
|
||||
List<String> blpop(String arg);
|
||||
|
||||
List<String> brpop(String arg);
|
||||
|
||||
Long del(String key);
|
||||
|
||||
String echo(String string);
|
||||
|
||||
Long move(String key, int dbIndex);
|
||||
|
||||
Long bitcount(final String key);
|
||||
|
||||
Long bitcount(final String key, long start, long end);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.commons.pool.BasePoolableObjectFactory;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
@@ -8,32 +10,66 @@ import redis.clients.util.Pool;
|
||||
|
||||
public class JedisPool extends Pool<Jedis> {
|
||||
|
||||
public JedisPool(final GenericObjectPool.Config poolConfig,
|
||||
final String host) {
|
||||
this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
|
||||
null);
|
||||
public JedisPool(final Config poolConfig, final String host) {
|
||||
this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisPool(String host, int port) {
|
||||
super(new Config(), new JedisFactory(host, port,
|
||||
Protocol.DEFAULT_TIMEOUT, null));
|
||||
this(new Config(), host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisPool(final String host) {
|
||||
URI uri = URI.create(host);
|
||||
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
|
||||
String h = uri.getHost();
|
||||
int port = uri.getPort();
|
||||
String password = uri.getUserInfo().split(":", 2)[1];
|
||||
int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(h, port,
|
||||
Protocol.DEFAULT_TIMEOUT, password, database), new Config());
|
||||
} else {
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(host,
|
||||
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null,
|
||||
Protocol.DEFAULT_DATABASE), new Config());
|
||||
}
|
||||
}
|
||||
|
||||
public JedisPool(final URI uri) {
|
||||
String h = uri.getHost();
|
||||
int port = uri.getPort();
|
||||
String password = uri.getUserInfo().split(":", 2)[1];
|
||||
int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
|
||||
this.internalPool = new GenericObjectPool(new JedisFactory(h, port,
|
||||
Protocol.DEFAULT_TIMEOUT, password, database), new Config());
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, int port,
|
||||
int timeout, final String password) {
|
||||
super(poolConfig, new JedisFactory(host, port, timeout, password));
|
||||
this(poolConfig, host, port, timeout, password, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisPool(final GenericObjectPool.Config poolConfig,
|
||||
final String host, final int port) {
|
||||
this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null);
|
||||
public JedisPool(final Config poolConfig, final String host, final int port) {
|
||||
this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisPool(final GenericObjectPool.Config poolConfig,
|
||||
final String host, final int port, final int timeout) {
|
||||
this(poolConfig, host, port, timeout, null);
|
||||
public JedisPool(final Config poolConfig, final String host, final int port, final int timeout) {
|
||||
this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE);
|
||||
}
|
||||
|
||||
public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password,
|
||||
final int database) {
|
||||
super(poolConfig, new JedisFactory(host, port, timeout, password, database));
|
||||
}
|
||||
|
||||
|
||||
public void returnBrokenResource(final BinaryJedis resource) {
|
||||
returnBrokenResourceObject(resource);
|
||||
}
|
||||
|
||||
public void returnResource(final BinaryJedis resource) {
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* PoolableObjectFactory custom impl.
|
||||
*/
|
||||
@@ -42,14 +78,16 @@ public class JedisPool extends Pool<Jedis> {
|
||||
private final int port;
|
||||
private final int timeout;
|
||||
private final String password;
|
||||
private final int database;
|
||||
|
||||
public JedisFactory(final String host, final int port,
|
||||
final int timeout, final String password) {
|
||||
final int timeout, final String password, final int database) {
|
||||
super();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.timeout = timeout;
|
||||
this.password = password;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public Object makeObject() throws Exception {
|
||||
@@ -59,8 +97,22 @@ public class JedisPool extends Pool<Jedis> {
|
||||
if (null != this.password) {
|
||||
jedis.auth(this.password);
|
||||
}
|
||||
if( database != 0 ) {
|
||||
jedis.select(database);
|
||||
}
|
||||
|
||||
return jedis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateObject(Object obj) throws Exception {
|
||||
if (obj instanceof Jedis) {
|
||||
final Jedis jedis = (Jedis)obj;
|
||||
if (jedis.getDB() != database) {
|
||||
jedis.select(database);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void destroyObject(final Object obj) throws Exception {
|
||||
if (obj instanceof Jedis) {
|
||||
@@ -91,6 +143,5 @@ public class JedisPool extends Pool<Jedis> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import redis.clients.util.ShardInfo;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class JedisShardInfo extends ShardInfo<Jedis> {
|
||||
public String toString() {
|
||||
return host + ":" + port + "*" + getWeight();
|
||||
return host + ":" + port + "*" + getWeight();
|
||||
}
|
||||
|
||||
private int timeout;
|
||||
@@ -15,67 +17,83 @@ public class JedisShardInfo extends ShardInfo<Jedis> {
|
||||
private String name = null;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
return host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
return port;
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host) {
|
||||
this(host, Protocol.DEFAULT_PORT);
|
||||
super(Sharded.DEFAULT_WEIGHT);
|
||||
URI uri = URI.create(host);
|
||||
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
|
||||
this.host = uri.getHost();
|
||||
this.port = uri.getPort();
|
||||
this.password = uri.getUserInfo().split(":", 2)[1];
|
||||
} else {
|
||||
this.host = host;
|
||||
this.port = Protocol.DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, String name) {
|
||||
this(host, Protocol.DEFAULT_PORT, name);
|
||||
this(host, Protocol.DEFAULT_PORT, name);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port) {
|
||||
this(host, port, 2000);
|
||||
this(host, port, 2000);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, String name) {
|
||||
this(host, port, 2000, name);
|
||||
this(host, port, 2000, name);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout) {
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout, String name) {
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
this.name = name;
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout, int weight) {
|
||||
super(weight);
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.timeout = timeout;
|
||||
super(weight);
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public JedisShardInfo(URI uri) {
|
||||
super(Sharded.DEFAULT_WEIGHT);
|
||||
this.host = uri.getHost();
|
||||
this.port = uri.getPort();
|
||||
this.password = uri.getUserInfo().split(":", 2)[1];
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String auth) {
|
||||
this.password = auth;
|
||||
this.password = auth;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis createResource() {
|
||||
return new Jedis(this);
|
||||
return new Jedis(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface MultiKeyBinaryCommands {
|
||||
Long del(byte[]... keys);
|
||||
|
||||
List<byte[]> blpop(int timeout, byte[]... keys);
|
||||
|
||||
List<byte[]> brpop(int timeout, byte[]... keys);
|
||||
|
||||
List<byte[]> blpop(byte[]... args);
|
||||
|
||||
List<byte[]> brpop(byte[]... args);
|
||||
|
||||
Set<byte[]> keys(byte[] pattern);
|
||||
|
||||
List<byte[]> mget(byte[]... keys);
|
||||
|
||||
String mset(byte[]... keysvalues);
|
||||
|
||||
Long msetnx(byte[]... keysvalues);
|
||||
|
||||
String rename(byte[] oldkey, byte[] newkey);
|
||||
|
||||
Long renamenx(byte[] oldkey, byte[] newkey);
|
||||
|
||||
byte[] rpoplpush(byte[] srckey, byte[] dstkey);
|
||||
|
||||
Set<byte[]> sdiff(byte[]... keys);
|
||||
|
||||
Long sdiffstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
Set<byte[]> sinter(byte[]... keys);
|
||||
|
||||
Long sinterstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
Long smove(byte[] srckey, byte[] dstkey, byte[] member);
|
||||
|
||||
Long sort(byte[] key, SortingParams sortingParameters, byte[] dstkey);
|
||||
|
||||
Long sort(byte[] key, byte[] dstkey);
|
||||
|
||||
Set<byte[]> sunion(byte[]... keys);
|
||||
|
||||
Long sunionstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
String watch(byte[]... keys);
|
||||
|
||||
String unwatch();
|
||||
|
||||
Long zinterstore(byte[] dstkey, byte[]... sets);
|
||||
|
||||
Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets);
|
||||
|
||||
Long zunionstore(byte[] dstkey, byte[]... sets);
|
||||
|
||||
Long zunionstore(byte[] dstkey, ZParams params, byte[]... sets);
|
||||
|
||||
byte[] brpoplpush(byte[] source, byte[] destination, int timeout);
|
||||
|
||||
Long publish(byte[] channel, byte[] message);
|
||||
|
||||
void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels);
|
||||
|
||||
void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns);
|
||||
|
||||
byte[] randomBinaryKey();
|
||||
|
||||
Long bitop(BitOP op, final byte[] destKey, byte[]... srcKeys);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multikey related commands (these are split out because they are non-shardable)
|
||||
*/
|
||||
public interface MultiKeyBinaryRedisPipeline {
|
||||
|
||||
Response<Long> del(byte[]... keys);
|
||||
|
||||
Response<List<byte[]>> blpop(byte[]... args);
|
||||
|
||||
Response<List<byte[]>> brpop(byte[]... args);
|
||||
|
||||
Response<Set<byte[]>> keys(byte[] pattern);
|
||||
|
||||
Response<List<byte[]>> mget(byte[]... keys);
|
||||
|
||||
Response<String> mset(byte[]... keysvalues);
|
||||
|
||||
Response<Long> msetnx(byte[]... keysvalues);
|
||||
|
||||
Response<String> rename(byte[] oldkey, byte[] newkey);
|
||||
|
||||
Response<Long> renamenx(byte[] oldkey, byte[] newkey);
|
||||
|
||||
Response<byte[]> rpoplpush(byte[] srckey, byte[] dstkey);
|
||||
|
||||
Response<Set<byte[]>> sdiff(byte[]... keys);
|
||||
|
||||
Response<Long> sdiffstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
Response<Set<byte[]>> sinter(byte[]... keys);
|
||||
|
||||
Response<Long> sinterstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
Response<Long> smove(byte[] srckey, byte[] dstkey, byte[] member);
|
||||
|
||||
Response<Long> sort(byte[] key, SortingParams sortingParameters, byte[] dstkey);
|
||||
|
||||
Response<Long> sort(byte[] key, byte[] dstkey);
|
||||
|
||||
Response<Set<byte[]>> sunion(byte[]... keys);
|
||||
|
||||
Response<Long> sunionstore(byte[] dstkey, byte[]... keys);
|
||||
|
||||
Response<String> watch(byte[]... keys);
|
||||
|
||||
Response<Long> zinterstore(byte[] dstkey, byte[]... sets);
|
||||
|
||||
Response<Long> zinterstore(byte[] dstkey, ZParams params, byte[]... sets);
|
||||
|
||||
Response<Long> zunionstore(byte[] dstkey, byte[]... sets);
|
||||
|
||||
Response<Long> zunionstore(byte[] dstkey, ZParams params, byte[]... sets);
|
||||
|
||||
Response<byte[]> brpoplpush(byte[] source, byte[] destination, int timeout);
|
||||
|
||||
Response<Long> publish(byte[] channel, byte[] message);
|
||||
|
||||
Response<byte[]> randomKeyBinary();
|
||||
|
||||
Response<Long> bitop(BitOP op, final byte[] destKey, byte[]... srcKeys);
|
||||
}
|
||||
73
src/main/java/redis/clients/jedis/MultiKeyCommands.java
Normal file
73
src/main/java/redis/clients/jedis/MultiKeyCommands.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface MultiKeyCommands {
|
||||
Long del(String... keys);
|
||||
|
||||
List<String> blpop(int timeout, String... keys);
|
||||
|
||||
List<String> brpop(int timeout, String... keys);
|
||||
|
||||
List<String> blpop(String... args);
|
||||
|
||||
List<String> brpop(String... args);
|
||||
|
||||
Set<String> keys(String pattern);
|
||||
|
||||
List<String> mget(String... keys);
|
||||
|
||||
String mset(String... keysvalues);
|
||||
|
||||
Long msetnx(String... keysvalues);
|
||||
|
||||
String rename(String oldkey, String newkey);
|
||||
|
||||
Long renamenx(String oldkey, String newkey);
|
||||
|
||||
String rpoplpush(String srckey, String dstkey);
|
||||
|
||||
Set<String> sdiff(String... keys);
|
||||
|
||||
Long sdiffstore(String dstkey, String... keys);
|
||||
|
||||
Set<String> sinter(String... keys);
|
||||
|
||||
Long sinterstore(String dstkey, String... keys);
|
||||
|
||||
Long smove(String srckey, String dstkey, String member);
|
||||
|
||||
Long sort(String key, SortingParams sortingParameters, String dstkey);
|
||||
|
||||
Long sort(String key, String dstkey);
|
||||
|
||||
Set<String> sunion(String... keys);
|
||||
|
||||
Long sunionstore(String dstkey, String... keys);
|
||||
|
||||
String watch(String... keys);
|
||||
|
||||
String unwatch();
|
||||
|
||||
Long zinterstore(String dstkey, String... sets);
|
||||
|
||||
Long zinterstore(String dstkey, ZParams params, String... sets);
|
||||
|
||||
Long zunionstore(String dstkey, String... sets);
|
||||
|
||||
Long zunionstore(String dstkey, ZParams params, String... sets);
|
||||
|
||||
String brpoplpush(String source, String destination, int timeout);
|
||||
|
||||
Long publish(String channel, String message);
|
||||
|
||||
void subscribe(JedisPubSub jedisPubSub, String... channels);
|
||||
|
||||
void psubscribe(JedisPubSub jedisPubSub, String... patterns);
|
||||
|
||||
String randomKey();
|
||||
|
||||
Long bitop(BitOP op, final String destKey, String... srcKeys);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Multikey related commands (these are split out because they are non-shardable)
|
||||
*/
|
||||
public interface MultiKeyCommandsPipeline {
|
||||
Response<Long> del(String... keys);
|
||||
|
||||
Response<List<String>> blpop(String... args);
|
||||
|
||||
Response<List<String>> brpop(String... args);
|
||||
|
||||
Response<Set<String>> keys(String pattern);
|
||||
|
||||
Response<List<String>> mget(String... keys);
|
||||
|
||||
Response<String> mset(String... keysvalues);
|
||||
|
||||
Response<Long> msetnx(String... keysvalues);
|
||||
|
||||
Response<String> rename(String oldkey, String newkey);
|
||||
|
||||
Response<Long> renamenx(String oldkey, String newkey);
|
||||
|
||||
Response<String> rpoplpush(String srckey, String dstkey);
|
||||
|
||||
Response<Set<String>> sdiff(String... keys);
|
||||
|
||||
Response<Long> sdiffstore(String dstkey, String... keys);
|
||||
|
||||
Response<Set<String>> sinter(String... keys);
|
||||
|
||||
Response<Long> sinterstore(String dstkey, String... keys);
|
||||
|
||||
Response<Long> smove(String srckey, String dstkey, String member);
|
||||
|
||||
Response<Long> sort(String key, SortingParams sortingParameters, String dstkey);
|
||||
|
||||
Response<Long> sort(String key, String dstkey);
|
||||
|
||||
Response<Set<String>> sunion(String... keys);
|
||||
|
||||
Response<Long> sunionstore(String dstkey, String... keys);
|
||||
|
||||
Response<String> watch(String... keys);
|
||||
|
||||
Response<Long> zinterstore(String dstkey, String... sets);
|
||||
|
||||
Response<Long> zinterstore(String dstkey, ZParams params, String... sets);
|
||||
|
||||
Response<Long> zunionstore(String dstkey, String... sets);
|
||||
|
||||
Response<Long> zunionstore(String dstkey, ZParams params, String... sets);
|
||||
|
||||
Response<String> brpoplpush(String source, String destination, int timeout);
|
||||
|
||||
Response<Long> publish(String channel, String message);
|
||||
|
||||
Response<String> randomKey();
|
||||
|
||||
Response<Long> bitop(BitOP op, final String destKey, String... srcKeys);
|
||||
}
|
||||
401
src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java
Normal file
401
src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java
Normal file
@@ -0,0 +1,401 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
abstract class MultiKeyPipelineBase extends PipelineBase implements
|
||||
BasicRedisPipeline,
|
||||
MultiKeyBinaryRedisPipeline,
|
||||
MultiKeyCommandsPipeline {
|
||||
|
||||
protected Client client = null;
|
||||
|
||||
public Response<List<String>> brpop(String... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> brpop(int timeout, String... keys) {
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(String... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Map<String, String>> blpopMap(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> brpop(byte[]... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> brpop(int timeout, byte[]... keys) {
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Map<String, String>> brpopMap(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> blpop(byte[]... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(int timeout, byte[]... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> del(String... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> del(byte[]... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> keys(String pattern) {
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> keys(byte[] pattern) {
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<List<String>> mget(String... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> mget(byte[]... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<String> mset(String... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> mset(byte[]... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(String... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(byte[]... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rename(String oldkey, String newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> rename(byte[] oldkey, byte[] newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(String oldkey, String newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(byte[] oldkey, byte[] newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rpoplpush(String srckey, String dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> rpoplpush(byte[] srckey, byte[] dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sdiff(String... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sdiff(byte[]... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(String dstkey, String... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sinter(String... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sinter(byte[]... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(String dstkey, String... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> smove(String srckey, String dstkey, String member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> smove(byte[] srckey, byte[] dstkey, byte[] member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(String key,
|
||||
SortingParams sortingParameters, String dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(byte[] key,
|
||||
SortingParams sortingParameters, byte[] dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(String key, String dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(byte[] key, byte[] dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sunion(String... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sunion(byte[]... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(String dstkey, String... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> watch(String... keys) {
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> watch(byte[]... keys) {
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, String... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, String... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> bgrewriteaof() {
|
||||
client.bgrewriteaof();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> bgsave() {
|
||||
client.bgsave();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configGet(String pattern) {
|
||||
client.configGet(pattern);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configSet(String parameter, String value) {
|
||||
client.configSet(parameter, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> brpoplpush(String source, String destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> brpoplpush(byte[] source, byte[] destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> configResetStat() {
|
||||
client.configResetStat();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> save() {
|
||||
client.save();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> lastsave() {
|
||||
client.lastsave();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(String channel, String message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(byte[] channel, byte[] message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> randomKey() {
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> randomKeyBinary() {
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> flushDB() {
|
||||
client.flushDB();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> flushAll() {
|
||||
client.flushAll();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> info() {
|
||||
client.info();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> dbSize() {
|
||||
client.dbSize();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> shutdown() {
|
||||
client.shutdown();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> ping() {
|
||||
client.ping();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> select(int index) {
|
||||
client.select(index);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> bitop(BitOP op, byte[] destKey, byte[]... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> bitop(BitOP op, String destKey, String... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
}
|
||||
1206
src/main/java/redis/clients/jedis/Pipeline.java
Normal file → Executable file
1206
src/main/java/redis/clients/jedis/Pipeline.java
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1162
src/main/java/redis/clients/jedis/PipelineBase.java
Normal file
1162
src/main/java/redis/clients/jedis/PipelineBase.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ public final class Protocol {
|
||||
|
||||
public static final int DEFAULT_PORT = 6379;
|
||||
public static final int DEFAULT_TIMEOUT = 2000;
|
||||
public static final int DEFAULT_DATABASE = 0;
|
||||
|
||||
public static final String CHARSET = "UTF-8";
|
||||
|
||||
@@ -23,134 +24,153 @@ public final class Protocol {
|
||||
public static final byte MINUS_BYTE = '-';
|
||||
public static final byte COLON_BYTE = ':';
|
||||
|
||||
public void sendCommand(final RedisOutputStream os, final Command command,
|
||||
final byte[]... args) {
|
||||
sendCommand(os, command.raw, args);
|
||||
public static final String SENTINEL_MASTERS = "masters";
|
||||
public static final String SENTINEL_GET_MASTER_ADDR_BY_NAME = "get-master-addr-by-name";
|
||||
public static final String SENTINEL_RESET = "reset";
|
||||
public static final String SENTINEL_SLAVES = "slaves";
|
||||
public static final String SENTINEL_IS_MASTER_DOWN_BY_ADDR = "is-master-down-by-addr";
|
||||
|
||||
private Protocol() {
|
||||
// this prevent the class from instantiation
|
||||
}
|
||||
|
||||
private void sendCommand(final RedisOutputStream os, final byte[] command,
|
||||
final byte[]... args) {
|
||||
try {
|
||||
os.write(ASTERISK_BYTE);
|
||||
os.writeIntCrLf(args.length + 1);
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(command.length);
|
||||
os.write(command);
|
||||
os.writeCrLf();
|
||||
|
||||
for (final byte[] arg : args) {
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(arg.length);
|
||||
os.write(arg);
|
||||
os.writeCrLf();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
public static void sendCommand(final RedisOutputStream os,
|
||||
final Command command, final byte[]... args) {
|
||||
sendCommand(os, command.raw, args);
|
||||
}
|
||||
|
||||
private void processError(final RedisInputStream is) {
|
||||
String message = is.readLine();
|
||||
throw new JedisDataException(message);
|
||||
private static void sendCommand(final RedisOutputStream os,
|
||||
final byte[] command, final byte[]... args) {
|
||||
try {
|
||||
os.write(ASTERISK_BYTE);
|
||||
os.writeIntCrLf(args.length + 1);
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(command.length);
|
||||
os.write(command);
|
||||
os.writeCrLf();
|
||||
|
||||
for (final byte[] arg : args) {
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(arg.length);
|
||||
os.write(arg);
|
||||
os.writeCrLf();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Object process(final RedisInputStream is) {
|
||||
try {
|
||||
byte b = is.readByte();
|
||||
if (b == MINUS_BYTE) {
|
||||
processError(is);
|
||||
} else if (b == ASTERISK_BYTE) {
|
||||
return processMultiBulkReply(is);
|
||||
} else if (b == COLON_BYTE) {
|
||||
return processInteger(is);
|
||||
} else if (b == DOLLAR_BYTE) {
|
||||
return processBulkReply(is);
|
||||
} else if (b == PLUS_BYTE) {
|
||||
return processStatusCodeReply(is);
|
||||
} else {
|
||||
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
return null;
|
||||
private static void processError(final RedisInputStream is) {
|
||||
String message = is.readLine();
|
||||
throw new JedisDataException(message);
|
||||
}
|
||||
|
||||
private byte[] processStatusCodeReply(final RedisInputStream is) {
|
||||
return SafeEncoder.encode(is.readLine());
|
||||
private static Object process(final RedisInputStream is) {
|
||||
try {
|
||||
byte b = is.readByte();
|
||||
if (b == MINUS_BYTE) {
|
||||
processError(is);
|
||||
} else if (b == ASTERISK_BYTE) {
|
||||
return processMultiBulkReply(is);
|
||||
} else if (b == COLON_BYTE) {
|
||||
return processInteger(is);
|
||||
} else if (b == DOLLAR_BYTE) {
|
||||
return processBulkReply(is);
|
||||
} else if (b == PLUS_BYTE) {
|
||||
return processStatusCodeReply(is);
|
||||
} else {
|
||||
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private byte[] processBulkReply(final RedisInputStream is) {
|
||||
int len = Integer.parseInt(is.readLine());
|
||||
if (len == -1) {
|
||||
return null;
|
||||
}
|
||||
byte[] read = new byte[len];
|
||||
int offset = 0;
|
||||
try {
|
||||
while (offset < len) {
|
||||
offset += is.read(read, offset, (len - offset));
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
is.readByte();
|
||||
is.readByte();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
|
||||
return read;
|
||||
private static byte[] processStatusCodeReply(final RedisInputStream is) {
|
||||
return SafeEncoder.encode(is.readLine());
|
||||
}
|
||||
|
||||
private Long processInteger(final RedisInputStream is) {
|
||||
String num = is.readLine();
|
||||
return Long.valueOf(num);
|
||||
private static byte[] processBulkReply(final RedisInputStream is) {
|
||||
int len = Integer.parseInt(is.readLine());
|
||||
if (len == -1) {
|
||||
return null;
|
||||
}
|
||||
byte[] read = new byte[len];
|
||||
int offset = 0;
|
||||
try {
|
||||
while (offset < len) {
|
||||
offset += is.read(read, offset, (len - offset));
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
is.readByte();
|
||||
is.readByte();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
private List<Object> processMultiBulkReply(final RedisInputStream is) {
|
||||
int num = Integer.parseInt(is.readLine());
|
||||
if (num == -1) {
|
||||
return null;
|
||||
}
|
||||
List<Object> ret = new ArrayList<Object>(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
ret.add(process(is));
|
||||
}
|
||||
return ret;
|
||||
private static Long processInteger(final RedisInputStream is) {
|
||||
String num = is.readLine();
|
||||
return Long.valueOf(num);
|
||||
}
|
||||
|
||||
public Object read(final RedisInputStream is) {
|
||||
return process(is);
|
||||
private static List<Object> processMultiBulkReply(final RedisInputStream is) {
|
||||
int num = Integer.parseInt(is.readLine());
|
||||
if (num == -1) {
|
||||
return null;
|
||||
}
|
||||
List<Object> ret = new ArrayList<Object>(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
try {
|
||||
ret.add(process(is));
|
||||
} catch (JedisDataException e) {
|
||||
ret.add(e);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Object read(final RedisInputStream is) {
|
||||
return process(is);
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final boolean value) {
|
||||
return toByteArray(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final int value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final long value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static final byte[] toByteArray(final double value) {
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
return SafeEncoder.encode(String.valueOf(value));
|
||||
}
|
||||
|
||||
public static enum Command {
|
||||
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE;
|
||||
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL,
|
||||
DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT;
|
||||
|
||||
public final byte[] raw;
|
||||
public final byte[] raw;
|
||||
|
||||
Command() {
|
||||
raw = SafeEncoder.encode(this.name());
|
||||
}
|
||||
Command() {
|
||||
raw = SafeEncoder.encode(this.name());
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Keyword {
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT;
|
||||
public final byte[] raw;
|
||||
|
||||
Keyword() {
|
||||
raw = SafeEncoder.encode(this.name().toLowerCase());
|
||||
}
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT,
|
||||
GETNAME, SETNAME,LIST;
|
||||
public final byte[] raw;
|
||||
|
||||
Keyword() {
|
||||
raw = SafeEncoder.encode(this.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
200
src/main/java/redis/clients/jedis/RedisPipeline.java
Normal file
200
src/main/java/redis/clients/jedis/RedisPipeline.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author guy
|
||||
*/
|
||||
public interface RedisPipeline {
|
||||
Response<Long> append(String key, String value);
|
||||
|
||||
Response<List<String>> blpop(String arg);
|
||||
|
||||
Response<List<String>> brpop(String arg);
|
||||
|
||||
Response<Long> decr(String key);
|
||||
|
||||
Response<Long> decrBy(String key, long integer);
|
||||
|
||||
Response<Long> del(String key);
|
||||
|
||||
Response<String> echo(String string);
|
||||
|
||||
Response<Boolean> exists(String key);
|
||||
|
||||
Response<Long> expire(String key, int seconds);
|
||||
|
||||
Response<Long> expireAt(String key, long unixTime);
|
||||
|
||||
Response<String> get(String key);
|
||||
|
||||
Response<Boolean> getbit(String key, long offset);
|
||||
|
||||
|
||||
|
||||
Response<String> getrange(String key, long startOffset,
|
||||
long endOffset);
|
||||
|
||||
Response<String> getSet(String key, String value);
|
||||
|
||||
Response<Long> hdel(String key, String... field);
|
||||
|
||||
Response<Boolean> hexists(String key, String field);
|
||||
|
||||
Response<String> hget(String key, String field);
|
||||
|
||||
Response<Map<String, String>> hgetAll(String key);
|
||||
|
||||
Response<Long> hincrBy(String key, String field, long value);
|
||||
|
||||
Response<Set<String>> hkeys(String key);
|
||||
|
||||
Response<Long> hlen(String key);
|
||||
|
||||
Response<List<String>> hmget(String key, String... fields);
|
||||
|
||||
Response<String> hmset(String key, Map<String, String> hash);
|
||||
|
||||
Response<Long> hset(String key, String field, String value);
|
||||
|
||||
Response<Long> hsetnx(String key, String field, String value);
|
||||
|
||||
Response<List<String>> hvals(String key);
|
||||
|
||||
Response<Long> incr(String key);
|
||||
|
||||
Response<Long> incrBy(String key, long integer);
|
||||
|
||||
Response<String> lindex(String key, long index);
|
||||
|
||||
Response<Long> linsert(String key, BinaryClient.LIST_POSITION where,
|
||||
String pivot, String value);
|
||||
|
||||
Response<Long> llen(String key);
|
||||
|
||||
Response<String> lpop(String key);
|
||||
|
||||
Response<Long> lpush(String key, String... string);
|
||||
|
||||
Response<Long> lpushx(String key, String... string);
|
||||
|
||||
Response<List<String>> lrange(String key, long start, long end);
|
||||
|
||||
Response<Long> lrem(String key, long count, String value);
|
||||
|
||||
Response<String> lset(String key, long index, String value);
|
||||
|
||||
Response<String> ltrim(String key, long start, long end);
|
||||
|
||||
Response<Long> move(String key, int dbIndex);
|
||||
|
||||
Response<Long> persist(String key);
|
||||
|
||||
Response<String> rpop(String key);
|
||||
|
||||
Response<Long> rpush(String key, String... string);
|
||||
|
||||
Response<Long> rpushx(String key, String... string);
|
||||
|
||||
Response<Long> sadd(String key, String... member);
|
||||
|
||||
Response<Long> scard(String key);
|
||||
|
||||
Response<Boolean> sismember(String key, String member);
|
||||
|
||||
Response<String> set(String key, String value);
|
||||
|
||||
Response<Boolean> setbit(String key, long offset, boolean value);
|
||||
|
||||
Response<String> setex(String key, int seconds, String value);
|
||||
|
||||
Response<Long> setnx(String key, String value);
|
||||
|
||||
Response<Long> setrange(String key, long offset, String value);
|
||||
|
||||
Response<Set<String>> smembers(String key);
|
||||
|
||||
Response<List<String>> sort(String key);
|
||||
|
||||
Response<List<String>> sort(String key,
|
||||
SortingParams sortingParameters);
|
||||
|
||||
Response<String> spop(String key);
|
||||
|
||||
Response<String> srandmember(String key);
|
||||
|
||||
Response<Long> srem(String key, String... member);
|
||||
|
||||
Response<Long> strlen(String key);
|
||||
|
||||
Response<String> substr(String key, int start, int end);
|
||||
|
||||
Response<Long> ttl(String key);
|
||||
|
||||
Response<String> type(String key);
|
||||
|
||||
Response<Long> zadd(String key, double score, String member);
|
||||
|
||||
Response<Long> zcard(String key);
|
||||
|
||||
Response<Long> zcount(String key, double min, double max);
|
||||
|
||||
Response<Double> zincrby(String key, double score, String member);
|
||||
|
||||
Response<Set<String>> zrange(String key, long start, long end);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, String min,
|
||||
String max);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
double min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, String max,
|
||||
String min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
double min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
|
||||
double max, double min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
|
||||
double max, double min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeWithScores(String key, long start, long end);
|
||||
|
||||
Response<Long> zrank(String key, String member);
|
||||
|
||||
Response<Long> zrem(String key, String... member);
|
||||
|
||||
Response<Long> zremrangeByRank(String key, long start, long end);
|
||||
|
||||
Response<Long> zremrangeByScore(String key, double start, double end);
|
||||
|
||||
Response<Set<String>> zrevrange(String key, long start, long end);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeWithScores(String key, long start,
|
||||
long end);
|
||||
|
||||
Response<Long> zrevrank(String key, String member);
|
||||
|
||||
Response<Double> zscore(String key, String member);
|
||||
|
||||
Response<Long> bitcount(String key);
|
||||
|
||||
Response<Long> bitcount(String key, long start, long end);
|
||||
}
|
||||
@@ -24,7 +24,12 @@ public class Response<T> {
|
||||
"Please close pipeline or multi block before calling this method.");
|
||||
}
|
||||
if (!built) {
|
||||
response = builder.build(data);
|
||||
if(data != null ){
|
||||
if (data instanceof JedisDataException){
|
||||
throw new JedisDataException((JedisDataException)data);
|
||||
}
|
||||
response = builder.build(data);
|
||||
}
|
||||
this.data = null;
|
||||
built = true;
|
||||
}
|
||||
|
||||
23
src/main/java/redis/clients/jedis/ScriptingCommands.java
Normal file
23
src/main/java/redis/clients/jedis/ScriptingCommands.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ScriptingCommands {
|
||||
Object eval(String script, int keyCount, String... params);
|
||||
|
||||
Object eval(String script, List<String> keys, List<String> args);
|
||||
|
||||
Object eval(String script);
|
||||
|
||||
Object evalsha(String script);
|
||||
|
||||
Object evalsha(String sha1, List<String> keys, List<String> args);
|
||||
|
||||
Object evalsha(String sha1, int keyCount, String... params);
|
||||
|
||||
Boolean scriptExists(String sha1);
|
||||
|
||||
List<Boolean> scriptExists(String... sha1);
|
||||
|
||||
String scriptLoad(String script);
|
||||
}
|
||||
@@ -1,416 +1,526 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
|
||||
public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
public ShardedJedis(List<JedisShardInfo> shards) {
|
||||
super(shards);
|
||||
super(shards);
|
||||
}
|
||||
|
||||
public ShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
|
||||
super(shards, algo);
|
||||
super(shards, algo);
|
||||
}
|
||||
|
||||
public ShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
|
||||
super(shards, keyTagPattern);
|
||||
super(shards, keyTagPattern);
|
||||
}
|
||||
|
||||
public ShardedJedis(List<JedisShardInfo> shards, Hashing algo,
|
||||
Pattern keyTagPattern) {
|
||||
super(shards, algo, keyTagPattern);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
for (Jedis jedis : getAllShards()) {
|
||||
jedis.quit();
|
||||
jedis.disconnect();
|
||||
}
|
||||
Pattern keyTagPattern) {
|
||||
super(shards, algo, keyTagPattern);
|
||||
}
|
||||
|
||||
public String set(String key, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.set(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.set(key, value);
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.get(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.get(key);
|
||||
}
|
||||
|
||||
public String echo(String string) {
|
||||
Jedis j = getShard(string);
|
||||
return j.echo(string);
|
||||
}
|
||||
|
||||
public Boolean exists(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.exists(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.exists(key);
|
||||
}
|
||||
|
||||
public String type(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.type(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.type(key);
|
||||
}
|
||||
|
||||
public Long expire(String key, int seconds) {
|
||||
Jedis j = getShard(key);
|
||||
return j.expire(key, seconds);
|
||||
Jedis j = getShard(key);
|
||||
return j.expire(key, seconds);
|
||||
}
|
||||
|
||||
public Long expireAt(String key, long unixTime) {
|
||||
Jedis j = getShard(key);
|
||||
return j.expireAt(key, unixTime);
|
||||
Jedis j = getShard(key);
|
||||
return j.expireAt(key, unixTime);
|
||||
}
|
||||
|
||||
public Long ttl(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.ttl(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.ttl(key);
|
||||
}
|
||||
|
||||
public boolean setbit(String key, long offset, boolean value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
public Boolean setbit(String key, long offset, boolean value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
}
|
||||
|
||||
public boolean getbit(String key, long offset) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getbit(key, offset);
|
||||
public Boolean setbit(String key, long offset, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
}
|
||||
|
||||
public long setrange(String key, long offset, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setrange(key, offset, value);
|
||||
public Boolean getbit(String key, long offset) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getbit(key, offset);
|
||||
}
|
||||
|
||||
public Long setrange(String key, long offset, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setrange(key, offset, value);
|
||||
}
|
||||
|
||||
public String getrange(String key, long startOffset, long endOffset) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getrange(key, startOffset, endOffset);
|
||||
Jedis j = getShard(key);
|
||||
return j.getrange(key, startOffset, endOffset);
|
||||
}
|
||||
|
||||
public String getSet(String key, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.getSet(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.getSet(key, value);
|
||||
}
|
||||
|
||||
public Long setnx(String key, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setnx(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.setnx(key, value);
|
||||
}
|
||||
|
||||
public String setex(String key, int seconds, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setex(key, seconds, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.setex(key, seconds, value);
|
||||
}
|
||||
|
||||
public List<String> blpop(String arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.blpop(arg);
|
||||
}
|
||||
|
||||
public List<String> brpop(String arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.brpop(arg);
|
||||
}
|
||||
|
||||
public Long decrBy(String key, long integer) {
|
||||
Jedis j = getShard(key);
|
||||
return j.decrBy(key, integer);
|
||||
Jedis j = getShard(key);
|
||||
return j.decrBy(key, integer);
|
||||
}
|
||||
|
||||
public Long decr(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.decr(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.decr(key);
|
||||
}
|
||||
|
||||
public Long incrBy(String key, long integer) {
|
||||
Jedis j = getShard(key);
|
||||
return j.incrBy(key, integer);
|
||||
Jedis j = getShard(key);
|
||||
return j.incrBy(key, integer);
|
||||
}
|
||||
|
||||
public Long incr(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.incr(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.incr(key);
|
||||
}
|
||||
|
||||
public Long append(String key, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.append(key, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.append(key, value);
|
||||
}
|
||||
|
||||
public String substr(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.substr(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.substr(key, start, end);
|
||||
}
|
||||
|
||||
public Long hset(String key, String field, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hset(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hset(key, field, value);
|
||||
}
|
||||
|
||||
public String hget(String key, String field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hget(key, field);
|
||||
Jedis j = getShard(key);
|
||||
return j.hget(key, field);
|
||||
}
|
||||
|
||||
public Long hsetnx(String key, String field, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hsetnx(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hsetnx(key, field, value);
|
||||
}
|
||||
|
||||
public String hmset(String key, Map<String, String> hash) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hmset(key, hash);
|
||||
Jedis j = getShard(key);
|
||||
return j.hmset(key, hash);
|
||||
}
|
||||
|
||||
public List<String> hmget(String key, String... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hmget(key, fields);
|
||||
Jedis j = getShard(key);
|
||||
return j.hmget(key, fields);
|
||||
}
|
||||
|
||||
public Long hincrBy(String key, String field, long value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hincrBy(key, field, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.hincrBy(key, field, value);
|
||||
}
|
||||
|
||||
public Boolean hexists(String key, String field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hexists(key, field);
|
||||
Jedis j = getShard(key);
|
||||
return j.hexists(key, field);
|
||||
}
|
||||
|
||||
public Long del(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.del(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.del(key);
|
||||
}
|
||||
|
||||
public Long hdel(String key, String field) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, field);
|
||||
public Long hdel(String key, String... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, fields);
|
||||
}
|
||||
|
||||
public Long hlen(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hlen(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hlen(key);
|
||||
}
|
||||
|
||||
public Set<String> hkeys(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public List<String> hvals(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
public Map<String, String> hgetAll(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hgetAll(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.hgetAll(key);
|
||||
}
|
||||
|
||||
public Long rpush(String key, String string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, string);
|
||||
public Long rpush(String key, String... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, strings);
|
||||
}
|
||||
|
||||
public Long lpush(String key, String string) {
|
||||
public Long lpush(String key, String... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, strings);
|
||||
}
|
||||
|
||||
public Long lpushx(String key, String... string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpushx(key, string);
|
||||
}
|
||||
|
||||
public Long strlen(final String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.strlen(key);
|
||||
}
|
||||
|
||||
public Long move(String key, int dbIndex) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, string);
|
||||
return j.move(key, dbIndex);
|
||||
}
|
||||
|
||||
public Long rpushx(String key, String... string) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpushx(key, string);
|
||||
}
|
||||
|
||||
public Long persist(final String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.persist(key);
|
||||
}
|
||||
|
||||
public Long llen(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.llen(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.llen(key);
|
||||
}
|
||||
|
||||
public List<String> lrange(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrange(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.lrange(key, start, end);
|
||||
}
|
||||
|
||||
public String ltrim(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.ltrim(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.ltrim(key, start, end);
|
||||
}
|
||||
|
||||
public String lindex(String key, long index) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lindex(key, index);
|
||||
Jedis j = getShard(key);
|
||||
return j.lindex(key, index);
|
||||
}
|
||||
|
||||
public String lset(String key, long index, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lset(key, index, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.lset(key, index, value);
|
||||
}
|
||||
|
||||
public Long lrem(String key, long count, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lrem(key, count, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.lrem(key, count, value);
|
||||
}
|
||||
|
||||
public String lpop(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.lpop(key);
|
||||
}
|
||||
|
||||
public String rpop(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.rpop(key);
|
||||
}
|
||||
|
||||
public Long sadd(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, member);
|
||||
public Long sadd(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, members);
|
||||
}
|
||||
|
||||
public Set<String> smembers(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.smembers(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.smembers(key);
|
||||
}
|
||||
|
||||
public Long srem(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, member);
|
||||
public Long srem(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, members);
|
||||
}
|
||||
|
||||
public String spop(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.spop(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.spop(key);
|
||||
}
|
||||
|
||||
public Long scard(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.scard(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.scard(key);
|
||||
}
|
||||
|
||||
public Boolean sismember(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sismember(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.sismember(key, member);
|
||||
}
|
||||
|
||||
public String srandmember(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srandmember(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.srandmember(key);
|
||||
}
|
||||
|
||||
public Long zadd(String key, double score, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, score, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, score, member);
|
||||
}
|
||||
|
||||
public Set<String> zrange(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
public Long zadd(String key, Map<Double, String> scoreMembers) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, scoreMembers);
|
||||
}
|
||||
|
||||
public Long zrem(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, member);
|
||||
public Set<String> zrange(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
}
|
||||
|
||||
public Long zrem(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, members);
|
||||
}
|
||||
|
||||
public Double zincrby(String key, double score, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zincrby(key, score, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zincrby(key, score, member);
|
||||
}
|
||||
|
||||
public Long zrank(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrank(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrank(key, member);
|
||||
}
|
||||
|
||||
public Long zrevrank(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrank(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrank(key, member);
|
||||
}
|
||||
|
||||
public Set<String> zrevrange(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrange(key, start, end);
|
||||
public Set<String> zrevrange(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrange(key, start, end);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeWithScores(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeWithScores(key, start, end);
|
||||
public Set<Tuple> zrangeWithScores(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeWithScores(key, start, end);
|
||||
public Set<Tuple> zrevrangeWithScores(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Long zcard(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcard(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.zcard(key);
|
||||
}
|
||||
|
||||
public Double zscore(String key, String member) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zscore(key, member);
|
||||
Jedis j = getShard(key);
|
||||
return j.zscore(key, member);
|
||||
}
|
||||
|
||||
public List<String> sort(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key);
|
||||
}
|
||||
|
||||
public List<String> sort(String key, SortingParams sortingParameters) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key, sortingParameters);
|
||||
Jedis j = getShard(key);
|
||||
return j.sort(key, sortingParameters);
|
||||
}
|
||||
|
||||
public Long zcount(String key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
}
|
||||
|
||||
public Long zcount(String key, String min, String max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zcount(key, min, max);
|
||||
}
|
||||
|
||||
public Set<String> zrangeByScore(String key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(String key, double max, double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public Set<String> zrangeByScore(String key, double min, double max,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(String key, double max, double min,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max,
|
||||
double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
double max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max,
|
||||
double min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
double min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Long zremrangeByRank(String key, int start, int end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByRank(key, start, end);
|
||||
public Set<String> zrangeByScore(String key, String min, String max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(String key, String max, String min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min);
|
||||
}
|
||||
|
||||
public Set<String> zrangeByScore(String key, String min, String max,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<String> zrevrangeByScore(String key, String max, String min,
|
||||
int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max,
|
||||
String min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(String key, String min,
|
||||
String max, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max,
|
||||
String min, int offset, int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Long zremrangeByRank(String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByRank(key, start, end);
|
||||
}
|
||||
|
||||
public Long zremrangeByScore(String key, double start, double end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
}
|
||||
|
||||
public Long zremrangeByScore(String key, String start, String end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
}
|
||||
|
||||
public Long linsert(String key, LIST_POSITION where, String pivot,
|
||||
String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.linsert(key, where, pivot, value);
|
||||
String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.linsert(key, where, pivot, value);
|
||||
}
|
||||
|
||||
public Long bitcount(final String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.bitcount(key);
|
||||
}
|
||||
|
||||
public Long bitcount(final String key, long start, long end) {
|
||||
Jedis j = getShard(key);
|
||||
return j.bitcount(key, start, end);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public abstract class ShardedJedisPipeline {
|
||||
public class ShardedJedisPipeline extends PipelineBase {
|
||||
private BinaryShardedJedis jedis;
|
||||
private List<FutureResult> results = new ArrayList<FutureResult>();
|
||||
private Queue<Client> clients = new LinkedList<Client>();
|
||||
|
||||
private class FutureResult {
|
||||
private static class FutureResult {
|
||||
private Client client;
|
||||
|
||||
public FutureResult(Client client) {
|
||||
@@ -26,429 +26,6 @@ public abstract class ShardedJedisPipeline {
|
||||
this.jedis = jedis;
|
||||
}
|
||||
|
||||
protected void set(String key, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.set(key, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void get(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.get(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void exists(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.exists(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void type(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.type(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void expire(String key, int seconds) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.expire(key, seconds);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void expireAt(String key, long unixTime) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.expireAt(key, unixTime);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void ttl(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.ttl(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void getSet(String key, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.getSet(key, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void setnx(String key, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.setnx(key, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void setex(String key, int seconds, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.setex(key, seconds, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void decrBy(String key, int integer) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.decrBy(key, integer);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void decr(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.decr(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void incrBy(String key, int integer) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.incrBy(key, integer);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void incr(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.incr(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void append(String key, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.append(key, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void substr(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.substr(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hset(String key, String field, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hset(key, field, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hget(String key, String field) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hget(key, field);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hsetnx(String key, String field, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hsetnx(key, field, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hmset(String key, Map<String, String> hash) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hmset(key, hash);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hmget(String key, String... fields) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hmget(key, fields);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hincrBy(String key, String field, int value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hincrBy(key, field, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hexists(String key, String field) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hexists(key, field);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hdel(String key, String field) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hdel(key, field);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hlen(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hlen(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hkeys(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hkeys(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hvals(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hvals(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void hgetAll(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.hgetAll(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void rpush(String key, String string) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.rpush(key, string);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lpush(String key, String string) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lpush(key, string);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void llen(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.llen(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lrange(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lrange(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void ltrim(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.ltrim(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lindex(String key, int index) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lindex(key, index);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lset(String key, int index, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lset(key, index, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lrem(String key, int count, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lrem(key, count, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void lpop(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.lpop(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void rpop(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.rpop(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void sadd(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.sadd(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void smembers(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.smembers(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void srem(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.srem(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void spop(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.spop(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void scard(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.scard(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void sismember(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.sismember(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void srandmember(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.srandmember(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zadd(String key, double score, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zadd(key, score, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrange(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrange(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrem(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrem(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zincrby(String key, double score, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zincrby(key, score, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrank(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrank(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrevrank(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrevrank(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrevrange(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrevrange(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrangeWithScores(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrangeWithScores(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrevrangeWithScores(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrevrangeWithScores(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zcard(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zcard(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zscore(String key, String member) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zscore(key, member);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void sort(String key) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.sort(key);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void sort(String key, SortingParams sortingParameters) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.sort(key, sortingParameters);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zcount(String key, double min, double max) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zcount(key, min, max);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrangeByScore(String key, double min, double max) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrangeByScore(key, min, max);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrangeByScore(String key, double min, double max,
|
||||
int offset, int count) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrangeByScore(key, min, max, offset, count);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrangeByScoreWithScores(String key, double min, double max) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrangeByScoreWithScores(key, min, max);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zrangeByScoreWithScores(String key, double min, double max,
|
||||
int offset, int count) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zremrangeByRank(String key, int start, int end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zremrangeByRank(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void zremrangeByScore(String key, double start, double end) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.zremrangeByScore(key, start, end);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void linsert(String key, LIST_POSITION where, String pivot,
|
||||
String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.linsert(key, where, pivot, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
protected void getbit(String key, long offset) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.getbit(key, offset);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
public void setbit(String key, long offset, boolean value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.setbit(key, offset, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
public void setrange(String key, long offset, String value) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.setrange(key, offset, value);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
public void getrange(String key, long startOffset, long endOffset) {
|
||||
Client c = jedis.getShard(key).getClient();
|
||||
c.getrange(key, startOffset, endOffset);
|
||||
results.add(new FutureResult(c));
|
||||
}
|
||||
|
||||
public List<Object> getResults() {
|
||||
List<Object> r = new ArrayList<Object>();
|
||||
for (FutureResult fr : results) {
|
||||
@@ -457,5 +34,54 @@ public abstract class ShardedJedisPipeline {
|
||||
return r;
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
/**
|
||||
* Syncronize pipeline by reading all responses. This operation closes the
|
||||
* pipeline. In order to get return values from pipelined commands, capture
|
||||
* the different Response<?> of the commands you execute.
|
||||
*/
|
||||
public void sync() {
|
||||
for (Client client : clients) {
|
||||
generateResponse(client.getOne());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncronize pipeline by reading all responses. This operation closes the
|
||||
* pipeline. Whenever possible try to avoid using this version and use
|
||||
* ShardedJedisPipeline.sync() as it won't go through all the responses and generate the
|
||||
* right response type (usually it is a waste of time).
|
||||
*
|
||||
* @return A list of all the responses in the order you executed them.
|
||||
*/
|
||||
public List<Object> syncAndReturnAll() {
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Client client : clients) {
|
||||
formatted.add(generateResponse(client.getOne()).get());
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be removed in Jedis 3.0. Use the methods that return Response's and call
|
||||
* sync().
|
||||
*/
|
||||
@Deprecated
|
||||
public void execute() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(String key) {
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(byte[] key) {
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@@ -1,580 +1,75 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class Transaction extends BinaryTransaction {
|
||||
public Transaction() {
|
||||
/**
|
||||
* Transaction is nearly identical to Pipeline, only differences are the multi/discard behaviors
|
||||
*/
|
||||
public class Transaction extends MultiKeyPipelineBase {
|
||||
|
||||
protected boolean inTransaction = true;
|
||||
|
||||
protected Transaction(){
|
||||
// client will be set later in transaction block
|
||||
}
|
||||
|
||||
public Transaction(final Client client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
public Response<Long> append(String key, String value) {
|
||||
client.append(key, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(String... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> brpop(String... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> decr(String key) {
|
||||
client.decr(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> decrBy(String key, long integer) {
|
||||
client.decrBy(key, integer);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> del(String... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> echo(String string) {
|
||||
client.echo(string);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Boolean> exists(String key) {
|
||||
client.exists(key);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<Long> expire(String key, int seconds) {
|
||||
client.expire(key, seconds);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> expireAt(String key, long unixTime) {
|
||||
client.expireAt(key, unixTime);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> get(String key) {
|
||||
client.get(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Boolean> getbit(String key, long offset) {
|
||||
client.getbit(key, offset);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<String> getrange(String key, long startOffset,
|
||||
long endOffset) {
|
||||
client.getrange(key, startOffset, endOffset);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> getSet(String key, String value) {
|
||||
client.getSet(key, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> hdel(String key, String field) {
|
||||
client.hdel(key, field);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Boolean> hexists(String key, String field) {
|
||||
client.hexists(key, field);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<String> hget(String key, String field) {
|
||||
client.hget(key, field);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Map<String, String>> hgetAll(String key) {
|
||||
client.hgetAll(key);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<Long> hincrBy(String key, String field, long value) {
|
||||
client.hincrBy(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> hkeys(String key) {
|
||||
client.hkeys(key);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Long> hlen(String key) {
|
||||
client.hlen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> hmget(String key, String... fields) {
|
||||
client.hmget(key, fields);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<String> hmset(String key, Map<String, String> hash) {
|
||||
client.hmset(key, hash);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> hset(String key, String field, String value) {
|
||||
client.hset(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> hsetnx(String key, String field, String value) {
|
||||
client.hsetnx(key, field, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> hvals(String key) {
|
||||
client.hvals(key);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> incr(String key) {
|
||||
client.incr(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> incrBy(String key, long integer) {
|
||||
client.incrBy(key, integer);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> keys(String pattern) {
|
||||
client.keys(pattern);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<String> lindex(String key, int index) {
|
||||
client.lindex(key, index);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> linsert(String key, LIST_POSITION where,
|
||||
String pivot, String value) {
|
||||
client.linsert(key, where, pivot, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> llen(String key) {
|
||||
client.llen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> lpop(String key) {
|
||||
client.lpop(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> lpush(String key, String string) {
|
||||
client.lpush(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> lpushx(String key, String string) {
|
||||
client.lpushx(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> lrange(String key, long start, long end) {
|
||||
client.lrange(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> lrem(String key, long count, String value) {
|
||||
client.lrem(key, count, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> lset(String key, long index, String value) {
|
||||
client.lset(key, index, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> ltrim(String key, long start, long end) {
|
||||
client.ltrim(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<String>> mget(String... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> move(String key, int dbIndex) {
|
||||
client.move(key, dbIndex);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> mset(String... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(String... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> persist(String key) {
|
||||
client.persist(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rename(String oldkey, String newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(String oldkey, String newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rpop(String key) {
|
||||
client.rpop(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> rpoplpush(String srckey, String dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> rpush(String key, String string) {
|
||||
client.rpush(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> rpushx(String key, String string) {
|
||||
client.rpushx(key, string);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sadd(String key, String member) {
|
||||
client.sadd(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> scard(String key) {
|
||||
client.scard(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sdiff(String... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(String dstkey, String... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> set(String key, String value) {
|
||||
client.set(key, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Boolean> setbit(String key, long offset, boolean value) {
|
||||
client.setbit(key, offset, value);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<String> setex(String key, int seconds, String value) {
|
||||
client.setex(key, seconds, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> setnx(String key, String value) {
|
||||
client.setnx(key, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> setrange(String key, long offset, String value) {
|
||||
client.setrange(key, offset, value);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sinter(String... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(String dstkey, String... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Boolean> sismember(String key, String member) {
|
||||
client.sismember(key, member);
|
||||
return getResponse(BuilderFactory.BOOLEAN);
|
||||
}
|
||||
|
||||
public Response<Set<String>> smembers(String key) {
|
||||
client.smembers(key);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Long> smove(String srckey, String dstkey, String member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key) {
|
||||
client.sort(key);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key,
|
||||
SortingParams sortingParameters) {
|
||||
client.sort(key, sortingParameters);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key,
|
||||
SortingParams sortingParameters, String dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key, String dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<String> spop(String key) {
|
||||
client.spop(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> srandmember(String key) {
|
||||
client.srandmember(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> srem(String key, String member) {
|
||||
client.srem(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> strlen(String key) {
|
||||
client.strlen(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> substr(String key, int start, int end) {
|
||||
client.substr(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sunion(String... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(String dstkey, String... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> ttl(String key) {
|
||||
client.ttl(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> type(String key) {
|
||||
client.type(key);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> zadd(String key, double score, String member) {
|
||||
client.zadd(key, score, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zcard(String key) {
|
||||
client.zcard(key);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zcount(String key, double min, double max) {
|
||||
client.zcount(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Double> zincrby(String key, double score, String member) {
|
||||
client.zincrby(key, score, member);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, String... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrange(String key, int start, int end) {
|
||||
client.zrange(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max) {
|
||||
client.zrangeByScore(key, min, max);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrangeByScore(String key, String min,
|
||||
String max) {
|
||||
client.zrangeByScore(key, min, max);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max, int offset, int count) {
|
||||
client.zrangeByScore(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max) {
|
||||
client.zrangeByScoreWithScores(key, min, max);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count) {
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeWithScores(String key, int start, int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> zrank(String key, String member) {
|
||||
client.zrank(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zrem(String key, String member) {
|
||||
client.zrem(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zremrangeByRank(String key, int start, int end) {
|
||||
client.zremrangeByRank(key, start, end);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zremrangeByScore(String key, double start, double end) {
|
||||
client.zremrangeByScore(key, start, end);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrevrange(String key, int start, int end) {
|
||||
client.zrevrange(key, start, end);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrevrangeWithScores(String key, int start,
|
||||
int end) {
|
||||
client.zrevrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> zrevrank(String key, String member) {
|
||||
client.zrevrank(key, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Double> zscore(String key, String member) {
|
||||
client.zscore(key, member);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, String... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> bgrewriteaof() {
|
||||
client.bgrewriteaof();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> bgsave() {
|
||||
client.bgsave();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configGet(String pattern) {
|
||||
client.configGet(pattern);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configSet(String parameter, String value) {
|
||||
client.configSet(parameter, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> brpoplpush(String source, String destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configResetStat() {
|
||||
client.configResetStat();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> save() {
|
||||
client.save();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> lastsave() {
|
||||
client.lastsave();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(String channel, String message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(byte[] channel, byte[] message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(String key) {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(byte[] key) {
|
||||
return client;
|
||||
}
|
||||
|
||||
public List<Object> exec() {
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public List<Response<?>> execGetResponse() {
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Response<?>> response = new ArrayList<Response<?>>();
|
||||
for (Object o : unformatted) {
|
||||
response.add(generateResponse(o));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public String discard() {
|
||||
client.discard();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
inTransaction = false;
|
||||
clean();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,6 @@ public abstract class TransactionBlock extends Transaction {
|
||||
public abstract void execute() throws JedisException;
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
|
||||
return internalMap.values();
|
||||
}
|
||||
|
||||
private final class ByteArrayWrapper {
|
||||
private static final class ByteArrayWrapper {
|
||||
private final byte[] data;
|
||||
|
||||
public ByteArrayWrapper(byte[] data) {
|
||||
@@ -110,7 +110,7 @@ public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
|
||||
}
|
||||
}
|
||||
|
||||
private final class JedisByteEntry implements Entry<byte[], byte[]> {
|
||||
private static final class JedisByteEntry implements Entry<byte[], byte[]> {
|
||||
private byte[] value;
|
||||
private byte[] key;
|
||||
|
||||
|
||||
@@ -7,8 +7,12 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public abstract class Pool<T> {
|
||||
private final GenericObjectPool internalPool;
|
||||
protected GenericObjectPool internalPool;
|
||||
|
||||
protected Pool() {
|
||||
this.internalPool = null;
|
||||
}
|
||||
|
||||
public Pool(final GenericObjectPool.Config poolConfig,
|
||||
PoolableObjectFactory factory) {
|
||||
this.internalPool = new GenericObjectPool(factory, poolConfig);
|
||||
@@ -23,8 +27,8 @@ public abstract class Pool<T> {
|
||||
"Could not get a resource from the pool", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void returnResource(final T resource) {
|
||||
|
||||
public void returnResourceObject(final Object resource) {
|
||||
try {
|
||||
internalPool.returnObject(resource);
|
||||
} catch (Exception e) {
|
||||
@@ -32,8 +36,16 @@ public abstract class Pool<T> {
|
||||
"Could not return the resource to the pool", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void returnBrokenResource(final T resource) {
|
||||
returnBrokenResourceObject(resource);
|
||||
}
|
||||
|
||||
public void returnResource(final T resource) {
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
|
||||
protected void returnBrokenResourceObject(final Object resource) {
|
||||
try {
|
||||
internalPool.invalidateObject(resource);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class RedisInputStream extends FilterInputStream {
|
||||
|
||||
@@ -84,7 +83,7 @@ public class RedisInputStream extends FilterInputStream {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisException(e);
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
String reply = sb.toString();
|
||||
if (reply.length() == 0) {
|
||||
|
||||
@@ -11,6 +11,14 @@ import redis.clients.jedis.exceptions.JedisException;
|
||||
*
|
||||
*/
|
||||
public class SafeEncoder {
|
||||
public static byte[][] encodeMany(final String... strs){
|
||||
byte[][] many = new byte[strs.length][];
|
||||
for(int i=0;i<strs.length;i++){
|
||||
many[i] = encode(strs[i]);
|
||||
}
|
||||
return many;
|
||||
}
|
||||
|
||||
public static byte[] encode(final String str) {
|
||||
try {
|
||||
if (str == null) {
|
||||
|
||||
@@ -77,7 +77,7 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
||||
|
||||
public S getShardInfo(byte[] key) {
|
||||
SortedMap<Long, S> tail = nodes.tailMap(algo.hash(key));
|
||||
if (tail.size() == 0) {
|
||||
if (tail.isEmpty()) {
|
||||
return nodes.get(nodes.firstKey());
|
||||
}
|
||||
return tail.get(tail.firstKey());
|
||||
|
||||
53
src/main/java/redis/clients/util/Slowlog.java
Normal file
53
src/main/java/redis/clients/util/Slowlog.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Slowlog {
|
||||
private final long id;
|
||||
private final long timeStamp;
|
||||
private final long executionTime;
|
||||
private final List<String> args;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slowlog> from(List<Object> nestedMultiBulkReply){
|
||||
List<Slowlog> logs = new ArrayList<Slowlog>(nestedMultiBulkReply.size());
|
||||
for(Object obj : nestedMultiBulkReply){
|
||||
List<Object> properties = (List<Object>)obj;
|
||||
logs.add(new Slowlog(properties));
|
||||
}
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Slowlog(List<Object> properties) {
|
||||
super();
|
||||
this.id = (Long)properties.get(0);
|
||||
this.timeStamp = (Long)properties.get(1);
|
||||
this.executionTime = (Long)properties.get(2);
|
||||
|
||||
List<byte[]> bargs = (List<byte[]>)properties.get(3);
|
||||
this.args = new ArrayList<String>(bargs.size());
|
||||
|
||||
for(byte[] barg:bargs){
|
||||
this.args.add(SafeEncoder.encode(barg));
|
||||
}
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public long getExecutionTime() {
|
||||
return executionTime;
|
||||
}
|
||||
|
||||
public List<String> getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,12 @@ public class ConnectionTest extends Assert {
|
||||
client.setPort(55665);
|
||||
client.connect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectIfNotConnectedWhenSettingTimeoutInfinite() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(6379);
|
||||
client.setTimeoutInfinite();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
@@ -95,4 +99,55 @@ public class JedisPoolTest extends Assert {
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonDefaultDatabase() {
|
||||
JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared");
|
||||
Jedis jedis0 = pool0.getResource();
|
||||
jedis0.set("foo", "bar");
|
||||
assertEquals( "bar", jedis0.get("foo") );
|
||||
pool0.returnResource(jedis0);
|
||||
pool0.destroy();
|
||||
|
||||
JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000, "foobared", 1);
|
||||
Jedis jedis1 = pool1.getResource();
|
||||
assertNull( jedis1.get("foo") );
|
||||
pool1.returnResource(jedis0);
|
||||
pool1.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnBinary() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host,
|
||||
hnp.port, 2000);
|
||||
BinaryJedis jedis = pool.getResource();
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrlString() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.select(2);
|
||||
j.set("foo", "bar");
|
||||
JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2");
|
||||
Jedis jedis = pool.getResource();
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrl() throws URISyntaxException {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.select(2);
|
||||
j.set("foo", "bar");
|
||||
JedisPool pool = new JedisPool(new URI("redis://:foobared@localhost:6380/2"));
|
||||
Jedis jedis = pool.getResource();
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
public class JedisSentinelTest {
|
||||
private static final String MASTER_NAME = "mymaster";
|
||||
|
||||
@Before
|
||||
public void setup() throws InterruptedException {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.configSet("masterauth", "foobared");
|
||||
j.slaveof("localhost", 6379);
|
||||
// TODO: The sleep is to give time to the slave to synchronize with the
|
||||
// master and also let know the sentinels about this new topology. We
|
||||
// should find a better way to do this.
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void clear() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.slaveofNoOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentinel() {
|
||||
Jedis j = new Jedis("localhost", 26379);
|
||||
List<Map<String, String>> masters = j.sentinelMasters();
|
||||
final String masterName = masters.get(0).get("name");
|
||||
|
||||
assertEquals(MASTER_NAME, masterName);
|
||||
|
||||
List<String> masterHostAndPort = j
|
||||
.sentinelGetMasterAddrByName(masterName);
|
||||
assertEquals("127.0.0.1", masterHostAndPort.get(0));
|
||||
assertEquals("6379", masterHostAndPort.get(1));
|
||||
|
||||
List<Map<String, String>> slaves = j.sentinelSlaves(masterName);
|
||||
assertEquals("6379", slaves.get(0).get("master-port"));
|
||||
|
||||
List<? extends Object> isMasterDownByAddr = j
|
||||
.sentinelIsMasterDownByAddr("127.0.0.1", 6379);
|
||||
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0));
|
||||
assertFalse("?".equals(isMasterDownByAddr.get(1)));
|
||||
|
||||
isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 1);
|
||||
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0));
|
||||
assertTrue("?".equals(isMasterDownByAddr.get(1)));
|
||||
|
||||
// DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
|
||||
assertEquals(Long.valueOf(1), j.sentinelReset(masterName));
|
||||
assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -17,56 +19,78 @@ import redis.clients.util.SafeEncoder;
|
||||
public class JedisTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void useWithoutConnecting() {
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
jedis.auth("foobared");
|
||||
jedis.dbSize();
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
jedis.auth("foobared");
|
||||
jedis.dbSize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkBinaryData() {
|
||||
byte[] bigdata = new byte[1777];
|
||||
for (int b = 0; b < bigdata.length; b++) {
|
||||
bigdata[b] = (byte) ((byte) b % 255);
|
||||
}
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("data", SafeEncoder.encode(bigdata));
|
||||
byte[] bigdata = new byte[1777];
|
||||
for (int b = 0; b < bigdata.length; b++) {
|
||||
bigdata[b] = (byte) ((byte) b % 255);
|
||||
}
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("data", SafeEncoder.encode(bigdata));
|
||||
|
||||
String status = jedis.hmset("foo", hash);
|
||||
assertEquals("OK", status);
|
||||
assertEquals(hash, jedis.hgetAll("foo"));
|
||||
String status = jedis.hmset("foo", hash);
|
||||
assertEquals("OK", status);
|
||||
assertEquals(hash, jedis.hgetAll("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectWithShardInfo() {
|
||||
JedisShardInfo shardInfo = new JedisShardInfo("localhost",
|
||||
Protocol.DEFAULT_PORT);
|
||||
shardInfo.setPassword("foobared");
|
||||
Jedis jedis = new Jedis(shardInfo);
|
||||
jedis.get("foo");
|
||||
JedisShardInfo shardInfo = new JedisShardInfo("localhost",
|
||||
Protocol.DEFAULT_PORT);
|
||||
shardInfo.setPassword("foobared");
|
||||
Jedis jedis = new Jedis(shardInfo);
|
||||
jedis.get("foo");
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void timeoutConnection() throws Exception {
|
||||
jedis = new Jedis("localhost", 6379, 15000);
|
||||
jedis.auth("foobared");
|
||||
jedis.configSet("timeout", "1");
|
||||
// we need to sleep a long time since redis check for idle connections
|
||||
// every 10 seconds or so
|
||||
Thread.sleep(20000);
|
||||
jedis.hmget("foobar", "foo");
|
||||
jedis = new Jedis("localhost", 6379, 15000);
|
||||
jedis.auth("foobared");
|
||||
jedis.configSet("timeout", "1");
|
||||
// we need to sleep a long time since redis check for idle connections
|
||||
// every 10 seconds or so
|
||||
Thread.sleep(20000);
|
||||
jedis.hmget("foobar", "foo");
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void failWhenSendingNullValues() {
|
||||
jedis.set("foo", null);
|
||||
jedis.set("foo", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReconnectToSameDB() throws IOException {
|
||||
jedis.select(1);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.getClient().getSocket().shutdownInput();
|
||||
jedis.getClient().getSocket().shutdownOutput();
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
jedis.select(1);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.getClient().getSocket().shutdownInput();
|
||||
jedis.getClient().getSocket().shutdownOutput();
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrlString() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.select(2);
|
||||
j.set("foo", "bar");
|
||||
Jedis jedis = new Jedis("redis://:foobared@localhost:6380/2");
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrl() throws URISyntaxException {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.select(2);
|
||||
j.set("foo", "bar");
|
||||
Jedis jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"));
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
}
|
||||
138
src/test/java/redis/clients/jedis/tests/PipeliningTest.java
Normal file → Executable file
138
src/test/java/redis/clients/jedis/tests/PipeliningTest.java
Normal file → Executable file
@@ -8,10 +8,7 @@ import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class PipeliningTest extends Assert {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
@@ -82,13 +79,95 @@ public class PipeliningTest extends Assert {
|
||||
assertEquals("foo", zset.get().iterator().next());
|
||||
assertEquals("foo", set.get());
|
||||
assertEquals(false, blist.get());
|
||||
assertEquals(new Double(2), zincrby.get());
|
||||
assertEquals(new Long(1), zcard.get());
|
||||
assertEquals(Double.valueOf(2), zincrby.get());
|
||||
assertEquals(Long.valueOf(1), zcard.get());
|
||||
assertEquals(1, lrange.get().size());
|
||||
assertNotNull(hgetAll.get().get("foo"));
|
||||
assertEquals(1, smembers.get().size());
|
||||
assertEquals(1, zrangeWithScores.get().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineResponseWithData() {
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "foo");
|
||||
p.sync();
|
||||
|
||||
assertNotNull(score.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineBinarySafeHashCommands() {
|
||||
jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes());
|
||||
jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes());
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Map<byte[],byte[]>> fmap = p.hgetAll("key".getBytes());
|
||||
Response<Set<byte[]>> fkeys = p.hkeys("key".getBytes());
|
||||
Response<List<byte[]>> fordered = p.hmget("key".getBytes(), "f22".getBytes(), "f1".getBytes());
|
||||
Response<List<byte[]>> fvals = p.hvals("key".getBytes());
|
||||
p.sync();
|
||||
|
||||
assertNotNull(fmap.get());
|
||||
// we have to do these strange contortions because byte[] is not a very good key
|
||||
// for a java Map. It only works with equality (you need the exact key object to retrieve
|
||||
// the value) I recommend we switch to using ByteBuffer or something similar:
|
||||
// http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java
|
||||
Map<byte[],byte[]> map = fmap.get();
|
||||
Set<byte[]> mapKeys = map.keySet();
|
||||
Iterator<byte[]> iterMap = mapKeys.iterator();
|
||||
byte[] firstMapKey = iterMap.next();
|
||||
byte[] secondMapKey = iterMap.next();
|
||||
assertFalse(iterMap.hasNext());
|
||||
verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), "f22".getBytes());
|
||||
byte[] firstMapValue = map.get(firstMapKey);
|
||||
byte[] secondMapValue = map.get(secondMapKey);
|
||||
verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), "v2222".getBytes());
|
||||
|
||||
assertNotNull(fkeys.get());
|
||||
Iterator<byte[]> iter = fkeys.get().iterator();
|
||||
byte[] firstKey = iter.next();
|
||||
byte[] secondKey = iter.next();
|
||||
assertFalse(iter.hasNext());
|
||||
verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), "f22".getBytes());
|
||||
|
||||
assertNotNull(fordered.get());
|
||||
assertArrayEquals("v2222".getBytes(), fordered.get().get(0));
|
||||
assertArrayEquals("v111".getBytes(), fordered.get().get(1));
|
||||
|
||||
assertNotNull(fvals.get());
|
||||
assertEquals(2, fvals.get().size());
|
||||
byte[] firstValue = fvals.get().get(0);
|
||||
byte[] secondValue = fvals.get().get(1);
|
||||
verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), "v2222".getBytes());
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value1, byte[] value2) {
|
||||
assertFalse(Arrays.equals(firstKey, secondKey));
|
||||
assertTrue(Arrays.equals(firstKey, value1) || Arrays.equals(firstKey, value2));
|
||||
assertTrue(Arrays.equals(secondKey, value1) || Arrays.equals(secondKey, value2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineSelect() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.select(1);
|
||||
p.sync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineResponseWithoutData() {
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "bar");
|
||||
p.sync();
|
||||
|
||||
assertNull(score.get());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineResponseWithinPipeline() {
|
||||
@@ -118,4 +197,49 @@ public class PipeliningTest extends Assert {
|
||||
p.sync();
|
||||
assertNull(shouldNotExist.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void piplineWithError(){
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
Response<Set<String>> error = p.smembers("foo");
|
||||
Response<String> r = p.get("foo");
|
||||
p.sync();
|
||||
try{
|
||||
error.get();
|
||||
fail();
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi(){
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
Response<Long> r1 = p.hincrBy("a", "f1", -1);
|
||||
Response<Long> r2 = p.hincrBy("a", "f1", -2);
|
||||
Response<List<Object>> r3 = p.exec();
|
||||
List<Object> result = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(new Long(-1), r1.get());
|
||||
assertEquals(new Long(-3), r2.get());
|
||||
|
||||
assertEquals(4, result.size());
|
||||
|
||||
assertEquals("OK", result.get(0));
|
||||
assertEquals("QUEUED", result.get(1));
|
||||
assertEquals("QUEUED", result.get(2));
|
||||
|
||||
//4th result is a list with the results from the multi
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> multiResult = (List<Object>) result.get(3);
|
||||
assertEquals(new Long(-1), multiResult.get(0));
|
||||
assertEquals(new Long(-3), multiResult.get(1));
|
||||
|
||||
assertEquals(new Long(-1), r3.get().get(0));
|
||||
assertEquals(new Long(-3), r3.get().get(1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
PipedOutputStream pos = new PipedOutputStream(pis);
|
||||
RedisOutputStream ros = new RedisOutputStream(pos);
|
||||
|
||||
Protocol protocol = new Protocol();
|
||||
protocol.sendCommand(ros, Protocol.Command.GET,
|
||||
Protocol.sendCommand(ros, Protocol.Command.GET,
|
||||
"SOMEKEY".getBytes(Protocol.CHARSET));
|
||||
ros.flush();
|
||||
pos.close();
|
||||
@@ -43,8 +42,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
@Test
|
||||
public void bulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("foobar"), response);
|
||||
}
|
||||
|
||||
@@ -52,8 +50,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
public void fragmentedBulkReply() {
|
||||
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
|
||||
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(fis));
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis));
|
||||
assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"),
|
||||
response);
|
||||
}
|
||||
@@ -61,24 +58,21 @@ public class ProtocolTest extends JedisTestBase {
|
||||
@Test
|
||||
public void nullBulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
String response = (String) protocol.read(new RedisInputStream(is));
|
||||
String response = (String) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLineReply() {
|
||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("OK"), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integerReply() {
|
||||
InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
long response = (Long) protocol.read(new RedisInputStream(is));
|
||||
long response = (Long) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(123, response);
|
||||
}
|
||||
|
||||
@@ -88,8 +82,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
InputStream is = new ByteArrayInputStream(
|
||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||
.getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
List<byte[]> response = (List<byte[]>) protocol
|
||||
List<byte[]> response = (List<byte[]>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add(SafeEncoder.encode("foo"));
|
||||
@@ -104,8 +97,7 @@ public class ProtocolTest extends JedisTestBase {
|
||||
@Test
|
||||
public void nullMultiBulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
List<String> response = (List<String>) protocol
|
||||
List<String> response = (List<String>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
assertNull(response);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.ShardedJedis;
|
||||
import redis.clients.jedis.ShardedJedisPipeline;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class ShardedJedisPipelineTest {
|
||||
private static HostAndPortUtil.HostAndPort redis1 = HostAndPortUtil
|
||||
.getRedisServers().get(0);
|
||||
private static HostAndPortUtil.HostAndPort redis2 = HostAndPortUtil
|
||||
.getRedisServers().get(1);
|
||||
|
||||
private ShardedJedis jedis;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Jedis jedis = new Jedis(redis1.host, redis1.port);
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
jedis.disconnect();
|
||||
jedis = new Jedis(redis2.host, redis2.port);
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
jedis.disconnect();
|
||||
|
||||
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.host, redis1.port);
|
||||
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.host, redis2.port);
|
||||
shardInfo1.setPassword("foobared");
|
||||
shardInfo2.setPassword("foobared");
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(shardInfo1);
|
||||
shards.add(shardInfo2);
|
||||
this.jedis = new ShardedJedis(shards);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipeline() throws UnsupportedEncodingException {
|
||||
ShardedJedisPipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
p.get("foo");
|
||||
List<Object> results = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineResponse() {
|
||||
jedis.set("string", "foo");
|
||||
jedis.lpush("list", "foo");
|
||||
jedis.hset("hash", "foo", "bar");
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
jedis.sadd("set", "foo");
|
||||
|
||||
ShardedJedisPipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
Response<Long> del = p.del("string");
|
||||
Response<String> emptyString = p.get("string");
|
||||
Response<String> list = p.lpop("list");
|
||||
Response<String> hash = p.hget("hash", "foo");
|
||||
Response<Set<String>> zset = p.zrange("zset", 0, -1);
|
||||
Response<String> set = p.spop("set");
|
||||
Response<Boolean> blist = p.exists("list");
|
||||
Response<Double> zincrby = p.zincrby("zset", 1, "foo");
|
||||
Response<Long> zcard = p.zcard("zset");
|
||||
p.lpush("list", "bar");
|
||||
Response<List<String>> lrange = p.lrange("list", 0, -1);
|
||||
Response<Map<String, String>> hgetAll = p.hgetAll("hash");
|
||||
p.sadd("set", "foo");
|
||||
Response<Set<String>> smembers = p.smembers("set");
|
||||
Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0,
|
||||
-1);
|
||||
p.sync();
|
||||
|
||||
assertEquals("foo", string.get());
|
||||
assertEquals(Long.valueOf(1), del.get());
|
||||
assertNull(emptyString.get());
|
||||
assertEquals("foo", list.get());
|
||||
assertEquals("bar", hash.get());
|
||||
assertEquals("foo", zset.get().iterator().next());
|
||||
assertEquals("foo", set.get());
|
||||
assertFalse(blist.get());
|
||||
assertEquals(Double.valueOf(2), zincrby.get());
|
||||
assertEquals(Long.valueOf(1), zcard.get());
|
||||
assertEquals(1, lrange.get().size());
|
||||
assertNotNull(hgetAll.get().get("foo"));
|
||||
assertEquals(1, smembers.get().size());
|
||||
assertEquals(1, zrangeWithScores.get().size());
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineResponseWithinPipeline() {
|
||||
jedis.set("string", "foo");
|
||||
|
||||
ShardedJedisPipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
string.get();
|
||||
p.sync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRetrieveUnsetKey() {
|
||||
ShardedJedisPipeline p = jedis.pipelined();
|
||||
Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
|
||||
p.sync();
|
||||
assertNull(shouldNotExist.get());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -152,8 +154,8 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
shards.set(1, new JedisShardInfo("nohost", 1234));
|
||||
pool = new ShardedJedisPool(redisConfig, shards);
|
||||
jedis = pool.getResource();
|
||||
Long actual = new Long(0);
|
||||
Long fails = new Long(0);
|
||||
Long actual = Long.valueOf(0);
|
||||
Long fails = Long.valueOf(0);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
try {
|
||||
jedis.get("a-test-" + i);
|
||||
@@ -167,4 +169,60 @@ public class ShardedJedisPoolTest extends Assert {
|
||||
assertEquals(actual, c1);
|
||||
assertEquals(fails, c2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrlString() {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
j = new Jedis("localhost", 6379);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6380"));
|
||||
shards.add(new JedisShardInfo("redis://:foobared@localhost:6379"));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
jedis = jedises[1];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithUrl() throws URISyntaxException {
|
||||
Jedis j = new Jedis("localhost", 6380);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
j = new Jedis("localhost", 6379);
|
||||
j.auth("foobared");
|
||||
j.set("foo", "bar");
|
||||
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
|
||||
shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));
|
||||
|
||||
Config redisConfig = new Config();
|
||||
ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
|
||||
|
||||
Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
|
||||
|
||||
Jedis jedis = jedises[0];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
jedis = jedises[1];
|
||||
assertEquals("PONG", jedis.ping());
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void ttl() {
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertEquals(-1, ttl);
|
||||
assertEquals(-2, ttl);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
ttl = jedis.ttl("foo");
|
||||
@@ -312,7 +312,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
// Binary
|
||||
long bttl = jedis.ttl(bfoo);
|
||||
assertEquals(-1, bttl);
|
||||
assertEquals(-2, bttl);
|
||||
|
||||
jedis.set(bfoo, bbar);
|
||||
bttl = jedis.ttl(bfoo);
|
||||
@@ -457,5 +457,50 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
byte[] bresult = jedis.echo(SafeEncoder.encode("hello world"));
|
||||
assertArrayEquals(SafeEncoder.encode("hello world"), bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dumpAndRestore() {
|
||||
jedis.set("foo1", "bar1");
|
||||
byte[] sv = jedis.dump("foo1");
|
||||
jedis.restore("foo2", 0, sv);
|
||||
assertTrue(jedis.exists("foo2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pexpire() {
|
||||
long status = jedis.pexpire("foo", 10000);
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
status = jedis.pexpire("foo", 10000);
|
||||
assertEquals(1, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pexpireAt() {
|
||||
long unixTime = (System.currentTimeMillis()) + 10000;
|
||||
|
||||
long status = jedis.pexpireAt("foo", unixTime);
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
unixTime = (System.currentTimeMillis()) + 10000;
|
||||
status = jedis.pexpireAt("foo", unixTime);
|
||||
assertEquals(1, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pttl() {
|
||||
long pttl = jedis.pttl("foo");
|
||||
assertEquals(-1, pttl);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
pttl = jedis.pttl("foo");
|
||||
assertEquals(-1, pttl);
|
||||
|
||||
jedis.pexpire("foo", 20000);
|
||||
pttl = jedis.pttl("foo");
|
||||
assertTrue(pttl >= 0 && pttl <= 20000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BitOP;
|
||||
|
||||
public class BitCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void setAndgetbit() {
|
||||
@@ -11,11 +13,11 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
bit = jedis.getbit("foo", 0);
|
||||
assertEquals(true, bit);
|
||||
|
||||
long bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes());
|
||||
assertEquals(0, bbit);
|
||||
boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes());
|
||||
assertFalse(bbit);
|
||||
|
||||
bbit = jedis.getbit("bfoo".getBytes(), 0);
|
||||
assertEquals(1, bbit);
|
||||
assertTrue(bbit);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -29,4 +31,63 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("Hello", jedis.getrange("key1", 0, 4));
|
||||
assertEquals("Jedis", jedis.getrange("key1", 6, 11));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitCount() {
|
||||
jedis.del("foo");
|
||||
|
||||
jedis.setbit("foo", 16, true);
|
||||
jedis.setbit("foo", 24, true);
|
||||
jedis.setbit("foo", 40, true);
|
||||
jedis.setbit("foo", 56, true);
|
||||
|
||||
long c4 = jedis.bitcount("foo");
|
||||
assertEquals(4, c4);
|
||||
|
||||
long c3 = jedis.bitcount("foo", 2L, 5L);
|
||||
assertEquals(3, c3);
|
||||
|
||||
jedis.del("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOp()
|
||||
{
|
||||
jedis.set("key1", "\u0060");
|
||||
jedis.set("key2", "\u0044");
|
||||
|
||||
jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2");
|
||||
String resultAnd = jedis.get("resultAnd");
|
||||
assertEquals("\u0040", resultAnd);
|
||||
|
||||
jedis.bitop(BitOP.OR, "resultOr", "key1", "key2");
|
||||
String resultOr = jedis.get("resultOr");
|
||||
assertEquals("\u0064", resultOr);
|
||||
|
||||
jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2");
|
||||
String resultXor = jedis.get("resultXor");
|
||||
assertEquals("\u0024", resultXor);
|
||||
|
||||
jedis.del("resultAnd");
|
||||
jedis.del("resultOr");
|
||||
jedis.del("resultXor");
|
||||
jedis.del("key1");
|
||||
jedis.del("key2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOpNot()
|
||||
{
|
||||
jedis.del("key");
|
||||
jedis.setbit("key", 0, true);
|
||||
jedis.setbit("key", 4, true);
|
||||
|
||||
jedis.bitop(BitOP.NOT, "resultNot", "key");
|
||||
|
||||
String resultNot = jedis.get("resultNot");
|
||||
assertEquals("\u0077", resultNot);
|
||||
|
||||
jedis.del("key");
|
||||
jedis.del("resultNot");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,13 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void bgrewriteaof() {
|
||||
String scheduled = "Background append only file rewriting scheduled";
|
||||
String started = "Background append only file rewriting started";
|
||||
|
||||
String status = jedis.bgrewriteaof();
|
||||
assertEquals("Background append only file rewriting started", status);
|
||||
|
||||
boolean ok = status.equals(scheduled) || status.equals(started);
|
||||
assertTrue(ok);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,6 +58,8 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
public void info() {
|
||||
String info = jedis.info();
|
||||
assertNotNull(info);
|
||||
info = jedis.info("server");
|
||||
assertNotNull(info);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,8 +64,8 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
|
||||
}
|
||||
}
|
||||
if (!contained) {
|
||||
throw new ComparisonFailure("element is missing", next
|
||||
.toString(), actual.toString());
|
||||
throw new ComparisonFailure("element is missing",
|
||||
Arrays.toString(next), actual.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,4 +93,4 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,17 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(1, size);
|
||||
size = jedis.rpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
|
||||
// Binary
|
||||
long bsize = jedis.rpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.rpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
|
||||
}
|
||||
|
||||
@@ -45,12 +50,16 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(1, size);
|
||||
size = jedis.lpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
// Binary
|
||||
long bsize = jedis.lpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.lpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
|
||||
}
|
||||
|
||||
@@ -620,4 +629,4 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ObjectCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
private String key = "mylist";
|
||||
private byte[] binaryKey = SafeEncoder.encode(key);
|
||||
|
||||
@Test
|
||||
public void objectRefcount() {
|
||||
jedis.lpush(key, "hello world");
|
||||
Long refcount = jedis.objectRefcount(key);
|
||||
assertEquals(new Long(1), refcount);
|
||||
|
||||
// Binary
|
||||
refcount = jedis.objectRefcount(binaryKey);
|
||||
assertEquals(new Long(1), refcount);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectEncoding() {
|
||||
jedis.lpush(key, "hello world");
|
||||
String encoding = jedis.objectEncoding(key);
|
||||
assertEquals("ziplist", encoding);
|
||||
|
||||
// Binary
|
||||
encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey));
|
||||
assertEquals("ziplist", encoding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectIdletime() throws InterruptedException {
|
||||
jedis.lpush(key, "hello world");
|
||||
|
||||
// Wait a little bit more than 10 seconds so the idle time is 10
|
||||
// seconds.
|
||||
Thread.sleep(10001);
|
||||
Long time = jedis.objectIdletime(key);
|
||||
assertEquals(new Long(10), time);
|
||||
|
||||
// Binary
|
||||
time = jedis.objectIdletime(binaryKey);
|
||||
assertEquals(new Long(10), time);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
@@ -471,7 +472,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
t.join();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test @Ignore
|
||||
public void subscribeWithoutConnecting() {
|
||||
try {
|
||||
Jedis jedis = new Jedis(hnp.host, hnp.port);
|
||||
@@ -527,4 +528,4 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
};
|
||||
pubsub.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void evalMultiBulk() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("key1");
|
||||
keys.add("key2");
|
||||
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("first");
|
||||
args.add("second");
|
||||
|
||||
List<String> response = (List<String>) jedis.eval(script, keys, args);
|
||||
|
||||
assertEquals(4, response.size());
|
||||
assertEquals("key1", response.get(0));
|
||||
assertEquals("key2", response.get(1));
|
||||
assertEquals("first", response.get(2));
|
||||
assertEquals("second", response.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalBulk() {
|
||||
String script = "return KEYS[1]";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("key1");
|
||||
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("first");
|
||||
|
||||
String response = (String) jedis.eval(script, keys, args);
|
||||
|
||||
assertEquals("key1", response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalInt() {
|
||||
String script = "return 2";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("key1");
|
||||
|
||||
Long response = (Long) jedis
|
||||
.eval(script, keys, new ArrayList<String>());
|
||||
|
||||
assertEquals(new Long(2), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalNoArgs() {
|
||||
String script = "return KEYS[1]";
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("key1");
|
||||
String response = (String) jedis.eval(script, keys,
|
||||
new ArrayList<String>());
|
||||
|
||||
assertEquals("key1", response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalsha() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.eval("return redis.call('get','foo')");
|
||||
String result = (String) jedis
|
||||
.evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791");
|
||||
|
||||
assertEquals("bar", result);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void evalshaShaNotFound() {
|
||||
jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptFlush() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.eval("return redis.call('get','foo')");
|
||||
jedis.scriptFlush();
|
||||
assertFalse(jedis
|
||||
.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptExists() {
|
||||
jedis.scriptLoad("return redis.call('get','foo')");
|
||||
List<Boolean> exists = jedis.scriptExists(
|
||||
"ffffffffffffffffffffffffffffffffffffffff",
|
||||
"6b1bf486c81ceb7edf3c093f4c48582e38c0e791");
|
||||
assertFalse(exists.get(0));
|
||||
assertTrue(exists.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptExistsBinary() {
|
||||
jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')"));
|
||||
List<Long> exists = jedis.scriptExists(
|
||||
SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"),
|
||||
SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
|
||||
assertEquals(new Long(0), exists.get(0));
|
||||
assertEquals(new Long(1), exists.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptLoad() {
|
||||
jedis.scriptLoad("return redis.call('get','foo')");
|
||||
assertTrue(jedis
|
||||
.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptLoadBinary() {
|
||||
jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')"));
|
||||
List<Long> exists = jedis.scriptExists(SafeEncoder
|
||||
.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
|
||||
assertEquals(new Long(1), exists.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptKill() {
|
||||
try {
|
||||
jedis.scriptKill();
|
||||
} catch (JedisDataException e) {
|
||||
assertTrue(e.getMessage().contains(
|
||||
"No scripts in execution right now."));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptEvalReturnNullValues() {
|
||||
String script = "return {redis.call('hget',KEYS[1],ARGV[1]),redis.call('hget',KEYS[2],ARGV[2])}";
|
||||
jedis.eval(script, 2, "key1", "key2", "1", "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptEvalShaReturnNullValues() {
|
||||
String script = "return {redis.call('hget',KEYS[1],ARGV[1]),redis.call('hget',KEYS[2],ARGV[2])}";
|
||||
String sha = jedis.scriptLoad(script);
|
||||
jedis.evalsha(sha, 2, "key1", "key2", "1", "1");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public class SlowlogCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void slowlog() {
|
||||
//do something
|
||||
jedis.configSet("slowlog-log-slower-than", "0");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
List<Slowlog> reducedLog = jedis.slowlogGet(1);
|
||||
assertEquals(1, reducedLog.size());
|
||||
|
||||
Slowlog log = reducedLog.get(0);
|
||||
assertTrue(log.getId() > 0);
|
||||
assertTrue(log.getTimeStamp() > 0);
|
||||
assertTrue(log.getExecutionTime() > 0);
|
||||
assertNotNull(log.getArgs());
|
||||
|
||||
List<byte[]> breducedLog = jedis.slowlogGetBinary(1);
|
||||
assertEquals(1, breducedLog.size());
|
||||
|
||||
List<Slowlog> log1 = jedis.slowlogGet();
|
||||
List<byte[]> blog1 = jedis.slowlogGetBinary();
|
||||
|
||||
assertNotNull(log1);
|
||||
assertNotNull(blog1);
|
||||
|
||||
long len1 = jedis.slowlogLen();
|
||||
|
||||
jedis.slowlogReset();
|
||||
|
||||
List<Slowlog> log2 = jedis.slowlogGet();
|
||||
List<byte[]> blog2 = jedis.slowlogGetBinary();
|
||||
long len2 = jedis.slowlogLen();
|
||||
|
||||
assertTrue(len1 > len2);
|
||||
assertTrue(log1.size() > log2.size());
|
||||
assertTrue(blog1.size() > blog2.size());
|
||||
}
|
||||
}
|
||||
@@ -373,6 +373,10 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(2, result);
|
||||
|
||||
result = jedis.zcount("foo", "(0.01", "+inf");
|
||||
|
||||
assertEquals(3, result);
|
||||
|
||||
// Binary
|
||||
jedis.zadd(bfoo, 1d, ba);
|
||||
jedis.zadd(bfoo, 10d, bb);
|
||||
@@ -383,6 +387,9 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(2, bresult);
|
||||
|
||||
bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), SafeEncoder.encode("+inf"));
|
||||
|
||||
assertEquals(3, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -655,7 +662,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zremrangeByRank() {
|
||||
jedis.zadd("foo", 1d, "a");
|
||||
|
||||
@@ -190,4 +190,20 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(Long.MIN_VALUE, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrByFloat() {
|
||||
double value = jedis.incrByFloat("foo", 10.5);
|
||||
assertEquals(10.5, value, 0.0);
|
||||
value = jedis.incrByFloat("foo", 0.1);
|
||||
assertEquals(10.6, value, 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void psetex() {
|
||||
String status = jedis.psetex("foo", 20000, "bar");
|
||||
assertEquals("OK", status);
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl > 0 && ttl <= 20000);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
@@ -170,7 +171,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
t.set(bmykey, bval);
|
||||
resp = t.exec();
|
||||
assertEquals(1, resp.size());
|
||||
assertArrayEquals("OK".getBytes(), (byte[]) resp.get(0));
|
||||
assertEquals("OK", resp.get(0));
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
@@ -241,4 +242,57 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
string.get();
|
||||
t.exec();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transactionResponseWithError() {
|
||||
Transaction t = jedis.multi();
|
||||
t.set("foo", "bar");
|
||||
Response<Set<String>> error = t.smembers("foo");
|
||||
Response<String> r = t.get("foo");
|
||||
List<Object> l = t.exec();
|
||||
assertEquals(JedisDataException.class, l.get(1).getClass());
|
||||
try{
|
||||
error.get();
|
||||
fail("We expect exception here!");
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void execGetResponse() {
|
||||
Transaction t = jedis.multi();
|
||||
|
||||
t.set("foo", "bar");
|
||||
t.smembers("foo");
|
||||
t.get("foo");
|
||||
|
||||
List<Response<?>> lr = t.execGetResponse();
|
||||
try{
|
||||
lr.get(1).get();
|
||||
fail("We expect exception here!");
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
}
|
||||
assertEquals("bar", lr.get(2).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void select() {
|
||||
jedis.select(1);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.watch("foo");
|
||||
Transaction t = jedis.multi();
|
||||
t.select(0);
|
||||
t.set("bar", "foo");
|
||||
|
||||
Jedis jedis2 = createJedis();
|
||||
jedis2.select(1);
|
||||
jedis2.set("foo", "bar2");
|
||||
|
||||
List<Object> results = t.exec();
|
||||
|
||||
assertNull(results);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class VariadicCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||
final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A };
|
||||
final byte[] bfoo2 = { 0x01, 0x02, 0x03, 0x04, 0x0B };
|
||||
|
||||
@Test
|
||||
public void hdel() {
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("bar", "car");
|
||||
hash.put("car", "bar");
|
||||
hash.put("foo2", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue());
|
||||
assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue());
|
||||
assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue());
|
||||
assertEquals(null, jedis.hget("foo", "bar"));
|
||||
|
||||
// Binary
|
||||
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||
bhash.put(bbar, bcar);
|
||||
bhash.put(bcar, bbar);
|
||||
bhash.put(bfoo2, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
|
||||
assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue());
|
||||
assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue());
|
||||
assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue());
|
||||
assertEquals(null, jedis.hget(bfoo, bbar));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpush() {
|
||||
long size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(bfoo);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lpush() {
|
||||
long size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("foo");
|
||||
expected.add("bar");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
bexpected.add(bbar);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sadd() {
|
||||
long status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(2, status);
|
||||
|
||||
status = jedis.sadd("foo", "bar", "car");
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(2, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bcar);
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(0, status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zadd() {
|
||||
Map<Double, String> scoreMembers = new HashMap<Double, String>();
|
||||
scoreMembers.put(1d, "bar");
|
||||
scoreMembers.put(10d, "foo");
|
||||
|
||||
long status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(2, status);
|
||||
|
||||
scoreMembers.clear();
|
||||
scoreMembers.put(0.1d, "car");
|
||||
scoreMembers.put(2d, "bar");
|
||||
|
||||
status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(1, status);
|
||||
|
||||
Map<Double, byte[]> bscoreMembers = new HashMap<Double, byte[]>();
|
||||
bscoreMembers.put(1d, bbar);
|
||||
bscoreMembers.put(10d, bfoo);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(2, status);
|
||||
|
||||
bscoreMembers.clear();
|
||||
bscoreMembers.put(0.1d, bcar);
|
||||
bscoreMembers.put(2d, bbar);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(1, status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zrem() {
|
||||
jedis.zadd("foo", 1d, "bar");
|
||||
jedis.zadd("foo", 2d, "car");
|
||||
jedis.zadd("foo", 3d, "foo1");
|
||||
|
||||
long status = jedis.zrem("foo", "bar", "car");
|
||||
|
||||
Set<String> expected = new LinkedHashSet<String>();
|
||||
expected.add("foo1");
|
||||
|
||||
assertEquals(2, status);
|
||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||
|
||||
status = jedis.zrem("foo", "bar", "car");
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.zrem("foo", "bar", "foo1");
|
||||
assertEquals(1, status);
|
||||
|
||||
//Binary
|
||||
jedis.zadd(bfoo, 1d, bbar);
|
||||
jedis.zadd(bfoo, 2d, bcar);
|
||||
jedis.zadd(bfoo, 3d, bfoo1);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
|
||||
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
|
||||
assertEquals(2, status);
|
||||
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bfoo1);
|
||||
assertEquals(1, status);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user