├── Release ├── RELEASE_BUILD_TIME ├── jredis-core-all-a.0-SNAPSHOT.jar ├── jredis-core-api-a.0-SNAPSHOT.jar ├── jredis-core-ri-a.0-SNAPSHOT.jar ├── jredis-examples-a.0-SNAPSHOT.jar ├── jredis-core-bench-a.0-SNAPSHOT.jar ├── jredis-core-all-a.0-SNAPSHOT-sources.jar ├── jredis-core-api-a.0-SNAPSHOT-sources.jar ├── jredis-core-ri-a.0-SNAPSHOT-sources.jar ├── jredis-examples-a.0-SNAPSHOT-sources.jar ├── jredis-core-bench-a.0-SNAPSHOT-sources.jar ├── jredis-core-all-a.0-SNAPSHOT-jar-with-dependencies.jar ├── jredis-core-ri-a.0-SNAPSHOT-jar-with-dependencies.jar ├── jredis-examples-a.0-SNAPSHOT-jar-with-dependencies.jar ├── jredis-core-bench-a.0-SNAPSHOT-jar-with-dependencies.jar ├── RELEASE-NOTES-Update-03122010.txt └── RELEASE-NOTES-Update-08132009.txt ├── .gitignore ├── extensions ├── README.markdown ├── api │ ├── README.markdown │ ├── NOTICE │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── jredis │ │ │ └── cluster │ │ │ ├── support │ │ │ └── HashAlgorithm.java │ │ │ └── ClusterType.java │ └── pom.xml ├── ri │ ├── README.markdown │ ├── NOTICE │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── jredis │ │ │ │ ├── test │ │ │ │ └── util │ │ │ │ │ └── RunningAverage.java │ │ │ │ ├── cluster │ │ │ │ ├── models │ │ │ │ │ ├── KetamaHashAlgoTest.java │ │ │ │ │ └── BasicStaticHashClusterTest.java │ │ │ │ └── ProviderTestBase.java │ │ │ │ └── ri │ │ │ │ └── cluster │ │ │ │ ├── DefaultClusterSpecTest.java │ │ │ │ └── ClusterNodeSpecImplTest.java │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── jredis │ │ │ └── ri │ │ │ └── cluster │ │ │ ├── model │ │ │ └── BasicStaticHashCluster.java │ │ │ ├── support │ │ │ └── CryptoHashUtils.java │ │ │ └── DefaultClusterSpec.java │ └── pom.xml ├── NOTICE ├── 3rd party Licenses │ ├── NET.SPY.MEMCACHED LICENSE │ └── NET.SPY.MEMCACHED NOTICE └── pom.xml ├── DEV-NOTES.txt ├── documentation ├── design │ └── diagrams │ │ └── connector-design │ │ ├── connector-design-a0.png │ │ └── connector-design-a0.1.png └── NOTICE ├── NOTICE ├── core ├── NOTICE ├── all │ ├── NOTICE │ └── pom.xml ├── api │ ├── NOTICE │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ └── log4j.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── jredis │ │ │ │ └── protocol │ │ │ │ └── TestCommand.java │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── jredis │ │ │ │ ├── resource │ │ │ │ ├── Context.java │ │ │ │ ├── ResourceException.java │ │ │ │ ├── package-info.java │ │ │ │ ├── _specification.java │ │ │ │ └── Resource.java │ │ │ │ ├── RedisType.java │ │ │ │ ├── connector │ │ │ │ ├── package-info.java │ │ │ │ ├── RequestListener.java │ │ │ │ ├── ConnectionFault.java │ │ │ │ ├── NotConnectedException.java │ │ │ │ ├── ConnectionException.java │ │ │ │ ├── Message.java │ │ │ │ ├── ConnectionReset.java │ │ │ │ └── FaultedConnection.java │ │ │ │ ├── protocol │ │ │ │ ├── Request.java │ │ │ │ ├── package-info.java │ │ │ │ ├── StatusResponse.java │ │ │ │ ├── BulkResponse.java │ │ │ │ ├── CommandNotImplemented.java │ │ │ │ ├── MultiBulkResponse.java │ │ │ │ ├── ResponseStatus.java │ │ │ │ ├── ValueResponse.java │ │ │ │ └── Protocol.java │ │ │ │ ├── package-info.java │ │ │ │ ├── semantics │ │ │ │ ├── SemanticSort.java │ │ │ │ ├── Semantics.java │ │ │ │ ├── SemanticQuery.java │ │ │ │ ├── CodecManager.java │ │ │ │ ├── package-info.java │ │ │ │ ├── BasicCodecManager.java │ │ │ │ └── KeyCodec.java │ │ │ │ ├── _specification.java │ │ │ │ ├── ZSetEntry.java │ │ │ │ ├── ObjectEncoding.java │ │ │ │ ├── Redis.java │ │ │ │ ├── NotSupportedException.java │ │ │ │ ├── Semantics.java │ │ │ │ ├── Codec.java │ │ │ │ ├── ProviderException.java │ │ │ │ ├── RedisInfo.java │ │ │ │ ├── Event.java │ │ │ │ ├── RedisException.java │ │ │ │ ├── ClientRuntimeException.java │ │ │ │ └── Query.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── redis-commands-2.4.n.txt │ └── pom.xml ├── bench │ ├── NOTICE │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── log4j.properties │ │ │ └── java │ │ │ └── org │ │ │ └── jredis │ │ │ ├── ri │ │ │ └── alphazero │ │ │ │ └── bench │ │ │ │ ├── JRedisClientJProfileSubject.java │ │ │ │ ├── SimpleBenchJRedisClient.java │ │ │ │ ├── SimpleBenchJRedisAsync.java │ │ │ │ ├── SimpleBenchJRedisPipeline.java │ │ │ │ ├── SimpleBenchJRedisChunkedPipeline.java │ │ │ │ ├── JRedisClientBenchmark.java │ │ │ │ ├── JRedisPipelineServiceBenchmark.java │ │ │ │ └── JRedisServiceBenchmark.java │ │ │ └── bench │ │ │ └── JRedisJProfileSubject.java │ └── pom.xml ├── ri │ ├── NOTICE │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ └── log4j.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── jredis │ │ │ │ └── ri │ │ │ │ ├── adhoc │ │ │ │ └── AdHocTestNoConnection.java │ │ │ │ ├── alphazero │ │ │ │ ├── support │ │ │ │ │ └── GZipTest.java │ │ │ │ ├── JRedisClientTest.java │ │ │ │ ├── JRedisAsyncClientTest.java │ │ │ │ └── JRedisChunkedPipelineClientTest.java │ │ │ │ └── ProviderTestBase.java │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── jredis │ │ │ └── ri │ │ │ ├── alphazero │ │ │ ├── support │ │ │ │ ├── package-info.java │ │ │ │ └── GZip.java │ │ │ ├── semantics │ │ │ │ ├── GZipCompressedStringCodec.java │ │ │ │ └── DefaultStringCodec.java │ │ │ ├── package-info.java │ │ │ ├── Pair.java │ │ │ ├── _specification.java │ │ │ ├── RedisVersion.java │ │ │ ├── connection │ │ │ │ ├── UnexpectedEOFException.java │ │ │ │ ├── AsyncPipelineConnection.java │ │ │ │ └── DefaultConnectionFactory.java │ │ │ ├── ZSetEntryImpl.java │ │ │ ├── protocol │ │ │ │ ├── DefaultProtocolFactory.java │ │ │ │ ├── ResponseSupport.java │ │ │ │ ├── VirtualResponse.java │ │ │ │ └── ConcurrentSyncProtocol.java │ │ │ ├── JRedisChunkedPipeline.java │ │ │ └── BulkSetMapping.java │ │ │ ├── package-info.java │ │ │ └── RI.java │ └── pom.xml └── README ├── examples ├── NOTICE ├── src │ └── main │ │ ├── resources │ │ └── log4j.properties │ │ └── java │ │ └── org │ │ └── jredis │ │ └── examples │ │ ├── commands │ │ └── package-info.java │ │ └── HelloAgain.java └── pom.xml └── redis_version_compliance.txt /Release/RELEASE_BUILD_TIME: -------------------------------------------------------------------------------- 1 | Fri Mar 12 11:19:49 EST 2010 2 | -------------------------------------------------------------------------------- /Release/jredis-core-all-a.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-all-a.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /Release/jredis-core-api-a.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-api-a.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /Release/jredis-core-ri-a.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-ri-a.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /Release/jredis-examples-a.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-examples-a.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /Release/jredis-core-bench-a.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-bench-a.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /Release/jredis-core-all-a.0-SNAPSHOT-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-all-a.0-SNAPSHOT-sources.jar -------------------------------------------------------------------------------- /Release/jredis-core-api-a.0-SNAPSHOT-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-api-a.0-SNAPSHOT-sources.jar -------------------------------------------------------------------------------- /Release/jredis-core-ri-a.0-SNAPSHOT-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-ri-a.0-SNAPSHOT-sources.jar -------------------------------------------------------------------------------- /Release/jredis-examples-a.0-SNAPSHOT-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-examples-a.0-SNAPSHOT-sources.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.log 3 | *.classpath 4 | *.project 5 | *.settings 6 | *.DS_Store 7 | *.class 8 | jredis.tmproj 9 | *.iml 10 | *.idea 11 | -------------------------------------------------------------------------------- /Release/jredis-core-bench-a.0-SNAPSHOT-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-bench-a.0-SNAPSHOT-sources.jar -------------------------------------------------------------------------------- /extensions/README.markdown: -------------------------------------------------------------------------------- 1 | # JRedis Extensions 2 | 3 | Extended functionality for [JRedis] 4 | 5 | [JRedis]: http://github.com/alphazero/jredis 6 | -------------------------------------------------------------------------------- /Release/jredis-core-all-a.0-SNAPSHOT-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-all-a.0-SNAPSHOT-jar-with-dependencies.jar -------------------------------------------------------------------------------- /Release/jredis-core-ri-a.0-SNAPSHOT-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-ri-a.0-SNAPSHOT-jar-with-dependencies.jar -------------------------------------------------------------------------------- /Release/jredis-examples-a.0-SNAPSHOT-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-examples-a.0-SNAPSHOT-jar-with-dependencies.jar -------------------------------------------------------------------------------- /extensions/api/README.markdown: -------------------------------------------------------------------------------- 1 | # API/Sepcifications of JRedis Extensions 2 | 3 | Extended functionality for [JRedis] 4 | 5 | [JRedis]: http://github.com/alphazero/jredis 6 | -------------------------------------------------------------------------------- /Release/jredis-core-bench-a.0-SNAPSHOT-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/Release/jredis-core-bench-a.0-SNAPSHOT-jar-with-dependencies.jar -------------------------------------------------------------------------------- /extensions/ri/README.markdown: -------------------------------------------------------------------------------- 1 | # Reference implementation of JRedis Extensions 2 | 3 | Extended functionality for [JRedis] 4 | 5 | [JRedis]: http://github.com/alphazero/jredis 6 | -------------------------------------------------------------------------------- /DEV-NOTES.txt: -------------------------------------------------------------------------------- 1 | Wed Feb 1 2012 2 | 3 | * Merged chunk-pipelien branch to master 4 | REFERENCE commit a9cff24fd8f041ec181598c571989680a4e5ad15 is 5 | master prior to merge. 6 | 7 | -------------------------------------------------------------------------------- /documentation/design/diagrams/connector-design/connector-design-a0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/documentation/design/diagrams/connector-design/connector-design-a0.png -------------------------------------------------------------------------------- /documentation/design/diagrams/connector-design/connector-design-a0.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphazero/jredis/HEAD/documentation/design/diagrams/connector-design/connector-design-a0.1.png -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/all/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/api/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/bench/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/ri/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /examples/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /extensions/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /documentation/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /extensions/api/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /extensions/ri/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012, Joubin Houshyar. 2 | 3 | All parts of the original works in JReids are licensed under the 4 | Apache License ver 2.0 http://www.apache.org/licenses. 5 | 6 | Each sub-project contains a NOTICE file with additional notices, 7 | which may contain additional licensing information. 8 | 9 | END OF NOTICE 10 | 11 | -------------------------------------------------------------------------------- /core/bench/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Configure logging for testing 2 | log4j.rootLogger=INFO, stdout, logfile 3 | 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c] - %m%n 7 | 8 | log4j.appender.logfile=org.apache.log4j.RollingFileAppender 9 | log4j.appender.logfile.File=jredis-bench.log 10 | log4j.appender.logfile.MaxFileSize=512KB 11 | 12 | log4j.appender.logfile.MaxBackupIndex=1 13 | 14 | # Pattern to output: date priority [category] - message 15 | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.logfile.layout.ConversionPattern=%d %-5p [%c] - %m%n 17 | -------------------------------------------------------------------------------- /examples/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Configure logging for testing 2 | log4j.rootLogger=INFO, stdout, logfile 3 | 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c] - %m%n 7 | 8 | log4j.appender.logfile=org.apache.log4j.RollingFileAppender 9 | log4j.appender.logfile.File=jredis-examples.log 10 | log4j.appender.logfile.MaxFileSize=512KB 11 | 12 | log4j.appender.logfile.MaxBackupIndex=1 13 | 14 | # Pattern to output: date priority [category] - message 15 | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.logfile.layout.ConversionPattern=%d %-5p [%c] - %m%n 17 | -------------------------------------------------------------------------------- /core/api/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Configure logging for testing 2 | log4j.rootLogger=DEBUG, stdout, logfile 3 | 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c] - %m%n 7 | 8 | log4j.appender.logfile=org.apache.log4j.RollingFileAppender 9 | log4j.appender.logfile.File=target/log/jredis-api-test.log 10 | log4j.appender.logfile.MaxFileSize=512KB 11 | 12 | log4j.appender.logfile.MaxBackupIndex=1 13 | 14 | # Pattern to output: date priority [category] - message 15 | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.logfile.layout.ConversionPattern=%d %-5p [%c] - %m%n 17 | -------------------------------------------------------------------------------- /core/ri/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Configure logging for testing 2 | log4j.rootLogger=DEBUG, stdout, logfile 3 | 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c] - %m%n 7 | 8 | log4j.appender.logfile=org.apache.log4j.RollingFileAppender 9 | log4j.appender.logfile.File=target/log/jredis-ri-test.log 10 | log4j.appender.logfile.MaxFileSize=512KB 11 | 12 | log4j.appender.logfile.MaxBackupIndex=1 13 | 14 | # Pattern to output: date priority [category] - message 15 | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.logfile.layout.ConversionPattern=%d %-5p [%c] - %m%n 17 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/resource/Context.java: -------------------------------------------------------------------------------- 1 | package org.jredis.resource; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * {@link Context} provides basic context support for {@link Resource}s, 7 | * by providing methods for {@link String} parameter name/values and basic 8 | * namespace operations for generic {@link Object} types. 9 | * 10 | * @author Joubin Houshyar (alphazero@sensesay.net) 11 | * @version alpha.0, Apr 16, 2009 12 | * @since alpha.0 13 | * 14 | */ 15 | 16 | public interface Context { 17 | public String getParam (String key); 18 | public void setParam (String key, String value); 19 | Set getParamsKeys(); 20 | 21 | public Object get (String name); 22 | public void bind (String name, Object value); 23 | public void rebind (String name, Object value); 24 | } -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/support/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Utility classes to support this implementation. 19 | */ 20 | package org.jredis.ri.alphazero.support; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/resource/ResourceException.java: -------------------------------------------------------------------------------- 1 | package org.jredis.resource; 2 | 3 | import org.jredis.ClientRuntimeException; 4 | 5 | /** 6 | * The overall superclass for resource related exceptions, itself an 7 | * extension of ClientRuntimeException. 8 | * 9 | * @author Joubin Houshyar (alphazero@sensesay.net) 10 | * @version alpha.0, Apr 16, 2009 11 | * @since alpha.0 12 | * 13 | */ 14 | public class ResourceException extends ClientRuntimeException { 15 | 16 | 17 | /** 18 | * @param message 19 | * @param cause 20 | */ 21 | public ResourceException(String message, Throwable cause) { 22 | super(message, cause); 23 | } 24 | 25 | /** 26 | * @param message 27 | */ 28 | public ResourceException(String message) { 29 | super(message); 30 | } 31 | 32 | /** */ 33 | private static final long serialVersionUID = _specification.Version.major; 34 | 35 | } -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/RedisType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | /** 20 | * 21 | * @author Joubin Houshyar (alphazero@sensesay.net) 22 | */ 23 | public enum RedisType { 24 | NONE, 25 | string, 26 | list, 27 | set, 28 | hash 29 | } -------------------------------------------------------------------------------- /examples/src/main/java/org/jredis/examples/commands/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains examples of using {@link org.jredis.JRedis} and {@link org.jredis.JRedisFuture} commands. 19 | */ 20 | package org.jredis.examples.commands; 21 | 22 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/semantics/GZipCompressedStringCodec.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.semantics; 2 | 3 | import static org.jredis.ri.alphazero.support.GZip.compress; 4 | import static org.jredis.ri.alphazero.support.GZip.decompress; 5 | 6 | /** 7 | * 8 | * @author Joubin (alphazero@sensesay.net) 9 | * @version alpha.0, Aug 23, 2009 10 | * @since alpha.0 11 | * 12 | */ 13 | public class GZipCompressedStringCodec extends DefaultStringCodec { 14 | 15 | /* (non-Javadoc) 16 | * @see org.jredis.Codec.DefaultStringCodec#decode(byte[]) 17 | */ 18 | @Override 19 | public String decode (byte[] bytes) { 20 | return super.decode(decompress(bytes)); 21 | } 22 | 23 | /* (non-Javadoc) 24 | * @see org.jredis.Codec.DefaultStringCodec#encode(java.lang.String) 25 | */ 26 | @Override 27 | public byte[] encode (String value) { 28 | return compress(super.encode(value)); 29 | } 30 | } -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Native Client Interface Specification. 19 | *
20 | * This package depends on the Protocol package. 21 | * [TODO: document me!] 22 | *

23 | * This is an optional package. 24 | */ 25 | package org.jredis.connector; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/resource/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Optional package. 19 | *

20 | * This package provides the necessary types to support non-trivial usage of JRedis 21 | * implementation artifacts as resources in the JRedis usage contexts. 22 | */ 23 | package org.jredis.resource; -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package and child packages contain reference implementation alphazero 19 | * of the {@link org.jredis.JRedis} and {@link org.jredis.connector.Connection} 20 | * of the optional Connector specifications. 21 | */ 22 | package org.jredis.ri.alphazero; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/RequestListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import org.jredis.protocol.Request; 20 | import org.jredis.protocol.Response; 21 | 22 | public interface RequestListener { 23 | 24 | public void onResponse (Object context, Request request, Response response); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /extensions/api/src/main/java/org/jredis/cluster/support/HashAlgorithm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.cluster.support; 18 | 19 | /** 20 | * silly me? Remove this. 21 | * 22 | * @author joubin (alphazero@sensesay.net) 23 | * @date Mar 24, 2010 24 | * 25 | */ 26 | 27 | public interface HashAlgorithm { 28 | public long hash(byte[] kb); 29 | } 30 | -------------------------------------------------------------------------------- /extensions/api/src/main/java/org/jredis/cluster/ClusterType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.cluster; 18 | 19 | /** 20 | * We'll enumerate the various cluster types. 21 | * [TODO: document me!] 22 | * 23 | * @author joubin (alphazero@sensesay.net) 24 | * @date Mar 30, 2010 25 | * 26 | */ 27 | public enum ClusterType { 28 | CONSISTENT_HASH, 29 | STATIC_HASH 30 | } -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | import org.jredis.connector.Message; 20 | 21 | 22 | /** 23 | * [TODO: document me!] 24 | * 25 | * @author Joubin Houshyar (alphazero@sensesay.net) 26 | * @version alpha.0, 04/02/09 27 | * @since alpha.0 28 | * 29 | */ 30 | public interface Request extends Message {/* nop */} 31 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains the constructs that define the Java API semantics of the 19 | * JRedis clients. 20 | * 21 | * TODO: elaborate on the spec requirements. 22 | * 23 | * @author joubin (alphazero@sensesay.net) 24 | * 25 | * @since jredis-a.0 26 | * @compliance redis-0.09 27 | * 28 | */ 29 | package org.jredis; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains the constructs that reflect the Redis Protocol Specification 19 | * 20 | * TODO: elaborate on the spec requirements. 21 | * 22 | * @author joubin (alphazero@sensesay.net) 23 | * 24 | * @since jredis-a.0 25 | * @compliance redis-1.0 26 | * 27 | */ 28 | package org.jredis.protocol; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/SemanticSort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.semantics; 18 | 19 | import org.jredis.Sort; 20 | 21 | /** 22 | * [TODO: document me!] 23 | * 24 | * @author Joubin Houshyar (alphazero@sensesay.net) 25 | * @version alpha.0, Apr 14, 2009 26 | * @since alpha.0 27 | * 28 | */ 29 | 30 | public interface SemanticSort extends Sort {/* nop */} 31 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/StatusResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | /** 20 | * This is just a marker interface. All responses include an implied or explicit status. 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, 04/02/09 24 | * @since alpha.0 25 | * 26 | */ 27 | 28 | public interface StatusResponse extends Response {/* nop */} 29 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/BulkResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | 20 | /** 21 | * [TODO: document me!] 22 | * 23 | * @author Joubin Houshyar (alphazero@sensesay.net) 24 | * @version alpha.0, 04/02/09 25 | * @since alpha.0 26 | * 27 | */ 28 | public interface BulkResponse extends Response { 29 | 30 | /** 31 | * @return 32 | */ 33 | public byte[] getBulkData (); 34 | } 35 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/_specification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | /** 20 | * [TODO: document me!] 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, 04/02/09 24 | * @since alpha.0 25 | * 26 | */ 27 | public interface _specification { 28 | 29 | /** specification level */ 30 | public interface Version { 31 | long major = 0xA; 32 | long minor = 0x1; 33 | } 34 | } -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | /** 20 | * Generic immutable 2-tuple data struct. 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, Mar 20, 2010 24 | * @since alpha.0 25 | * 26 | */ 27 | 28 | class Pair { 29 | public final T1 t1; 30 | public final T2 t2; 31 | public Pair(T1 t1, T2 t2){ 32 | this.t1 = t1; 33 | this.t2 = t2; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This the top level package for the reference implementations of JRedis. 19 | * This package may in the future itself contain support classes for the 20 | * {@link org.jredis.JRedis} interface and other types in the root package 21 | * as barebones clients to redis. 22 | *

23 | * Child packages contain reference implementations of optional packages 24 | * of JRedis. 25 | */ 26 | package org.jredis.ri; -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/_specification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | /** 20 | * [TODO: document me!] 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, Apr 15, 2009 24 | * @since alpha.0 25 | * 26 | */ 27 | 28 | public interface _specification { 29 | 30 | /** specification level */ 31 | public interface Version { 32 | long major = 0xA; 33 | long minor = 0x0; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/Semantics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.semantics; 18 | 19 | import org.jredis.NotSupportedException; 20 | 21 | /** 22 | * [TODO: document me!] 23 | * 24 | * @author Joubin Houshyar (alphazero@sensesay.net) 25 | * @version alpha.0, Apr 14, 2009 26 | * @since alpha.0 27 | * 28 | */ 29 | 30 | public interface Semantics extends CodecManager{ 31 | public SemanticJRedis forType (Class type) throws NotSupportedException; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/SemanticQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.semantics; 18 | 19 | import java.util.List; 20 | 21 | import org.jredis.RedisException; 22 | 23 | /** 24 | * [TODO: document me!] 25 | * 26 | * @author Joubin Houshyar (alphazero@sensesay.net) 27 | * @version alpha.0, Apr 14, 2009 28 | * @since alpha.0 29 | * 30 | */ 31 | 32 | public interface SemanticQuery /*extends Query*/ { 33 | public List exec () throws IllegalStateException, RedisException; 34 | } 35 | -------------------------------------------------------------------------------- /extensions/3rd party Licenses/NET.SPY.MEMCACHED LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2009 Dustin Sallings 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/ZSetEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | /** 20 | * An entry in a Redis "sorted set" and returned by a subset Z* commands. 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, Mar 20, 2010 24 | * @since alpha.0 25 | * 26 | */ 27 | 28 | public interface ZSetEntry{ 29 | /** @return the value of this entry in a Redis sorted set */ 30 | byte[] getValue(); 31 | 32 | /** @return the score associated with the value */ 33 | double getScore(); 34 | } 35 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/ObjectEncoding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | /** 20 | * Internal Redis object encoding schemes. 21 | * 22 | * @see ObjectInfo#getEncoding() 23 | * @author Joubin Houshyar (alphazero@sensesay.net) 24 | * @version alpha.0, Mar 17, 2010 25 | * @since alpha.0 | Redis 1.3.5 26 | * 27 | */ 28 | public enum ObjectEncoding { 29 | /** Redis 'raw' */ 30 | RAW (), 31 | /** Redis 'int' */ 32 | INT (), 33 | /** Redis 'zipmap' */ 34 | ZIPMAP(), 35 | /** Redis 'hashtable' */ 36 | HASHTABLE, 37 | /** Redis 'embstr' */ 38 | EMBSTR, 39 | } -------------------------------------------------------------------------------- /core/api/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | org.jredis 8 | jredis-core 9 | a.0-SNAPSHOT 10 | 11 | 12 | 13 | JRedis - Core - API 14 | org.jredis 15 | jredis-core-api 16 | a.0-SNAPSHOT 17 | jar 18 | 19 | 20 | 21 | 22 | 23 | org.testng 24 | testng 25 | 7.7.0 26 | test 27 | 28 | 29 | 30 | log4j 31 | log4j 32 | 1.2.12 33 | 34 | 35 | commons-logging 36 | commons-logging 37 | 1.1.1 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/resource/_specification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.resource; 18 | 19 | /** 20 | * [TODO: document me!] 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, Apr 16, 2009 24 | * @since alpha.0 25 | * 26 | */ 27 | 28 | public interface _specification { 29 | 30 | /** specification level */ 31 | public interface Version { 32 | /** currently at toplevel spec version */ 33 | long major = org.jredis._specification.Version.major; 34 | /** currently at toplevel spec version */ 35 | long minor = org.jredis._specification.Version.minor; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/adhoc/AdHocTestNoConnection.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.adhoc; 2 | 3 | import java.util.concurrent.Future; 4 | 5 | import org.jredis.JRedisFuture; 6 | import org.jredis.connector.ConnectionSpec; 7 | import org.jredis.ri.alphazero.JRedisPipeline; 8 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 9 | import org.jredis.ri.alphazero.support.Log; 10 | 11 | public class AdHocTestNoConnection { 12 | private static final int NOT_A_USUAL_REDIS_PORT = 9999; 13 | public static void main(String[] args) throws Throwable { 14 | try { 15 | new AdHocTestNoConnection().run(); 16 | } catch (Exception e) { 17 | Log.error(e.getMessage()); 18 | } 19 | } 20 | final ConnectionSpec spec; 21 | JRedisFuture jredis = null; 22 | public AdHocTestNoConnection() throws Throwable{ 23 | spec = DefaultConnectionSpec.newSpec("localhost", NOT_A_USUAL_REDIS_PORT, 11, "jredis".getBytes()); 24 | jredis = new JRedisPipeline(spec); 25 | } 26 | /** this is not supposed to get called unless you actually run redis on port 9999 :P */ 27 | public void run() { 28 | final byte[] key = "foo".getBytes(); 29 | for(;;){ 30 | try { 31 | @SuppressWarnings("unused") 32 | Future fcntr = jredis.incr(key); 33 | } catch (Throwable t) { 34 | t.printStackTrace(); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/CodecManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.semantics; 18 | 19 | import org.jredis.Codec; 20 | import org.jredis.JRedis; 21 | 22 | /** 23 | * A CodecManager maintains a mapping of Java types to {@link Codec} instances 24 | * and can be used by a {@link JRedis} implementation to support the optional semantic 25 | * methods. 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Apr 14, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | public interface CodecManager { 34 | public Codec getCodec(Class type); 35 | public boolean register (Codec code, Class type); 36 | } 37 | -------------------------------------------------------------------------------- /Release/RELEASE-NOTES-Update-03122010.txt: -------------------------------------------------------------------------------- 1 | Final release for Redis 1.2.n compliant clients. 2 | 3 | REQUIREMENTS CHANGES: 4 | 5 | Requires Redis server 1.2.n. This release is NOT compatible with either Redis 1.000 or 2.n (development edge). 6 | 7 | See: 8 | http://code.google.com/p/redis/downloads/list 9 | 10 | NEW FEATURES: 11 | 12 | * Heartbeat 13 | 14 | Connectors will launch a heartbeat thread to maintain connections. Frequency can be set using ConnectionSpec, with default of 1/sec. 15 | 16 | * Synchronous semantics for Pipeline 17 | 18 | See JRedisPipeline.sync(). In a nutshell, allows for mixing in synchronous semantics when using the asynchronous pipelines. For example, you may issue a set of asynchronous commands (per JRedisFuture interface) and then use pipeline.sync() to obtain a JRedis (synchronous) interface to issue a blocking command. See UsingJredisPipeline.exampleUseofSyncInPipeline() (in /Examples) 19 | 20 | 21 | BUG FIX: 22 | 23 | A few bugs were reported and have been addressed. (Thanks to all who provided feedback.) 24 | 25 | See: 26 | http://github.com/alphazero/jredis/issues/closed 27 | 28 | ROAD MAP: 29 | 30 | Development focus will be on Redis 2.n compliance in tandem with Redis edge (http://github.com/antirez/redis), and maintenance for (this) 1.2.n compliant clients. 31 | 32 | /enjoy 33 | 34 | 03-12-2010 35 | NoVA 36 | 37 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/CommandNotImplemented.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | import org.jredis.ProviderException; 20 | import org.jredis._specification; 21 | 22 | 23 | /** 24 | * [TODO: document me!] 25 | * 26 | * @author Joubin Houshyar (alphazero@sensesay.net) 27 | * @version alpha.0, 04/02/09 28 | * @since alpha.0 29 | * 30 | */ 31 | public final class CommandNotImplemented extends ProviderException { 32 | /** */ 33 | private static final long serialVersionUID = _specification.Version.major; 34 | 35 | /** 36 | * @param command 37 | */ 38 | public CommandNotImplemented (Command command) { super(command.code + " is not supported!");} 39 | } -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package is optional. Its entirely debatable whether such mechanisms 19 | * have any legitimate place in JRedis, which is a connector to a type-less 20 | * system storing blobs of bytes. At this intial point, its place here simply 21 | * serves the purpose of keeping the issues that this package attempts to address 22 | * in mind. 23 | *

24 | * When all is said and done, all these artifacts will provide little more than 25 | * what a helper or wrapper object will provide -- JRedis can not be in the 26 | * type management business, as it does not control the object store. 27 | */ 28 | package org.jredis.semantics; -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/ConnectionFault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import java.net.SocketException; 20 | import org.jredis._specification; 21 | 22 | /** 23 | * [TODO: document me!] 24 | * 25 | * @author joubin (alphazero@sensesay.net) 26 | * @date Sep 12, 2010 27 | * 28 | */ 29 | 30 | public class ConnectionFault extends ConnectionException { 31 | /** */ 32 | private static final long serialVersionUID = _specification.Version.major; 33 | 34 | /** 35 | * @param string 36 | * @param e 37 | */ 38 | public ConnectionFault(String msg, SocketException e) { 39 | super(msg, e); 40 | } 41 | public ConnectionFault(String msg) { 42 | super(msg); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/RedisVersion.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2009 Joubin Houshyar 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package org.jredis.ri.alphazero; 18 | // 19 | ///** 20 | // * TODO: think about depcrecating this -- there really would be only one version 21 | // * of Redis. 22 | // *

23 | // * [TODO: document me!] 24 | // * 25 | // * @author Joubin Houshyar (alphazero@sensesay.net) 26 | // * @version alpha.0, Apr 12, 2009 27 | // * @since alpha.0 28 | // * 29 | // */ 30 | ////public enum RedisVersion { 31 | //// current_revision ("0.09"), 32 | //// beta_0_09 ("0.09"); 33 | //// public String id; 34 | //// public String getId() { return id; } 35 | //// private RedisVersion(String id) { 36 | //// this.id = id; 37 | //// } 38 | //// 39 | ////} 40 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/connection/UnexpectedEOFException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.connection; 18 | 19 | import org.jredis.connector.ConnectionException; 20 | import org.jredis.ri.alphazero._specification; 21 | 22 | 23 | /** 24 | * [TODO: document me!] 25 | * 26 | * @author Joubin Houshyar (alphazero@sensesay.net) 27 | * @version alpha.0, Apr 15, 2009 28 | * @since alpha.0 29 | * 30 | */ 31 | 32 | public class UnexpectedEOFException extends ConnectionException { 33 | /** 34 | * @param msg 35 | * @param e 36 | */ 37 | public UnexpectedEOFException(String msg) { 38 | super(msg); 39 | } 40 | 41 | /** */ 42 | private static final long serialVersionUID = _specification.Version.major; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/test/util/RunningAverage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.test.util; 18 | 19 | public class RunningAverage { 20 | private float avg; 21 | private long max; 22 | private long min = Long.MAX_VALUE; 23 | private long n; 24 | public RunningAverage() { 25 | avg = 0; 26 | n = 0; 27 | } 28 | public long onMeasure (long delta){ 29 | avg =((avg*n)+delta)/(++n); 30 | if(delta > max) max = delta; 31 | if(delta < min) min = delta; 32 | return (long) avg; 33 | } 34 | public long get () { return (long) avg; } 35 | /** 36 | * @return 37 | */ 38 | public long getMin () { return min; } 39 | public long getMax () { return max; } 40 | /** 41 | * 42 | */ 43 | public long getCount () { return n; } 44 | } 45 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/Redis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Annotation to mark complaint elements of JRedis implementations. 26 | * 27 | * [TODO: document me!] 28 | * 29 | * @author Joubin Houshyar (alphazero@sensesay.net) 30 | * @version alpha.0, 04/02/09 31 | * @since alpha.0 32 | * 33 | */ 34 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PACKAGE}) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | public @interface Redis { 37 | /** 38 | * @return array of strings denoting version of redis protocol supported 39 | */ 40 | String[] versions(); 41 | } 42 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/JRedisClientJProfileSubject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.bench; 18 | 19 | import org.jredis.JRedis; 20 | import org.jredis.RedisException; 21 | import org.jredis.bench.JRedisJProfileSubject; 22 | import org.jredis.ri.alphazero.JRedisClient; 23 | 24 | /** 25 | * [TODO: document me!] 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Apr 24, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | public class JRedisClientJProfileSubject extends JRedisJProfileSubject{ 34 | 35 | public static void main(String[] args) throws RedisException { 36 | JRedis jredis; 37 | jredis = new JRedisClient("localhost", 6379, "jredis", 0); 38 | new JRedisJProfileSubject (jredis).run(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/README: -------------------------------------------------------------------------------- 1 | README : JRedis Module Core 2 | 3 | ---------------------------------------------------------- 4 | BUILD 5 | ---------------------------------------------------------- 6 | 7 | For build instructions refer to the README in root. 8 | 9 | ---------------------------------------------------------- 10 | MODULES 11 | ---------------------------------------------------------- 12 | 13 | The Core module is composed of all the core elements that 14 | are used to create JRedis clients and connectors for the 15 | Redis server. 16 | 17 | This includes: 18 | 19 | - the specification (API), 20 | - the reference implementation (RI), 21 | - the benchmark module (BENCH) 22 | 23 | An additional module ALL is a virtual module used to 24 | create a unified jar for the core. (Its a hack of manve; 25 | likely will be replaced by an assembly directive in the 26 | future. If you are a maven guru let me know how to do it 27 | better.) 28 | 29 | * JRedis users 30 | 31 | If you want to use JRedis clients and connectors, you'll 32 | only need the classes of API and RI. 33 | 34 | Depending on your preferences and requirements, you may 35 | either uses the individual jars for each module, OR, 36 | simply use the jar 'with dependencies' in RI's target 37 | directory. 38 | 39 | Each module should also produce a source jar. (See build 40 | instructions.) 41 | 42 | No javadocs are produced as of now. (c.f. maven newbiness). 43 | 44 | **** PLEASE REFER TO UNIT TEST INFO IN ROOT README ***** 45 | 46 | /end 47 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/RI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * [TODO: document me!] 26 | * 27 | * @author joubin (alphazero@sensesay.net) 28 | * @date Sep 17, 2010 29 | * 30 | */ 31 | 32 | public interface RI { 33 | public enum Release { 34 | ALPHA, 35 | BETA, 36 | FINAL 37 | } 38 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PACKAGE, ElementType.CONSTRUCTOR, ElementType.FIELD}) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | public @interface Version { 41 | int major() default 2; 42 | int minor() default 0; 43 | Release release() default Release.ALPHA; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/NotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | 20 | /** 21 | * Providers can throw this exception in response for requests for optional 22 | * aspects of Redis Specification. 23 | * 24 | * @author Joubin Houshyar (alphazero@sensesay.net) 25 | * @version alpha.0, 04/02/09 26 | * @since alpha.0 27 | * 28 | */ 29 | public class NotSupportedException extends ProviderException { 30 | 31 | /** */ 32 | private static final long serialVersionUID = _specification.Version.major; 33 | 34 | /** 35 | * @param string 36 | */ 37 | public NotSupportedException(String string) { 38 | super (string); 39 | } 40 | /** 41 | * @param string 42 | */ 43 | public NotSupportedException(String string, Throwable cause) { 44 | super (string, cause); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/ZSetEntryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import org.jredis.ZSetEntry; 20 | import org.jredis.ri.alphazero.support.DefaultCodec; 21 | 22 | /** 23 | * [TODO: document me!] 24 | * 25 | * @author Joubin Houshyar (alphazero@sensesay.net) 26 | * @version alpha.0, Mar 20, 2010 27 | * @since alpha.0 28 | * 29 | */ 30 | 31 | class ZSetEntryImpl extends Pair implements ZSetEntry { 32 | 33 | public ZSetEntryImpl (byte[] valueBytes, byte[] scoreBytes) { 34 | super(valueBytes, scoreBytes); 35 | } 36 | /* (non-Javadoc) @see org.jredis.ZSetEntry#getScore() */ 37 | public double getScore () { return DefaultCodec.toDouble(t2); } 38 | 39 | /* (non-Javadoc) @see org.jredis.ZSetEntry#getValue() */ 40 | public byte[] getValue () { return t1;} 41 | } 42 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | org.jredis 8 | jredis 9 | a.0-SNAPSHOT 10 | 11 | 12 | 13 | JRedis - EXAMPLES 14 | org.jredis 15 | jredis-examples 16 | a.0-SNAPSHOT 17 | jar 18 | 19 | 20 | 21 | org.jredis 22 | jredis-core-all 23 | a.0-SNAPSHOT 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | maven-assembly-plugin 32 | 33 | 34 | simple-install 35 | package 36 | 37 | attached 38 | 39 | 40 | 41 | 42 | 43 | jar-with-dependencies 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/NotConnectedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | import org.jredis.JRedis; 21 | import org.jredis._specification; 22 | 23 | 24 | /** 25 | * This connection will should be thrown if users issue any calls on 26 | * the {@link JRedis} interface after a call to either {@link JRedis#quit()} 27 | * or {@link JRedis#shutdown()} 28 | * 29 | * [TODO: document me!] 30 | * 31 | * @author Joubin Houshyar (alphazero@sensesay.net) 32 | * @version alpha.0, 04/02/09 33 | * @since alpha.0 34 | * 35 | */ 36 | public class NotConnectedException extends ClientRuntimeException { 37 | /** */ 38 | private static final long serialVersionUID = _specification.Version.major; 39 | 40 | public NotConnectedException (String msg) { 41 | super (msg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /core/api/src/main/resources/META-INF/redis-commands-2.4.n.txt: -------------------------------------------------------------------------------- 1 | auth 2 | ping 3 | echo 4 | set 5 | setnx 6 | setex 7 | get 8 | del 9 | exists 10 | setbit 11 | getbit 12 | setrange 13 | getrange 14 | incr 15 | decr 16 | incrby 17 | decrby 18 | select 19 | randomkey 20 | keys 21 | dbsize 22 | lastsave 23 | save 24 | bgsave 25 | bgrewriteaof 26 | shutdown 27 | move 28 | rename 29 | renamenx 30 | lpush 31 | rpush 32 | lpushx 33 | rpushx 34 | linsert 35 | lpop 36 | rpop 37 | llen 38 | lindex 39 | lrange 40 | ltrim 41 | type 42 | lset 43 | sadd 44 | srem 45 | smove 46 | sismember 47 | scard 48 | spop 49 | srandmember 50 | sinter 51 | sinterstore 52 | sunion 53 | sunionstore 54 | sdiff 55 | sdiffstore 56 | sync 57 | flushdb 58 | flushall 59 | sort 60 | lrem 61 | rpoplpush 62 | info 63 | mget 64 | monitor 65 | expire 66 | expireat 67 | getset 68 | ttl 69 | persist 70 | slaveof 71 | debug 72 | mset 73 | msetnx 74 | zadd 75 | zincrby 76 | zrange 77 | zrangebyscore 78 | zrevrangebyscore 79 | zcount 80 | zrevrange 81 | zcard 82 | zrem 83 | zscore 84 | zremrangebyscore 85 | multi 86 | exec 87 | discard 88 | blpop 89 | brpop 90 | brpoplpush 91 | append 92 | strlen 93 | zrank 94 | zrevrank 95 | hset 96 | hsetnx 97 | hget 98 | hmset 99 | hmget 100 | hdel 101 | hlen 102 | zremrangebyrank 103 | zunionstore 104 | zinterstore 105 | hkeys 106 | hvals 107 | hgetall 108 | hexists 109 | config 110 | hincrby 111 | subscribe 112 | unsubscribe 113 | psubscribe 114 | punsubscribe 115 | publish 116 | watch 117 | unwatch 118 | object 119 | client 120 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/cluster/models/KetamaHashAlgoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.cluster.models; 18 | 19 | import org.jredis.cluster.support.HashAlgorithm; 20 | import org.jredis.cluster.support.HashAlgorithmProviderTestBase; 21 | import org.jredis.ri.cluster.model.KetamaHashProvider; 22 | 23 | /** 24 | * [TODO: document me!] 25 | * 26 | * @author joubin (alphazero@sensesay.net) 27 | * @date Mar 27, 2010 28 | * 29 | */ 30 | 31 | public class KetamaHashAlgoTest extends HashAlgorithmProviderTestBase { 32 | 33 | // ------------------------------------------------------------------------ 34 | // super overrides 35 | // ------------------------------------------------------------------------ 36 | 37 | /* (non-Javadoc) @see org.jredis.cluster.ProviderTestBase#newProviderInstance() */ 38 | @Override 39 | protected HashAlgorithm newProviderInstance () { 40 | return new KetamaHashProvider(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /extensions/3rd party Licenses/NET.SPY.MEMCACHED NOTICE: -------------------------------------------------------------------------------- 1 | NOTICE: 2 | 3 | Portions of the reference implementation libaray for JRedis/extensions uses 4 | verbatim and/or modified derivatives of original work by Dustin Sallings in 5 | net.spy.memcached (Java client for Memcached). Documentation in extensions/ri 6 | highlights such usage in JRedis library. 7 | 8 | Original work's Copyright notice follows: 9 | 10 | -- BEGIN -- 11 | 12 | Copyright (c) 2006-2009 Dustin Sallings 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy of 15 | this software and associated documentation files (the "Software"), to deal in 16 | the Software without restriction, including without limitation the rights to 17 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 18 | of the Software, and to permit persons to whom the Software is furnished to do 19 | so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in all 22 | copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | SOFTWARE. 31 | 32 | -- END -- 33 | 34 | END OF NOTICE 35 | 36 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/ConnectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import java.net.SocketException; 20 | 21 | import org.jredis.ClientRuntimeException; 22 | import org.jredis._specification; 23 | 24 | /** 25 | * [TODO: document me!] 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Apr 15, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | abstract public class ConnectionException extends ClientRuntimeException{ 34 | 35 | /** */ 36 | private static final long serialVersionUID = _specification.Version.major; 37 | 38 | /** 39 | * TODO: not sure if specifying {@link SocketException} is a good idea. 40 | * @param msg 41 | * @param e 42 | */ 43 | public ConnectionException(String msg, SocketException e) { 44 | super(msg, e); 45 | } 46 | 47 | /** 48 | * @param msg 49 | */ 50 | public ConnectionException(String msg) { 51 | super(msg); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/bench/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | org.jredis 8 | jredis-core 9 | a.0-SNAPSHOT 10 | 11 | 12 | 13 | JRedis - Core - BENCH 14 | org.jredis 15 | jredis-core-bench 16 | a.0-SNAPSHOT 17 | jar 18 | 19 | 20 | 21 | 22 | 23 | org.jredis 24 | jredis-core-api 25 | a.0-SNAPSHOT 26 | 27 | 28 | 29 | 30 | org.jredis 31 | jredis-core-ri 32 | a.0-SNAPSHOT 33 | 34 | 35 | 36 | 37 | 38 | 39 | maven-assembly-plugin 40 | 41 | 42 | simple-install 43 | package 44 | 45 | attached 46 | 47 | 48 | 49 | 50 | 51 | jar-with-dependencies 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/semantics/BasicCodecManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.semantics; 18 | 19 | import java.util.Map; 20 | import java.util.concurrent.ConcurrentHashMap; 21 | 22 | import org.jredis.Codec; 23 | 24 | // REFACTOR: this doesn't belong here 25 | // 26 | public final class BasicCodecManager implements CodecManager { 27 | private final Map, Codec> map = new ConcurrentHashMap, Codec>(); 28 | public void foo () { 29 | Codec stringCodec = null; 30 | map.put(String.class, stringCodec); 31 | } 32 | 33 | @SuppressWarnings("unchecked") 34 | @Override 35 | public Codec getCodec(Class type) { 36 | return (Codec) map.get(type); 37 | } 38 | 39 | @Override 40 | public boolean register(Codec code, Class type) { 41 | Codec existing = map.get(type); 42 | if(null == existing){ 43 | if (code.supports(type)){ 44 | map.put(type, code); 45 | return true; 46 | } 47 | } 48 | return false; 49 | } 50 | } -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/SimpleBenchJRedisClient.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.bench; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.jredis.JRedis; 6 | import org.jredis.RedisException; 7 | import org.jredis.connector.ConnectionSpec; 8 | import org.jredis.ri.alphazero.JRedisClient; 9 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 10 | 11 | public class SimpleBenchJRedisClient { 12 | public static void main(String[] args) { 13 | try { 14 | new SimpleBenchJRedisClient().run(); 15 | } catch (RedisException e) { 16 | e.printStackTrace(); 17 | } 18 | } 19 | 20 | private void run() throws RedisException { 21 | int database = 11; 22 | ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes()); 23 | JRedis jredis = new JRedisClient(connSpec); 24 | 25 | byte[] key = "bench-jredis-pipeline-key".getBytes(); 26 | int iters = 100 * 1000; 27 | 28 | try { 29 | cleandb(jredis); 30 | } catch (Throwable e) { 31 | e.printStackTrace(); 32 | return; 33 | } 34 | 35 | for(;;){ 36 | Long counter = null; 37 | long start = System.nanoTime(); 38 | for(int i=0;i 32 | * @param keyClass 33 | * @return the Codec used to 34 | */ 35 | public Codec getKeyCodec(Class keyClass); 36 | /** 37 | * @param 38 | * @param keyClass 39 | * @param keyCodec 40 | * @return 41 | */ 42 | public Semantics setKeyCodec(Class keyClass, Codec keyCodec); 43 | /** 44 | * @param 45 | * @param valueClass 46 | * @return 47 | */ 48 | public Codec getValueCodec(Class valueClass); 49 | /** 50 | * @param 51 | * @param valueClass 52 | * @param valueCdec 53 | * @return 54 | */ 55 | public Semantics setValueCodec(Class valueClass, Codec valueCdec); 56 | } 57 | -------------------------------------------------------------------------------- /redis_version_compliance.txt: -------------------------------------------------------------------------------- 1 | compliance: Redis 3.0 2 | tested with: Redis 2.9.102 (4ad1b2f8/0) 64 bit 3 | 4 | -- compliance report (see api/src/test/org/jredis/compliance package -- 5 | 6 | /// non-compliance report for JRedis ////////////// 7 | [ 0] auth 8 | [ 1] setex 9 | [ 2] setbit 10 | [ 3] getbit 11 | [ 4] setrange 12 | [ 5] getrange 13 | [ 6] select 14 | [ 7] shutdown 15 | [ 8] lpushx 16 | [ 9] rpushx 17 | [10] linsert 18 | [11] sync 19 | [12] monitor 20 | [13] persist 21 | [14] zrevrangebyscore 22 | [15] exec 23 | [16] blpop 24 | [17] brpop 25 | [18] brpoplpush 26 | [19] strlen 27 | [20] hsetnx 28 | [21] hmset 29 | [22] hmget 30 | [23] zunionstore 31 | [24] zinterstore 32 | [25] config 33 | [26] hincrby 34 | [27] subscribe 35 | [28] unsubscribe 36 | [29] psubscribe 37 | [30] punsubscribe 38 | [31] publish 39 | [32] watch 40 | [33] unwatch 41 | [34] object 42 | [35] client 43 | 44 | ///////////////////////////////////////////////////////// 45 | 46 | /// non-compliance report for JRedisFuture ////////////// 47 | [ 0] auth 48 | [ 1] setex 49 | [ 2] setbit 50 | [ 3] getbit 51 | [ 4] setrange 52 | [ 5] getrange 53 | [ 6] select 54 | [ 7] shutdown 55 | [ 8] lpushx 56 | [ 9] rpushx 57 | [10] linsert 58 | [11] sync 59 | [12] monitor 60 | [13] persist 61 | [14] zrevrangebyscore 62 | [15] multi 63 | [16] exec 64 | [17] discard 65 | [18] blpop 66 | [19] brpop 67 | [20] brpoplpush 68 | [21] strlen 69 | [22] hsetnx 70 | [23] hmset 71 | [24] hmget 72 | [25] zunionstore 73 | [26] zinterstore 74 | [27] config 75 | [28] hincrby 76 | [29] subscribe 77 | [30] unsubscribe 78 | [31] psubscribe 79 | [32] punsubscribe 80 | [33] publish 81 | [34] watch 82 | [35] unwatch 83 | [36] object 84 | [37] client 85 | 86 | ///////////////////////////////////////////////////////// 87 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/connection/AsyncPipelineConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.connection; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | import org.jredis.connector.ConnectionSpec; 21 | 22 | /** 23 | * 24 | * @author Joubin Houshyar (alphazero@sensesay.net) 25 | * @version alpha.0, Sep 7, 2009 26 | * @since alpha.0 27 | * 28 | */ 29 | 30 | public class AsyncPipelineConnection extends PipelineConnectionBase{ 31 | 32 | // ------------------------------------------------------------------------ 33 | // Properties 34 | // ------------------------------------------------------------------------ 35 | // ------------------------------------------------------------------------ 36 | // Constructor(s) 37 | // ------------------------------------------------------------------------ 38 | /** 39 | * @param spec 40 | * @throws ClientRuntimeException 41 | */ 42 | public AsyncPipelineConnection (ConnectionSpec spec) throws ClientRuntimeException { 43 | super(spec.setModality(Modality.Asynchronous)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/ri/cluster/DefaultClusterSpecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.cluster; 18 | 19 | import org.jredis.cluster.ClusterNodeSpec; 20 | import org.jredis.cluster.ClusterSpec; 21 | import org.jredis.cluster.ClusterSpecProviderTestBase; 22 | import org.jredis.connector.ConnectionSpec; 23 | import org.jredis.ri.cluster.DefaultClusterSpec; 24 | 25 | /** 26 | * [TODO: document me!] 27 | * 28 | * @author joubin (alphazero@sensesay.net) 29 | * @date Mar 27, 2010 30 | * 31 | */ 32 | 33 | public class DefaultClusterSpecTest extends ClusterSpecProviderTestBase { 34 | /* (non-Javadoc) @see org.jredis.ri.ProviderTestBase#newProviderInstance() */ 35 | @Override 36 | protected ClusterSpec newProviderInstance () { 37 | return new DefaultClusterSpec (); 38 | } 39 | 40 | /* (non-Javadoc) @see org.jredis.cluster.ClusterSpecProviderTestBase#newNodeSpec(org.jredis.connector.ConnectionSpec) */ 41 | @Override 42 | protected ClusterNodeSpec newNodeSpec (ConnectionSpec connectionSpec) { 43 | return new DefaultClusterNodeSpec(connectionSpec); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/Codec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | 20 | 21 | /** 22 | * Defines the necessary methods for a Java type encoder-decoder. Implementations of this 23 | * interface can be registered with a {@link CodecManager} used by a {@link JRedis} implementation 24 | * (whether per instance or by other relations per JRedis provider implementation), and used 25 | * during the encoding of an semantic java type into {@link byte[]} and back. 26 | * 27 | * @author Joubin (alphazero@sensesay.net) 28 | * @version alpha.0, Apr 14, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | public interface Codec { 34 | /** 35 | * @param bytes 36 | * @return an instance of type T corresponding to the value of decoded bytes 37 | */ 38 | public T decode (byte[] bytes); 39 | /** 40 | * @param object 41 | * @return 42 | */ 43 | public byte[] encode (T object); 44 | /** 45 | * @param type 46 | * @return whether this codec supports the (en/de)coding of the type T 47 | */ 48 | public boolean supports (Class type); 49 | } 50 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/ri/cluster/ClusterNodeSpecImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.cluster; 18 | 19 | import org.jredis.cluster.ClusterNodeSpec; 20 | import org.jredis.cluster.ClusterNodeSpecProviderTestBase; 21 | import org.jredis.connector.ConnectionSpec; 22 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 23 | 24 | /** 25 | * [TODO: document me!] 26 | * 27 | * @author joubin (alphazero@sensesay.net) 28 | * @date Mar 27, 2010 29 | * 30 | */ 31 | 32 | public class ClusterNodeSpecImplTest extends ClusterNodeSpecProviderTestBase { 33 | /* (non-Javadoc) @see org.jredis.ri.ProviderTestBase#newProviderInstance() */ 34 | @Override 35 | final protected ClusterNodeSpec newProviderInstance () { 36 | return new DefaultClusterNodeSpec (DefaultConnectionSpec.newSpec()); 37 | } 38 | /* (non-Javadoc) @see org.jredis.cluster.ClusterNodeSpecProviderTestBase#newProviderInstance(org.jredis.connector.ConnectionSpec) */ 39 | @Override 40 | final protected ClusterNodeSpec newProviderInstance (ConnectionSpec connectionSpec) { 41 | return new DefaultClusterNodeSpec (connectionSpec); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/semantics/DefaultStringCodec.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.semantics; 2 | 3 | import java.nio.charset.Charset; 4 | import org.jredis.Codec; 5 | 6 | /** 7 | * Nothing to see here, folks. Your basic {@link String#getBytes(Charset)} and {@link String#String(byte[], Charset)} 8 | * wrapper, and of course you can get to set the {@link Charset} if the default UTF-8 {@link Charset} is 9 | * not to your liking. 10 | * 11 | * @author Joubin (alphazero@sensesay.net) 12 | * @version alpha.0, Aug 23, 2009 13 | * @since alpha.0 14 | * 15 | */ 16 | public class DefaultStringCodec implements Codec { 17 | /** Default supported character set is UTF-8 */ 18 | public final static Charset DEFAULT_CHARSET = Charset.forName ("UTF-8"); 19 | /** */ 20 | @SuppressWarnings("unused") 21 | private final Charset charSet; // java 1.6 22 | /** 23 | * 24 | */ 25 | public DefaultStringCodec() { 26 | this(DEFAULT_CHARSET); 27 | } 28 | /** 29 | * @param charset 30 | */ 31 | public DefaultStringCodec(Charset charset){ 32 | this.charSet = charset; 33 | } 34 | 35 | /* (non-Javadoc) 36 | * @see org.jredis.Codec#decode(byte[]) 37 | */ 38 | @Override 39 | public String decode (byte[] bytes) { 40 | return new String(bytes); 41 | // return new String(bytes, charSet); // java 1.6 42 | } 43 | 44 | /* (non-Javadoc) 45 | * @see org.jredis.Codec#encode(java.lang.Object) 46 | */ 47 | @Override 48 | public byte[] encode (String value) { 49 | return value.getBytes(); 50 | // return value.getBytes(charSet); 51 | } 52 | 53 | /* (non-Javadoc) 54 | * @see org.jredis.Codec#supports(java.lang.Class) 55 | */ 56 | @Override 57 | public boolean supports (Class type) { 58 | return type.equals(String.class) ? true : false; 59 | } 60 | } -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/ProviderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | 20 | 21 | /** 22 | * Used by JRedis implementation providers to indicate an exception related to the 23 | * implementation of the specification. Effectively, this exception and its extensions 24 | * should only be thrown when a fault has occurred that is neither a {@link SystemException}, 25 | * nor a Redis prompted server side error. 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, 04/02/09 29 | * @since alpha.0 30 | * 31 | */ 32 | public class ProviderException extends ClientRuntimeException { 33 | 34 | /** */ 35 | public static final long version = _specification.Version.major; 36 | 37 | /** */ 38 | private static final long serialVersionUID = _specification.Version.major; 39 | 40 | 41 | /** 42 | * @param message 43 | */ 44 | public ProviderException(String message) { 45 | super(message); 46 | // TODO Auto-generated constructor stub 47 | } 48 | 49 | /** 50 | * @param message 51 | * @param cause 52 | */ 53 | public ProviderException(String message, Throwable cause) { 54 | super(message, cause); 55 | // TODO Auto-generated constructor stub 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/resource/Resource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.resource; 18 | 19 | 20 | 21 | /** 22 | * 23 | * @author Joubin Houshyar (alphazero@sensesay.net) 24 | * @version alpha.0, Apr 16, 2009 25 | * @since alpha.0 26 | * 27 | */ 28 | 29 | public interface Resource { 30 | 31 | /** 32 | * @return the resource type specific interface. 33 | */ 34 | public T getInterface(); 35 | 36 | /** 37 | * Sets the resource context. 38 | * 39 | * @see Context 40 | * @param context the context for this resource. 41 | * @throws ResourceException if the resource context provided is either insufficient, or, 42 | * if the new context (regardless of its utility) can not be used. (For example, it already 43 | * has a context and re-setting of contexts is not supported or permissible.) 44 | */ 45 | public void setContext (Context context) throws ResourceException; 46 | 47 | /** 48 | * @see Context 49 | * @return the context for this resource. 50 | * @throws ResourceException if the resource for whatever reason can not (or will not) 51 | * return a reference to its context. (Security considerations, for example.) 52 | */ 53 | public Context getContext () throws ResourceException; 54 | } 55 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/MultiBulkResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | import java.io.InputStream; 20 | import java.util.List; 21 | 22 | import org.jredis.ClientRuntimeException; 23 | import org.jredis.ProviderException; 24 | 25 | 26 | 27 | /** 28 | * [TODO: document me!] 29 | * 30 | * @author Joubin Houshyar (alphazero@sensesay.net) 31 | * @version alpha.0, 04/02/09 32 | * @since alpha.0 33 | * 34 | */ 35 | public interface MultiBulkResponse extends Response { 36 | /** 37 | * @return the List of values returned from the server. List may contain null elements, 38 | * reflecting 'nil' values per redis specification. The operation {@link List#size()} will return 39 | * the same number that is received from the server, with the exception 40 | * 41 | * @throws ClientRuntimeException if data access is attempted before the response has been read, or, 42 | * if the provided {@link InputStream} presents any problems. 43 | * 44 | * @throws ProviderException for any other errors beyond system level (stream, network, etc.) or 45 | * user errors (such as attempting getData before the response has been read. 46 | */ 47 | public List getMultiBulkData () throws ClientRuntimeException, ProviderException; 48 | } 49 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/SimpleBenchJRedisAsync.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.bench; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | import java.util.concurrent.Future; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.jredis.JRedisFuture; 8 | import org.jredis.connector.ConnectionSpec; 9 | import org.jredis.ri.alphazero.JRedisAsyncClient; 10 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 11 | 12 | public class SimpleBenchJRedisAsync { 13 | public static void main(String[] args) { 14 | new SimpleBenchJRedisAsync().run(); 15 | } 16 | 17 | private void run() { 18 | int database = 11; 19 | ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes()); 20 | JRedisFuture jredis = new JRedisAsyncClient(connSpec); 21 | 22 | byte[] key = "bench-jredis-pipeline-key".getBytes(); 23 | int iters = 100 * 1000; 24 | 25 | try { 26 | cleandb(jredis); 27 | } catch (Throwable e) { 28 | e.printStackTrace(); 29 | return; 30 | } 31 | 32 | for(;;){ 33 | Future frCounter = null; 34 | long start = System.nanoTime(); 35 | for(int i=0;i frCounter = null; 35 | long start = System.nanoTime(); 36 | for(int i=0;i 3 | 4.0.0 4 | 5 | 6 | 7 | org.jredis 8 | jredis-core 9 | a.0-SNAPSHOT 10 | 11 | 12 | 13 | JRedis - Core - RI 14 | org.jredis 15 | jredis-core-ri 16 | a.0-SNAPSHOT 17 | jar 18 | 19 | 20 | 21 | 22 | org.jredis 23 | jredis-core-api 24 | a.0-SNAPSHOT 25 | 26 | 27 | 28 | org.testng 29 | testng 30 | 7.7.0 31 | test 32 | 33 | 34 | 35 | log4j 36 | log4j 37 | 1.2.12 38 | 39 | 40 | commons-logging 41 | commons-logging 42 | 1.1.1 43 | 44 | 45 | 46 | 47 | 48 | 49 | maven-assembly-plugin 50 | 2.1 51 | 52 | 53 | simple-install 54 | package 55 | 56 | attached 57 | 58 | 59 | 60 | 61 | 62 | jar-with-dependencies 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/JRedisChunkedPipeline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2012 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import java.util.concurrent.Future; 20 | 21 | import org.jredis.ClientRuntimeException; 22 | import org.jredis.JRedisFuture; 23 | import org.jredis.ProviderException; 24 | import org.jredis.connector.Connection; 25 | import org.jredis.connector.ConnectionSpec; 26 | import org.jredis.protocol.Command; 27 | import org.jredis.protocol.Response; 28 | import org.jredis.ri.alphazero.connection.ChunkedPipelineConnection; 29 | 30 | /** 31 | * An asynchronous pipeline supporting {@link JRedisFuture} api, 32 | * utilizing the {@link ChunkedPipelineConnection}, providing 33 | * maximal throughput as a forwarding pipe to Redis server. 34 | * 35 | * Thread safe. Use only one instance per application. 36 | * 37 | * 38 | * @author Joubin 39 | * 40 | */ 41 | public class JRedisChunkedPipeline extends JRedisFutureSupport { 42 | 43 | final private Connection connection; 44 | public JRedisChunkedPipeline(ConnectionSpec spec){ 45 | assert spec != null : "spec is null"; 46 | connection = new ChunkedPipelineConnection(spec); 47 | } 48 | @Override 49 | protected Future queueRequest(Command cmd, byte[]... args) 50 | throws ClientRuntimeException, ProviderException 51 | { 52 | return connection.queueRequest(cmd, args); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/ResponseStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | /** 20 | * [TODO: document me!] 21 | * 22 | * @author Joubin Houshyar (alphazero@sensesay.net) 23 | * @version alpha.0, 04/02/09 24 | * @since alpha.0 25 | * 26 | */ 27 | public final class ResponseStatus { 28 | 29 | /** Status code enum -- error or ok */ 30 | public enum Code { OK, ERROR, CIAO } 31 | 32 | /** 33 | * Hopefully we have many none error response statuses 34 | * and we don't want to keep instantiating them. 35 | * Use this singleton instance for non-error status. 36 | */ 37 | public static final ResponseStatus STATUS_OK = new ResponseStatus (ResponseStatus.Code.OK); 38 | 39 | public static final ResponseStatus STATUS_CIAO = new ResponseStatus (ResponseStatus.Code.CIAO); 40 | 41 | /** */ 42 | private final Code code; 43 | /** */ 44 | private String msg; 45 | 46 | /** 47 | * @param code 48 | */ 49 | public ResponseStatus(ResponseStatus.Code code) { 50 | this.code = code; 51 | this.msg = ""; 52 | } 53 | 54 | /** 55 | * @param code 56 | * @param msg 57 | */ 58 | public ResponseStatus(ResponseStatus.Code code, String msg) { 59 | this.code = code; 60 | this.msg = msg; 61 | } 62 | 63 | public ResponseStatus.Code code() { return code; } 64 | public String message() {return msg; } 65 | public boolean isError () { return this.code==Code.ERROR; } 66 | } -------------------------------------------------------------------------------- /extensions/api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | 8 | org.jredis 9 | jredis-extensions 10 | ${jredisVersion} 11 | 12 | 13 | 14 | JRedis - Extensions - API 15 | org.jredis 16 | jredis-extensions-api 17 | ${jredisVersion} 18 | jar 19 | 20 | 21 | 22 | 23 | 24 | org.jredis 25 | jredis-core-api 26 | ${jredisVersion} 27 | 28 | 29 | 30 | 31 | org.jredis 32 | jredis-core-ri 33 | ${jredisVersion} 34 | 35 | 36 | 37 | 38 | org.testng 39 | testng 40 | 6.1.1 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | maven-assembly-plugin 49 | 2.1 50 | 51 | 52 | simple-install 53 | package 54 | 55 | attached 56 | 57 | 58 | 59 | 60 | 61 | jar-with-dependencies 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Release/RELEASE-NOTES-Update-08132009.txt: -------------------------------------------------------------------------------- 1 | This update includes changes to the JRedis interface, as previously announced. 2 | 3 | API CHANGES: 4 | 5 | As of this release update, you will need to specify the password and/or db on connect time. 6 | You will no longer be able to change the selected db for a connection. 7 | The default db selected on connect is db 0. 8 | 9 | The test suites are all positive on these changes. (Fairly substantial changes in the internal 10 | connector packages.) That said, I have not had the time to conduct exhaustive testing beyond 11 | the test suites. If you find a bug, please report it under issues in github. If you post to 12 | the Redis newsgroup, please indicate JRedis in the subject line as I usually just skim the 13 | list's subjects and may miss your feedback. 14 | 15 | BUG FIX: 16 | 17 | Previous releases had a bug that reconnected to db 0 on timed out connections. Per the changes 18 | in this release, the automatic reconnect will connect to the Redis server using the authorization 19 | credentials (if any), and, the db you specified, on the initial connection (using new JRedisClient()). 20 | 21 | 22 | ROAD MAP: 23 | 24 | Now that we have the db select issue out of the way, the way is clear for connection pooling and 25 | thread safe connections. 26 | 27 | Also, the ConnectionFactory interface of the specification may be finally brought into use to allow 28 | for complete user control over the Redis and TCP connection characteristics. (Current implementation 29 | relies on a default ConnectionSpec to create its connection.) This will potentially of use to domains 30 | that require specialized settings for the buffer sizes, tcp preferences, etc. 31 | 32 | Pipe-lining is also an upcoming addtion. Frankly its been held back for no better reason other than 33 | my laziness and/or other pressing issues occupying my time. A rough implementation has been played 34 | with and the performance characteristic increases are in the order of magnitude. (100,000 ops/sec vs 35 | 30,000 for the synch clients on my machine). Of course these are throughput measures, and not latency. 36 | 37 | /enjoy 38 | 39 | 08-13-2009 40 | NoVA 41 | 42 | -------------------------------------------------------------------------------- /core/api/src/test/java/org/jredis/protocol/TestCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | import org.jredis.TestBase; 20 | import static org.jredis.protocol.Command.Flag.*; 21 | 22 | import org.jredis.protocol.Command.Flag; 23 | import org.testng.Assert; 24 | import org.testng.annotations.Test; 25 | import static org.testng.Assert.*; 26 | 27 | /** 28 | * [TODO: document me!] 29 | * 30 | * @author joubin (alphazero@sensesay.net) 31 | * @date Sep 11, 2010 32 | * 33 | */ 34 | 35 | public class TestCommand extends TestBase { 36 | @Test 37 | public void testCommandSemanticsRequestType () { 38 | log.info("TEST:PROTOCOL Command sematics - RequestType"); 39 | for(Command c : Command.values()){ 40 | assertTrue(new String(c.bytes).indexOf(Command.OPTCODE) == -1, "Command bytes must not include control characters."); 41 | } 42 | } 43 | @Test 44 | public void testCommandFlags() { 45 | log.info("TEST:PROTOCOL Command sematics - CommandFlags"); 46 | Flag flags[] = {TEST, FOO, BAR}; 47 | int bitset = Flag.bitset(flags); 48 | for(Flag f : flags) 49 | Assert.assertTrue(Flag.isSet(bitset, f), String.format("%s should have been set!\n", f.name())); 50 | int oldbitset = bitset; 51 | 52 | bitset = Flag.bitclear(bitset, flags[1]); 53 | Assert.assertFalse(bitset == oldbitset, "clearing flag should have changed bitset"); 54 | Assert.assertFalse(Flag.isSet(bitset, flags[1]), String.format("%s should have been cleared!\n", flags[1].name())); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/all/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | org.jredis 8 | jredis-core 9 | a.0-SNAPSHOT 10 | 11 | 12 | 13 | 18 | 19 | JRedis - Core - ALL [Jar POM] 20 | org.jredis 21 | jredis-core-all 22 | a.0-SNAPSHOT 23 | jar 24 | 25 | 26 | 27 | 28 | 29 | org.jredis 30 | jredis-core-api 31 | a.0-SNAPSHOT 32 | 33 | 34 | 35 | 36 | org.jredis 37 | jredis-core-ri 38 | a.0-SNAPSHOT 39 | 40 | 41 | 42 | 43 | org.jredis 44 | jredis-core-bench 45 | a.0-SNAPSHOT 46 | 47 | 48 | 49 | 50 | 51 | 52 | maven-assembly-plugin 53 | 54 | 55 | simple-install 56 | package 57 | 58 | attached 59 | 60 | 61 | 62 | 63 | 64 | jar-with-dependencies 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/ValueResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | 20 | /** 21 | * Formally, redis only returns "integers" as values, but in fact, an operation such as 22 | * {@link Command#RANDOMKEY} will return a key in a single line reply, and not a bulk reply. 23 | * (As of 04/02/09. Ex randomkey response => +woof ) 24 | * 25 | *

This class deals with all responses that are a single line responses distinct from 'status' 26 | * replies. For now, this means the result is either a UTF-8 String key or number. 27 | * 28 | * [TODO: document me!] 29 | * 30 | * @author Joubin Houshyar (alphazero@sensesay.net) 31 | * @version alpha.0, 04/02/09 32 | * @since alpha.0 33 | * 34 | */ 35 | public interface ValueResponse extends Response { 36 | /** 37 | * Redis number values are "64bit signed integers". 38 | * @return 39 | * @throws IllegalStateException 40 | */ 41 | public long getLongValue () throws IllegalStateException; 42 | 43 | /** 44 | * Its gone. Everything is 64 bit signed integer now. 45 | * This is deprecated but kept in the initial release just in case things change on the Redis side. 46 | * @return 47 | * @throws IllegalStateException 48 | */ 49 | // @Deprecated 50 | // public int getIntValue () throws IllegalStateException; 51 | 52 | /** 53 | * @return 54 | * @throws IllegalStateException 55 | */ 56 | public String getStringValue () throws IllegalStateException; 57 | /** 58 | * @return 59 | * @throws IllegalStateException 60 | */ 61 | public boolean getBooleanValue () throws IllegalStateException; 62 | } 63 | -------------------------------------------------------------------------------- /extensions/ri/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | 8 | org.jredis 9 | jredis-extensions 10 | ${jredisVersion} 11 | 12 | 13 | 14 | JRedis - Extensions - RI 15 | org.jredis 16 | jredis-extensions-ri 17 | ${jredisVersion} 18 | jar 19 | 20 | 21 | 22 | 23 | 24 | org.jredis 25 | jredis-core-api 26 | ${jredisVersion} 27 | 28 | 29 | 30 | 31 | org.jredis 32 | jredis-core-ri 33 | ${jredisVersion} 34 | 35 | 36 | 37 | 38 | org.jredis 39 | jredis-extensions-api 40 | ${jredisVersion} 41 | 42 | 43 | 44 | 45 | org.testng 46 | testng 47 | 6.1.1 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | maven-assembly-plugin 56 | 2.1 57 | 58 | 59 | simple-install 60 | package 61 | 62 | attached 63 | 64 | 65 | 66 | 67 | 68 | jar-with-dependencies 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | 23 | import org.jredis.ClientRuntimeException; 24 | import org.jredis.ProviderException; 25 | 26 | 27 | /** 28 | * [TODO: document me!] 29 | * 30 | * @author Joubin Houshyar (alphazero@sensesay.net) 31 | * @version alpha.0, 04/02/09 32 | * @since alpha.0 33 | * 34 | */ 35 | public interface Message { 36 | 37 | /** 38 | * Reads itself from the provided {@link InputStream} 39 | * 40 | * @param in the steam to read from. 41 | * 42 | * @throws ClientRuntimeException to indicate a system error, potentially network related 43 | * and hopefully recoverable. Typically used to wrap and propagate the IO stream's thrown 44 | * {@link IOException}s. 45 | * 46 | * @throws ProviderException to indicate operational error not directly related to the stream, 47 | * and should be treated as a bug. 48 | */ 49 | public void read (InputStream in) throws ClientRuntimeException, ProviderException; 50 | 51 | /** 52 | * Writes itself to the provided {@link OutputStream}. 53 | * 54 | * @param out the stream to write to. 55 | * 56 | * @throws ClientRuntimeException to indicate a system error, potentially network related 57 | * and hopefully recoverable. Typically used to wrap and propagate the IO stream's thrown 58 | * {@link IOException}s. 59 | * 60 | * @throws ProviderException to indicate operational error not directly related to the stream, 61 | * and should be treated as a bug. 62 | */ 63 | public void write (OutputStream out)throws ClientRuntimeException, ProviderException; 64 | } 65 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/SimpleBenchJRedisChunkedPipeline.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.bench; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | import java.util.concurrent.Future; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.jredis.JRedisFuture; 8 | import org.jredis.connector.ConnectionSpec; 9 | import org.jredis.protocol.ResponseStatus; 10 | import org.jredis.ri.alphazero.JRedisChunkedPipeline; 11 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 12 | import org.jredis.ri.alphazero.support.Log; 13 | 14 | public class SimpleBenchJRedisChunkedPipeline implements Runnable { 15 | public static void main(String[] args) { 16 | Runnable bench = new SimpleBenchJRedisChunkedPipeline(); 17 | Thread bt = new Thread(bench, ""); 18 | bt.start(); 19 | try { 20 | bt.join(); 21 | } catch (InterruptedException e) { 22 | // TODO Auto-generated catch block 23 | e.printStackTrace(); 24 | } 25 | 26 | } 27 | 28 | @Override 29 | public void run() { 30 | int database = 11; 31 | ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes()); 32 | JRedisFuture jredis = new JRedisChunkedPipeline(connSpec); 33 | 34 | byte[] key = "cpct".getBytes(); 35 | int iters = 100000; 36 | 37 | for(;;){ 38 | Future frCounter = null; 39 | long start = System.nanoTime(); 40 | for(int i=0;i fr = jredis.flushdb(); 64 | jredis.flush(); 65 | fr.get(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/bench/JRedisJProfileSubject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Mohammad Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.bench; 18 | 19 | import org.jredis.JRedis; 20 | import org.jredis.RedisException; 21 | import org.jredis.ri.alphazero.support.Log; 22 | 23 | /** 24 | * [TODO: document me!] 25 | * 26 | * @author Joubin Houshyar (alphazero@sensesay.net) 27 | * @version alpha.0, Apr 11, 2009 28 | * @since alpha.0 29 | * 30 | */ 31 | public class JRedisJProfileSubject { 32 | private final JRedis jredis; 33 | 34 | public JRedisJProfileSubject (JRedis jredis){ 35 | this.jredis = jredis; 36 | } 37 | protected JRedisJProfileSubject () { 38 | jredis = null; 39 | } 40 | /** 41 | * In a tight loop, we execute a few select 42 | * commands that touch the various permutations of 43 | * request complexity, and response type, so that 44 | * we can pinpoint the bottlenecks and the general 45 | * runtime characteristics of the JRedic provider. 46 | * @throws RedisException 47 | */ 48 | public void run () throws RedisException { 49 | Log.log("***** JProfileTestCase ****"); 50 | // jredis.auth("jredis").ping().flushall(); 51 | 52 | int iter = 100000; 53 | String key = "foostring"; 54 | String cntrkey = "foocntr"; 55 | String listkey = "foolist"; 56 | String setkey = "fooset"; 57 | byte[] data = "meow".getBytes(); 58 | long start = System.currentTimeMillis(); 59 | for(Long j=0L; j 27 | * A KeyCodec is a {@link String} {@link Codec} that is tasked 28 | * with the optimal performance of encoding and decoding String keys 29 | * for use by connector implementations that support such extended 30 | * mechanisms. 31 | *

32 | * This interface is projected to be implemented by a key caching 33 | * mechanism suitable for employment in usage scenarios where a finite 34 | * set of keys is repeatedly employed to accomplish domain specific tasks. 35 | *

36 | * For example, a common Redis pattern is the use of atomic counters to 37 | * increment IDs. Whenever this pattern is used, the key for the ID(s) 38 | * will be repeatedly encoded and decoded by a non-optimized client 39 | * which can not make indiscriminate decisions regarding such optimizations. 40 | *

41 | * A key cache, implementing {@link KeyCodec}, for example, can be used to indicate to 42 | * the client that for keys, the default codec (which is basically delegating to 43 | * {@link String}'s {@link String#getBytes()} and {@link String#String(byte[], int, int)}) 44 | * should not be used and that the client should use the object implementing this 45 | * to accomplish the same task. 46 | *

47 | * This is just a marker interface beyond that. 48 | * 49 | * 50 | * @author Joubin Houshyar (alphazero@sensesay.net) 51 | * @version alpha.0, Apr 15, 2009 52 | * @since alpha.0 53 | * 54 | */ 55 | 56 | public interface KeyCodec extends Codec {/* nop */} 57 | -------------------------------------------------------------------------------- /extensions/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | 8 | org.jredis 9 | jredis 10 | ${jredisVersion} 11 | 12 | 13 | 14 | JRedis - Extensions [Build POM] 15 | org.jredis 16 | jredis-extensions 17 | ${jredisVersion} 18 | pom 19 | 20 | 21 | 22 | api 23 | ri 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-surefire-plugin 32 | 33 | 34 | 35 | 36 | 37 | jredis.cluster.node.cnt100 38 | jredis.cluster.node.address.baselocalhost 39 | jredis.cluster.node.port.base6379 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Apache 2 51 | http://www.apache.org/licenses/LICENSE-2.0.txt 52 | all 53 | Copyright 2009-2010 (c) Joubin Houshyar - All Right Resererved 54 | 55 | 56 | 57 | 58 | joubin 59 | Joubin Houshyar 60 | alphazero@sensesay.net 61 | http://www.sensesay.net 62 | 63 | ReleaseManager 64 | Designer 65 | Developer 66 | 67 | UTC-5 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/RedisInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2012 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | * RedisInfo is a convenience enum that tracks the canonical entries returned by INFO command. 23 | * Exception to this is the db## when ## is db number e.g. db10. 24 | * 25 | * Note that of course the {@link JRedis#info()} command returns a {@link Map} so you can always 26 | * query for the db info directly using the returned map. 27 | * 28 | * @author Joubin Houshyar (alphazero@sensesay.net) 29 | * @version alpha.0-05062012 30 | * @since alpha.0 31 | * 32 | */ 33 | public enum RedisInfo { 34 | redis_git_dirty, 35 | redis_git_sha1, 36 | used_cpu_user, 37 | client_longest_output_list, 38 | latest_fork_usec, 39 | used_memory_peak, 40 | pubsub_patterns, 41 | used_cpu_sys_children, 42 | used_memory_rss, 43 | lru_clock, 44 | aof_enabled, 45 | mem_fragmentation_ratio, 46 | used_memory_peak_human, 47 | loading, 48 | client_biggest_input_buf, 49 | used_cpu_sys, 50 | keyspace_hits, 51 | evicted_keys, 52 | pubsub_channels, 53 | used_cpu_user_children, 54 | gcc_version, 55 | expired_keys, 56 | mem_allocator, 57 | keyspace_misses, 58 | arch_bits, 59 | multiplexing_api, 60 | redis_version, 61 | process_id, 62 | connected_clients, 63 | connected_slaves, 64 | blocked_clients, 65 | used_memory, 66 | used_memory_human, 67 | changes_since_last_save, 68 | bgsave_in_progress, 69 | last_save_time, 70 | bgrewriteaof_in_progress, 71 | total_connections_received, 72 | total_commands_processed, 73 | uptime_in_seconds, 74 | uptime_in_days, 75 | // hash_max_zipmap_entries, 76 | // hash_max_zipmap_value, 77 | // vm_enabled, 78 | os, 79 | tcp_port, 80 | used_memory_lua, 81 | last_bgsave_status, 82 | instantaneous_ops_per_sec, 83 | rejected_connections, 84 | run_id, 85 | bgrewriteaof_scheduled, 86 | role 87 | } -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/JRedisClientBenchmark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Mohammad Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.bench; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | import org.jredis.JRedis; 21 | import org.jredis.bench.JRedisBenchmark; 22 | import org.jredis.ri.alphazero.JRedisClient; 23 | 24 | 25 | /** 26 | * Not fully baked ... just a hack to get things going. 27 | * [TODO: document me!] 28 | * 29 | * @author Joubin Houshyar (alphazero@sensesay.net) 30 | * @version alpha.0, 04/10/09 31 | * @since alpha.0 32 | * 33 | */ 34 | public class JRedisClientBenchmark extends JRedisBenchmark { 35 | 36 | /** 37 | * Runs the benchmark tests. 38 | * [TODO: lets do proper usage here and clean this up.] 39 | * 40 | * Currently, uses 50 concurrent connections and 5000 requests / each connection. 41 | * TODO: munch on some commandline args ... 42 | * @param args 43 | */ 44 | public static void main(String[] args) { 45 | String host = "127.0.0.1"; 46 | int port = 6379; 47 | int size = 3; 48 | int workerCnt = 10; 49 | int reqCnt = 20000; 50 | int db = 13; 51 | if(args.length > 0) db = Integer.valueOf (args[0]); 52 | if(args.length > 1) workerCnt = Integer.valueOf(args[1]); 53 | if(args.length > 2) reqCnt = Integer.valueOf(args[2]); 54 | if(args.length > 3) size = Integer.parseInt(args[3]); 55 | if(args.length > 4) host = args[4]; 56 | 57 | System.out.format("==> Usage: [db [conn [req [size [host]]]]\n"); 58 | 59 | new JRedisClientBenchmark().runBenchmarks (host, port, workerCnt, reqCnt, size, db); 60 | } 61 | 62 | @Override 63 | protected final JRedis newConnection(String host, int port, int db, String password) throws ClientRuntimeException { 64 | return new JRedisClient(host, port, password, db); 65 | } 66 | @Override 67 | protected final Class getImplementationClass() { 68 | return JRedisClient.class; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /extensions/ri/src/main/java/org/jredis/ri/cluster/model/BasicStaticHashCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.cluster.model; 18 | 19 | import org.jredis.cluster.ClusterNodeSpec; 20 | import org.jredis.cluster.ClusterSpec; 21 | import org.jredis.cluster.model.StaticHashCluster; 22 | import org.jredis.cluster.support.HashAlgorithm; 23 | 24 | /** 25 | * As barebones as it gets. Uses the key's hashCode() (that is {@link byte[]#hashCode()}) 26 | * to compute a node index, using a basic hashcode % nodeCnt as the index to the nodes list. 27 | * @author joubin (alphazero@sensesay.net) 28 | * @date Mar 30, 2010 29 | * 30 | */ 31 | 32 | public class BasicStaticHashCluster extends StaticHashCluster.Support implements StaticHashCluster { 33 | 34 | // ------------------------------------------------------------------------ 35 | // Constructor 36 | // ------------------------------------------------------------------------ 37 | /** 38 | * @param clusterSpec 39 | */ 40 | public BasicStaticHashCluster (ClusterSpec clusterSpec) { 41 | super(clusterSpec); 42 | } 43 | 44 | // ------------------------------------------------------------------------ 45 | // super overrides 46 | // ------------------------------------------------------------------------ 47 | 48 | /* (non-Javadoc) @see org.jredis.cluster.model.StaticHashCluster.Support#newHashAlgorithm() */ 49 | @Override 50 | protected HashAlgorithm newHashAlgorithm () { 51 | // TDOO: get this from the clusterspec 52 | return new HashAlgorithm() { 53 | public long hash (byte[] kb) { 54 | return kb.hashCode(); 55 | } 56 | }; 57 | } 58 | 59 | /* (non-Javadoc) @see org.jredis.cluster.ClusterModel#getNodeForKey(byte[]) */ 60 | public ClusterNodeSpec getNodeForKey (byte[] key) { 61 | int nodeIdx = (int) (hashAlgo.hash(key)%nodeCnt); 62 | return nodes[nodeIdx]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | import java.io.IOException; 20 | import java.io.ObjectInputStream; 21 | import java.io.ObjectOutputStream; 22 | import java.io.Serializable; 23 | import java.lang.ref.WeakReference; 24 | 25 | /** 26 | * Generic Event class for JRedis and sub-modules. 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Mar 29, 2010 29 | * @since alpha.0 30 | * 31 | * @param 32 | * @param 33 | * @param 34 | */ 35 | public class Event implements Serializable{ 36 | /** */ 37 | private static final long serialVersionUID = 1L; 38 | 39 | /** */ 40 | private final ETYPE type; 41 | /** */ 42 | private transient WeakReference srcRef; 43 | /** */ 44 | private final INFO info; 45 | 46 | /** 47 | * @param src 48 | * @param eType 49 | * @param info 50 | */ 51 | protected Event(SRC src, ETYPE eType, INFO info){ 52 | this.type = eType; 53 | this.srcRef = new WeakReference(src); 54 | this.info = info; 55 | } 56 | /** 57 | * @param src 58 | * @param eType 59 | */ 60 | protected Event(SRC src, ETYPE eType){ 61 | this(src, eType, null); 62 | } 63 | /** 64 | * @return 65 | */ 66 | public ETYPE getType () { 67 | return type; 68 | } 69 | /** 70 | * @return 71 | */ 72 | public SRC getSource () { 73 | return srcRef.get(); 74 | } 75 | /** 76 | * @return 77 | */ 78 | public INFO getInfo () { 79 | return info; 80 | } 81 | 82 | private void writeObject(ObjectOutputStream out) throws IOException { 83 | out.defaultWriteObject(); 84 | out.writeObject(srcRef.get()); 85 | } 86 | 87 | @SuppressWarnings("unchecked") 88 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 89 | in.defaultReadObject(); 90 | srcRef = new WeakReference((SRC)in.readObject()); 91 | } 92 | } -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/support/GZip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.support; 18 | 19 | import java.io.ByteArrayInputStream; 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | import java.util.zip.GZIPInputStream; 23 | import java.util.zip.GZIPOutputStream; 24 | 25 | /** 26 | * GZip (de)compression utility methods. 27 | * @author Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Aug 24, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | public class GZip { 34 | /** 35 | * @param data 36 | * @return 37 | */ 38 | public static final byte[] compress(byte[] data){ 39 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 40 | try { 41 | GZIPOutputStream gzipOutputtStream = new GZIPOutputStream(out); 42 | gzipOutputtStream.write(data); 43 | gzipOutputtStream.close(); 44 | } 45 | catch (IOException e) { 46 | throw new RuntimeException("Failed to GZip compress data", e); 47 | } 48 | return out.toByteArray(); 49 | } 50 | 51 | /** 52 | * @param data 53 | * @return 54 | */ 55 | public static final byte[] decompress(byte[] data){ 56 | ByteArrayOutputStream buffer = null; 57 | GZIPInputStream gizpInputStream= null; 58 | try { 59 | buffer = new ByteArrayOutputStream(); 60 | gizpInputStream = new GZIPInputStream(new ByteArrayInputStream(data)); 61 | int n=-1; 62 | @SuppressWarnings("unused") 63 | int tot = 0; 64 | byte[] _buffer = new byte[1024 * 12]; 65 | while(-1 != (n = gizpInputStream.read(_buffer))){ 66 | buffer.write(_buffer, 0, n); 67 | tot += n; 68 | } 69 | gizpInputStream.close(); 70 | buffer.close(); 71 | } 72 | catch (IOException e) { 73 | throw new RuntimeException("Failed to GZip decompress data", e); 74 | } 75 | return buffer.toByteArray(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /extensions/ri/src/main/java/org/jredis/ri/cluster/support/CryptoHashUtils.java: -------------------------------------------------------------------------------- 1 | /* -- BEGIN NOTICE -- 2 | * 3 | * This class uses in parts extant and/or modified code from net.spy.memcached.HashAlgorithm 4 | * by Dustin Sallings. See this module's 3rd party license folder for license details. 5 | * 6 | * -- END NOTICE -- 7 | * 8 | * Copyright 2009-2010 Joubin Houshyar 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | */ 22 | 23 | package org.jredis.ri.cluster.support; 24 | 25 | import java.security.MessageDigest; 26 | import java.security.NoSuchAlgorithmException; 27 | import org.jredis.ClientRuntimeException; 28 | 29 | /** 30 | * [TODO: document me!] 31 | * 32 | * @author joubin (alphazero@sensesay.net) 33 | * @date Mar 26, 2010 34 | * 35 | */ 36 | 37 | public class CryptoHashUtils { 38 | /** 39 | * Get the md5 of the given key. 40 | * @throws ClientRuntimeException if MD5 algorithm is not supported. 41 | * @throws IllegalArgumentException if input is null or zero length 42 | * 43 | * @Copyright (c) 2006-2009 Dustin Sallings 44 | */ 45 | public static byte[] computeMd5(byte[] b) throws ClientRuntimeException{ 46 | if(null == b) throw new IllegalArgumentException ("null input"); 47 | if(b.length == 0) throw new IllegalArgumentException ("zero length input"); 48 | MessageDigest md5 = null; 49 | try { 50 | md5 = MessageDigest.getInstance("MD5"); 51 | md5.reset(); 52 | md5.update(b); 53 | } 54 | catch (NoSuchAlgorithmException e) { 55 | throw new ClientRuntimeException("MD5 Message Digest algorithm is not present in this JRE", e); 56 | } 57 | return md5.digest(); 58 | } 59 | 60 | /** 61 | * @param s 62 | * @return 63 | * @throws ClientRuntimeException 64 | * @throws IllegalArgumentException if input is null or zero length 65 | */ 66 | public static byte[] computeMd5(String s) throws ClientRuntimeException{ 67 | if(null == s) throw new IllegalArgumentException ("null input"); 68 | return computeMd5(s.getBytes()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/ConnectionReset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2011 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | import java.net.Socket; 22 | import java.net.SocketException; 23 | 24 | import org.jredis._specification; 25 | import org.jredis.protocol.Command; 26 | 27 | /** 28 | * This exception is thrown by a {@link Connection} to indicate that the connection to redis was 29 | * reset (typically due to timeout on Redis side). 30 | *

31 | * If the {@link Connection} is specified to use 32 | * auto-reconnect, the connection has been re-established, but, the status of the request that 33 | * gave rise to this exception is indeterminate, in the sense that while this exception certainly indicates 34 | * that the response was not received from Redis, it is not clear whether the request itself was 35 | * received by the server. This is due to the fact that writing to the {@link OutputStream} of a {@link Socket} 36 | * that has been closed by the remote peer does NOT raise an exception. The exception is raised (reliably) only 37 | * on the receive when reading from the {@link Socket}'s {@link InputStream}. 38 | *

39 | * Depending on the application domain and the {@link Command} of the request, the user may retry 40 | * the request. 41 | * 42 | * @author Joubin (alphazero@sensesay.net) 43 | * @version alpha.0, Apr 15, 2009 44 | * @since alpha.0 45 | * 46 | */ 47 | 48 | public class ConnectionReset extends ConnectionException { 49 | 50 | /** */ 51 | private static final long serialVersionUID = _specification.Version.major; 52 | 53 | private static final String info = "potential redis timeout"; 54 | /** 55 | * @param string 56 | * @param e 57 | */ 58 | public ConnectionReset(String msg, SocketException e) { 59 | super(String.format("(%s) %s", info, msg), e); 60 | } 61 | public ConnectionReset(String msg) { 62 | super(String.format("(%s) %s", info, msg)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/protocol/ResponseSupport.java: -------------------------------------------------------------------------------- 1 | package org.jredis.ri.alphazero.protocol; 2 | 3 | import java.io.OutputStream; 4 | import org.jredis.ClientRuntimeException; 5 | import org.jredis.ProviderException; 6 | import org.jredis.protocol.Command; 7 | import org.jredis.protocol.Response; 8 | import org.jredis.protocol.ResponseStatus; 9 | 10 | /** 11 | * Base for all responses. Responsible for reading and determining status. 12 | * 13 | * @author Joubin Houshyar (alphazero@sensesay.net) 14 | * @version alpha.0, 04/02/09 15 | * @since alpha.0 16 | * 17 | */ 18 | public abstract class ResponseSupport implements Response { 19 | 20 | // ------------------------------------------------------------------------ 21 | // Properties and fields 22 | // ------------------------------------------------------------------------ 23 | protected Type type; 24 | protected ResponseStatus status; 25 | protected Command cmd; 26 | protected boolean didRead = false; 27 | protected boolean isError = false; 28 | 29 | // ------------------------------------------------------------------------ 30 | // Constructor 31 | // ------------------------------------------------------------------------ 32 | public ResponseSupport (Command cmd, Type type) { 33 | this.type = type; 34 | this.cmd = cmd; 35 | } 36 | // ------------------------------------------------------------------------ 37 | // Internal ops 38 | // ------------------------------------------------------------------------ 39 | /** called by child classes to indicate if & when their read operation has completed */ 40 | protected final boolean didRead (boolean value) { return didRead = value;} 41 | 42 | /** a bit aggressive but to force out the little bugs .. */ 43 | protected final void assertResponseRead () { 44 | if(!didRead) throw new ProviderException ("Response has not been read yet! -- whose bad?"); 45 | } 46 | 47 | // ------------------------------------------------------------------------ 48 | // Interface 49 | // ------------------------------------------------------------------------ 50 | 51 | @Override 52 | public boolean didRead() { return didRead; } 53 | 54 | @Override 55 | public ResponseStatus getStatus() {return status; } 56 | 57 | @Override 58 | public Type getType() { return type;} 59 | 60 | @Override 61 | public boolean isError() { 62 | assertResponseRead(); 63 | return isError; 64 | } 65 | 66 | @Override 67 | public void write(OutputStream out) throws ClientRuntimeException, ProviderException { 68 | throw new RuntimeException ("Message.write not implemented! [Apr 10, 2009]"); 69 | } 70 | } -------------------------------------------------------------------------------- /examples/src/main/java/org/jredis/examples/HelloAgain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.examples; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | import org.jredis.JRedis; 21 | import org.jredis.ProviderException; 22 | import org.jredis.RedisException; 23 | import org.jredis.connector.ConnectionSpec; 24 | import org.jredis.protocol.Command; 25 | import org.jredis.ri.alphazero.JRedisClient; 26 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 27 | import static org.jredis.ri.alphazero.support.DefaultCodec.*; 28 | 29 | /** 30 | * [TODO: document me!] 31 | * 32 | * @author Joubin Houshyar (alphazero@sensesay.net) 33 | * @version alpha.0, Apr 15, 2009 34 | * @since alpha.0 35 | * 36 | */ 37 | 38 | public class HelloAgain { 39 | public static final String key = "jredis::examples::HelloAgain::message"; 40 | public static final byte[] bkey = key.getBytes(); 41 | public static void main(String[] args) { 42 | String password = "jredis"; 43 | if(args.length > 0) password = args[0]; 44 | new HelloAgain().run(password); 45 | } 46 | 47 | private void run(String password) { 48 | try { 49 | ConnectionSpec spec = DefaultConnectionSpec.newSpec().setCredentials(password); 50 | JRedis jredis = new JRedisClient(spec); 51 | jredis.ping(); 52 | 53 | if(!jredis.exists(bkey)) { 54 | jredis.set(bkey, "Hello Again!"); 55 | System.out.format("Hello! You should run me again!\n"); 56 | } 57 | else { 58 | String msg = toStr ( jredis.get(bkey) ); 59 | System.out.format("%s\n", msg); 60 | } 61 | jredis.quit(); 62 | } 63 | catch (RedisException e){ 64 | if (e.getCommand()==Command.PING){ 65 | System.out.format("I'll need that password! Try again with password as command line arg for this program.\n"); 66 | } 67 | } 68 | catch (ProviderException e){ 69 | System.out.format("Oh no, an 'un-documented feature': %s\nKindly report it.", e.getMessage()); 70 | } 71 | catch (ClientRuntimeException e){ 72 | System.out.format("%s\n", e.getMessage()); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/RedisException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | import org.jredis.protocol.Command; 20 | 21 | //import org.jredis.connector.ProviderException; 22 | 23 | /** 24 | * [TODO: update doc regarding "extensions"] 25 | * 26 | * RedisExceptions are only created/raised subsequent to an error result from the redis server. 27 | * These exceptions are _not_ intended as a general purpose exception mechanism for 28 | * implementations of this specification. Accordingly, this exception (and extensions if any) 29 | * do not (and must not) provide default no arg constructors. (Minimal information required is 30 | * an associated {@link Command} object.) 31 | * 32 | *

Further, this class (and extension if any) should never expose a constructor accepting 33 | * an underlying 'cause' (as in {@link Exception#Exception(Throwable)}), since this excpetion, 34 | * to repeat, has very specific semantics: Redis has responded with an error 35 | * status to an issued command and the content of that message (e.g. "-ERR operation on wrong type" 36 | * is what is required for instantiating a {@link RedisException}. 37 | * 38 | * @see ClientRuntimeException 39 | * 40 | * @author Joubin Houshyar (alphazero@sensesay.net) 41 | * @version alpha.0, 04/02/09 42 | * @since alpha.0 43 | * 44 | */ 45 | public final class RedisException extends Exception { 46 | 47 | /** */ 48 | public static final long version = _specification.Version.major; 49 | 50 | /** */ 51 | private static final long serialVersionUID = version; 52 | 53 | /** */ 54 | private final Command command; 55 | 56 | // public RedisException (String message) { 57 | // super (message); 58 | // } 59 | 60 | public RedisException (Command command, String message){ 61 | super (message); 62 | this.command = command; 63 | } 64 | 65 | /** @return the associated {@link Command} if any */ 66 | public Command getCommand () { return command; } 67 | 68 | public String toString () { 69 | return "Exception on [" + command.code + "] => " + getMessage(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/protocol/VirtualResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Mohammad Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.protocol; 18 | 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | 22 | import org.jredis.ClientRuntimeException; 23 | import org.jredis.ProviderException; 24 | import org.jredis.protocol.Command; 25 | import org.jredis.protocol.Response; 26 | import org.jredis.protocol.ResponseStatus; 27 | 28 | 29 | 30 | /** 31 | * Certain requested commands do not have a corresponding response from 32 | * redis. Quit and Shutdown are two examples as of now. This response 33 | * provides a virtual response for this type of request. You can set 34 | * the virtual response's status in the constructor. The default constructor 35 | * provides for OK status. 36 | * 37 | * @author Joubin Houshyar (alphazero@sensesay.net) 38 | * @version alpha.0, 04/02/09 39 | * @since alpha.0 40 | * 41 | */ 42 | public final class VirtualResponse implements Response { 43 | 44 | 45 | private final ResponseStatus status; 46 | public VirtualResponse () { 47 | this.status = ResponseStatus.STATUS_OK; 48 | } 49 | public VirtualResponse (ResponseStatus status) { 50 | this.status = status; 51 | } 52 | 53 | @Override 54 | public boolean didRead() {return true;} 55 | 56 | @Override 57 | public ResponseStatus getStatus() { return status;} 58 | 59 | @Override 60 | public Type getType() { return Type.Status;} 61 | 62 | @Override 63 | public boolean isError() { return false;} 64 | 65 | @Override 66 | /** 67 | * The purpose of this class is to provide responses that are not actually read from 68 | * the server. Typically this is for commands that closed the connection on the send, such 69 | * as QUIT. 70 | * @see Command#QUIT 71 | * @see Command#SHUTDOWN 72 | * @see org.jredis.connector.Message#read(java.io.InputStream) 73 | */ 74 | public void read(InputStream in) throws ClientRuntimeException, ProviderException { return;} 75 | 76 | @Override 77 | public void write(OutputStream out) throws ClientRuntimeException, ProviderException { 78 | throw new RuntimeException ("Streamable.write not implemented! [Apr 4, 2009]"); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/ClientRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis; 18 | 19 | 20 | /** 21 | * Base class for all non-Redis exceptions relating to client runtime. Implementations 22 | * must only throw this type of exception when the problem(s) encountered are neither Redis usage errors, nor 23 | * unexpected code segment execution. 24 | *

25 | * For example, failure to establish a connection, or losing the connection, should raise this type of exception. But 26 | * encountering parse errors in Redis responses streams is a bug and should be noted by raising a {@link ProviderException}. 27 | * 28 | * @author Joubin Houshyar (alphazero@sensesay.net) 29 | * @version alpha.0, 04/02/09 30 | * @since alpha.0 31 | * 32 | */ 33 | public class ClientRuntimeException extends RuntimeException { 34 | 35 | /** */ 36 | private static final long serialVersionUID = _specification.Version.major; 37 | 38 | /** 39 | * @param message 40 | */ 41 | public ClientRuntimeException(String message) { 42 | super (message); 43 | } 44 | 45 | /** 46 | * @param message 47 | * @param cause 48 | */ 49 | public ClientRuntimeException(String message, Throwable cause) { 50 | super(message, cause); 51 | } 52 | 53 | // ------------------------------------------------------------------------ 54 | // Super overrides 55 | // ------------------------------------------------------------------------ 56 | 57 | /* (non-Javadoc) 58 | * @see java.lang.Throwable#getLocalizedMessage() 59 | */ 60 | @Override 61 | final public String getLocalizedMessage () { 62 | return this.getMessage(); 63 | } 64 | 65 | /* (non-Javadoc) 66 | * @see java.lang.Throwable#getMessage() 67 | */ 68 | @Override 69 | final public String getMessage () { 70 | StringBuffer buff = new StringBuffer(); 71 | 72 | String message = super.getMessage(); 73 | if(null == message) buff.append("[BUG: null message]"); 74 | else buff.append(message); 75 | 76 | Throwable cause = getCause(); 77 | if(null != cause) buff.append(" cause: => [").append(cause.getClass().getSimpleName()).append(": ").append(cause.getMessage()).append("]"); 78 | 79 | return buff.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/JRedisPipelineServiceBenchmark.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2009 Joubin Houshyar 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package org.jredis.ri.alphazero.bench; 18 | // 19 | //import org.jredis.ClientRuntimeException; 20 | //import org.jredis.JRedis; 21 | //import org.jredis.bench.JRedisBenchmark; 22 | //import org.jredis.connector.ConnectionSpec; 23 | //import org.jredis.ri.alphazero.JRedisPipelineService; 24 | //import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 25 | // 26 | ///** 27 | // * [TODO: document me!] 28 | // * 29 | // * @author Joubin Houshyar (alphazero@sensesay.net) 30 | // * @version alpha.0, Nov 6, 2009 31 | // * @since alpha.0 32 | // * 33 | // */ 34 | // 35 | //public class JRedisPipelineServiceBenchmark extends JRedisBenchmark { 36 | // public static void main(String[] args) { 37 | //// host = "192.168.1.222"; 38 | // String host = "127.0.0.1"; 39 | // String password = "jredis"; 40 | // int port = 6379; 41 | // int size = 3; 42 | // int workerCnt = 100; 43 | // int reqCnt = 1000; 44 | // int db = 13; 45 | // if(args.length > 0) db = Integer.valueOf (args[0]); 46 | // if(args.length > 1) workerCnt = Integer.valueOf(args[1]); 47 | // if(args.length > 2) reqCnt = Integer.valueOf(args[2]); 48 | // if(args.length > 3) size = Integer.parseInt(args[3]); 49 | // if(args.length > 4) host = args[4]; 50 | // 51 | // System.out.format("==> Usage: [db [conn [req [size [host]]]]\n"); 52 | // 53 | // new JRedisPipelineServiceBenchmark(host, port, db, password).runBenchmarks (host, port, workerCnt, reqCnt, size, db); 54 | // } 55 | // final JRedis jredisService; 56 | // public JRedisPipelineServiceBenchmark (String host, int port, int db, String password) { 57 | // ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec("localhost", 6379, db, "jredis".getBytes()); 58 | // jredisService = new JRedisPipelineService(connectionSpec); 59 | // super.quitOnRunEnd(false); 60 | // } 61 | // @Override 62 | // protected final JRedis newConnection (String host, int port, int db, String password) throws ClientRuntimeException { 63 | // return jredisService; 64 | // } 65 | // @Override 66 | // protected final Class getImplementationClass() { 67 | // return JRedisPipelineService.class; 68 | // } 69 | //} 70 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/alphazero/support/GZipTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.support; 18 | 19 | import java.nio.charset.Charset; 20 | import java.util.Random; 21 | import org.testng.annotations.*; 22 | import org.testng.Assert; 23 | import static org.jredis.ri.alphazero.support.GZip.*; 24 | /** 25 | * [TODO: document me!] 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Aug 24, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | @Test(suiteName="support-tests") 34 | public class GZipTest { 35 | public final static Charset SUPPORTED_CHARSET = Charset.forName ("UTF-8"); 36 | 37 | @Test 38 | public void testCompression() { 39 | Log.log("Testing compress/decompress of 1000 random 24KB strings ..."); 40 | int cnt = 1000; 41 | int size = 1024 * 24; 42 | for(int i=0; ibyte[] values. 25 | * 26 | *

Specific {@link Query} types are obtained from the {@link JRedis} api. Extensions of this interface 27 | * allow for the definition of natural expression of the query clauses. Such interfaces should only 28 | * define methods for the optional elements of the specific query type. Redis interface itself will also 29 | * only allow for obtaining a reference to such an interface by specifying the required arguments in the 30 | * associated method signature. 31 | * 32 | *

For example, to get a {@link Sort} instance, {@link JRedis} api specifies the required argument, 33 | * (namely the the key) in the method signature for {@link JRedis#sort(String)}, and all the optional 34 | * elements of the SORT command are provided for in the {@link Sort} interface: 35 | *

36 | *


37 |  * Sort    sort = redis.sort (key)
38 |  * List  results = BY("foo*").LIMIT(1, 11).GET("*woof*").DESC().exec();
39 |  * for(byte[] item : results) {
40 |  *     // do something with item ..
41 |  *  }
42 |  * 
43 |  * 
44 | * 45 | * @see Sort 46 | * 47 | * @author Joubin Houshyar (alphazero@sensesay.net) 48 | * @version alpha.0, 04/02/09 49 | * @since alpha.0 50 | * 51 | */ 52 | public interface Query { 53 | 54 | /** 55 | * Executes the query. 56 | * 57 | * @return the resultant value list from redis. 58 | * @throws IllegalStateException 59 | * @throws RedisException 60 | */ 61 | // TODO: why illegal state? 62 | public List exec () throws IllegalStateException, RedisException; 63 | public Future> execAsync (); 64 | 65 | public static class Support { 66 | public static long unpackValue (List queryResult){ 67 | if(null == queryResult) throw new ClientRuntimeException("queryResult is null"); 68 | if(queryResult.size() < 1) throw new ClientRuntimeException("queryResult must have at least 1 entry"); 69 | return Long.parseLong(new String(queryResult.get(0))); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/cluster/ProviderTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.cluster; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | //import org.jredis.JRedis; 21 | import org.jredis.ri.alphazero.support.Log; 22 | import org.testng.annotations.BeforeTest; 23 | import static org.testng.Assert.*; 24 | 25 | /** 26 | * Support for tests of interface T implementation providers. 27 | * 28 | * @author Joubin Houshyar (alphazero@sensesay.net) 29 | * @version alpha.0, Oct 10, 2009 30 | * @since alpha.0 31 | * 32 | */ 33 | 34 | public abstract class ProviderTestBase { 35 | 36 | // ======================================================================== 37 | // Test Properties 38 | // ======================================================================== 39 | 40 | /** the JRedis implementation being tested */ 41 | protected T provider = null; 42 | protected Class specClass = null; 43 | // ------------------------------------------------------------------------ 44 | // JRedisFuture Provider initialize methods 45 | // ------------------------------------------------------------------------ 46 | /** 47 | * Sets the {@link JRedis} implementation provider for the test suite 48 | */ 49 | @BeforeTest 50 | public void initialize () { 51 | try { 52 | specClass = getSpecificationClass(); 53 | assertNotNull(specClass, "getSpecificationClass() returned null"); 54 | provider = newProviderInstance(); 55 | assertNotNull(provider, "newProviderInstance() returned null"); 56 | Log.log("\n\nTEST: " + 57 | "\n\t-----------------------------------------------\n" + 58 | "\tSpec Interface: %s\n" + 59 | "\tProvider Class: %s" + 60 | "\n\t-----------------------------------------------\n", 61 | specClass.getCanonicalName(), 62 | provider.getClass().getCanonicalName()); 63 | } 64 | catch (ClientRuntimeException e) { 65 | Log.error(e.getLocalizedMessage()); 66 | } 67 | } 68 | 69 | /** 70 | * Extension point: Tests for specific implementations of T 71 | * implement this method to create the provider instance. 72 | * @return T implementation instance 73 | */ 74 | protected abstract T newProviderInstance () ; 75 | /** 76 | * @return 77 | */ 78 | protected abstract Class getSpecificationClass () ; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /extensions/ri/src/test/java/org/jredis/cluster/models/BasicStaticHashClusterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.cluster.models; 18 | 19 | import org.jredis.cluster.ClusterModel; 20 | import org.jredis.cluster.ClusterNodeSpec; 21 | import org.jredis.cluster.ClusterSpec; 22 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 23 | import org.jredis.ri.alphazero.support.Log; 24 | import org.jredis.ri.cluster.DefaultClusterNodeSpec; 25 | import org.jredis.ri.cluster.DefaultClusterSpec; 26 | import org.jredis.ri.cluster.model.BasicStaticHashCluster; 27 | 28 | import org.testng.annotations.Test; 29 | import static org.testng.Assert.*; 30 | 31 | /** 32 | * [TODO: document me!] 33 | * 34 | * @author joubin (alphazero@sensesay.net) 35 | * @date Mar 31, 2010 36 | * 37 | */ 38 | @Test(suiteName="basic static hash") 39 | public class BasicStaticHashClusterTest extends StaticHashClusterProviderTestBase { 40 | 41 | // ------------------------------------------------------------------------ 42 | // super overrides 43 | // ------------------------------------------------------------------------ 44 | 45 | 46 | /* (non-Javadoc) @see org.jredis.cluster.ClusterModelProviderTestBase#newClusterModel(org.jredis.cluster.ClusterSpec) */ 47 | @Override 48 | protected ClusterModel newClusterModel (ClusterSpec clusterSpec) { 49 | ClusterModel model = null; 50 | try { 51 | model = new BasicStaticHashCluster(clusterSpec); 52 | } 53 | catch (RuntimeException e){ 54 | Log.error("NOTE: propagating error > " + e.getLocalizedMessage()); 55 | throw e; 56 | } 57 | return model; 58 | } 59 | 60 | /* (non-Javadoc) @see org.jredis.cluster.ClusterModelProviderTestBase#newClusterSpec() */ 61 | @Override 62 | protected ClusterSpec newClusterSpec () { 63 | ClusterSpec spec = new DefaultClusterSpec(); 64 | for(int i=0; i<100; i++){ 65 | ClusterNodeSpec node = new DefaultClusterNodeSpec(DefaultConnectionSpec.newSpec("localhost", 6379+i, 0, null)); 66 | spec.addNode(node); 67 | } 68 | return spec; 69 | } 70 | 71 | // ------------------------------------------------------------------------ 72 | // BasicStaticHashCluster specific tests 73 | // ------------------------------------------------------------------------ 74 | @Test 75 | public void fooTest() { 76 | Log.log("Foo test for BasicStaticHash"); 77 | assertTrue(true); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /core/bench/src/main/java/org/jredis/ri/alphazero/bench/JRedisServiceBenchmark.java: -------------------------------------------------------------------------------- 1 | ///* 2 | // * Copyright 2009 Joubin Houshyar 3 | // * 4 | // * Licensed under the Apache License, Version 2.0 (the "License"); 5 | // * you may not use this file except in compliance with the License. 6 | // * You may obtain a copy of the License at 7 | // * 8 | // * http://www.apache.org/licenses/LICENSE-2.0 9 | // * 10 | // * Unless required by applicable law or agreed to in writing, software 11 | // * distributed under the License is distributed on an "AS IS" BASIS, 12 | // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // * See the License for the specific language governing permissions and 14 | // * limitations under the License. 15 | // */ 16 | // 17 | //package org.jredis.ri.alphazero.bench; 18 | // 19 | //import org.jredis.ClientRuntimeException; 20 | //import org.jredis.JRedis; 21 | //import org.jredis.bench.JRedisBenchmark; 22 | //import org.jredis.connector.ConnectionSpec; 23 | //import org.jredis.ri.alphazero.JRedisService; 24 | //import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 25 | // 26 | ///** 27 | // * [TODO: document me!] 28 | // * 29 | // * @author Joubin (alphazero@sensesay.net) 30 | // * @version alpha.0, Sep 2, 2009 31 | // * @since alpha.0 32 | // * 33 | // */ 34 | // 35 | //public class JRedisServiceBenchmark extends JRedisBenchmark { 36 | // public static void main(String[] args) { 37 | //// host = "192.168.1.222"; 38 | // String host = "127.0.0.1"; 39 | // String password = "jredis"; 40 | // int port = 6379; 41 | // int size = 3; 42 | // int workerCnt = 100; 43 | // int poolCnt = 80; 44 | // int reqCnt = 1000; 45 | // int db = 13; 46 | // if(args.length > 0) db = Integer.valueOf (args[0]); 47 | // if(args.length > 1) workerCnt = Integer.valueOf(args[1]); 48 | // if(args.length > 2) reqCnt = Integer.valueOf(args[2]); 49 | // if(args.length > 3) size = Integer.parseInt(args[3]); 50 | // if(args.length > 4) host = args[4]; 51 | // 52 | // System.out.format("==> Usage: [db [conn [req [size [host]]]]\n"); 53 | //// System.out.format("*** host: %s:%d (db: %d) | datasize: %d | connections: %d | request/conn: %d \n\n", host, port, db, size ,connectionCnt, reqCnt); 54 | // 55 | // new JRedisServiceBenchmark(poolCnt, host, port, db, password).runBenchmarks (host, port, workerCnt, reqCnt, size, db); 56 | // } 57 | // 58 | // final JRedis jredisService; 59 | // public JRedisServiceBenchmark (int poolCnt, String host, int port, int db, String password) { 60 | // ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec("localhost", 6379, db, "jredis".getBytes()); 61 | // jredisService = new JRedisService(connectionSpec, poolCnt); 62 | // super.quitOnRunEnd(false); 63 | // } 64 | // @Override 65 | // protected final JRedis newConnection (String host, int port, int db, String password) throws ClientRuntimeException { 66 | // return jredisService; 67 | // } 68 | // @Override 69 | // protected final Class getImplementationClass() { 70 | // return JRedisService.class; 71 | // } 72 | // 73 | //} 74 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/ProviderTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | //import org.jredis.JRedis; 21 | import org.jredis.ri.alphazero.support.Log; 22 | import org.testng.annotations.BeforeTest; 23 | 24 | /** 25 | * Support for tests of interface T implementation providers. 26 | * 27 | * @author Joubin Houshyar (alphazero@sensesay.net) 28 | * @version alpha.0, Oct 10, 2009 29 | * @since alpha.0 30 | * 31 | */ 32 | 33 | public abstract class ProviderTestBase { 34 | 35 | // ======================================================================== 36 | // Test Properties 37 | // ======================================================================== 38 | 39 | /** the JRedis implementation being tested */ 40 | protected T provider = null; 41 | 42 | // ------------------------------------------------------------------------ 43 | // JRedisFuture Provider initialize methods 44 | // ------------------------------------------------------------------------ 45 | /** 46 | * Sets the {@link JRedis} implementation provider for the test suite 47 | */ 48 | @BeforeTest 49 | public void setProvider () { 50 | try { 51 | T provider = newProviderInstance(); 52 | 53 | setProviderInstance (provider); 54 | Log.log("%s.setProvider - done", this.getClass().getSimpleName()); 55 | } 56 | catch (ClientRuntimeException e) { 57 | Log.error(e.getLocalizedMessage()); 58 | } 59 | } 60 | 61 | /** 62 | * Extension point: Tests for specific implementations of T 63 | * implement this method to create the provider instance. 64 | * @return T implementation instance 65 | */ 66 | protected abstract T newProviderInstance () ; 67 | 68 | /** 69 | * Must be called by a BeforeTest method to set the jredis parameter. 70 | * @param provider that is being tested. 71 | */ 72 | private final void setProviderInstance (T provider) { 73 | this.provider = provider; 74 | Log.log("\n\nTEST: " + 75 | "\n\t-----------------------------------------------\n" + 76 | "\tProvider Class: %s" + 77 | "\n\t-----------------------------------------------\n", 78 | provider.getClass().getCanonicalName()); 79 | } 80 | /** 81 | * @return the T instance used for the provider tests 82 | */ 83 | protected final T getProviderInstance() { 84 | return provider; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/protocol/ConcurrentSyncProtocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.protocol; 18 | 19 | import org.jredis.protocol.Command; 20 | import org.jredis.protocol.Response; 21 | 22 | /** 23 | * This basically extends {@link SyncProtocol} so that the response buffers 24 | * are not shared, so that it can be used in multi-threaded environments. 25 | * @author Joubin (alphazero@sensesay.net) 26 | * @version alpha.0, Apr 23, 2009 27 | * @since alpha.0 28 | * 29 | */ 30 | 31 | public class ConcurrentSyncProtocol extends SyncProtocol { 32 | // ------------------------------------------------------------------------ 33 | // Properties 34 | // ------------------------------------------------------------------------ 35 | 36 | // ------------------------------------------------------------------------ 37 | // Super Extensions 38 | // ------------------------------------------------------------------------ 39 | 40 | // @Override 41 | // protected ByteArrayOutputStream createRequestBufffer(Command cmd) { 42 | // return new ByteArrayOutputStream (PREFERRED_REQUEST_BUFFER_SIZE); 43 | // } 44 | // 45 | // protected Request createRequest (ByteArrayOutputStream buffer) { 46 | //// sharedRequestObject.reset(buffer); 47 | // return new StreamBufferRequest (buffer); 48 | // } 49 | 50 | @Override 51 | protected Response createStatusResponse(Command cmd) { 52 | return new SyncLineResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd, ValueType.STATUS); 53 | } 54 | 55 | @Override 56 | protected Response createBooleanResponse(Command cmd) { 57 | return new SyncLineResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd, ValueType.BOOLEAN); 58 | } 59 | @Override 60 | protected Response createStringResponse(Command cmd) { 61 | return new SyncLineResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd, ValueType.STRING); 62 | } 63 | 64 | @Override 65 | protected Response createNumberResponse(Command cmd /*, boolean isBigNum*/) { 66 | ValueType flavor = ValueType.NUMBER64; 67 | return new SyncLineResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd, flavor); 68 | } 69 | 70 | @Override 71 | protected Response createBulkResponse(Command cmd) { 72 | return new SyncBulkResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd); 73 | } 74 | 75 | @Override 76 | protected Response createMultiBulkResponse(Command cmd) { 77 | return new SyncMultiBulkResponse (new byte[PREFERRED_LINE_BUFFER_SIZE], cmd); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/BulkSetMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import java.io.Serializable; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.Map.Entry; 23 | import org.jredis.KeyValueSet; 24 | import org.jredis.ri.alphazero.semantics.DefaultKeyCodec; 25 | import org.jredis.ri.alphazero.support.DefaultCodec; 26 | import org.jredis.semantics.KeyCodec; 27 | 28 | public abstract class BulkSetMapping implements KeyValueSet{ 29 | private final Map map = new HashMap(); 30 | abstract byte[] toBytes(T value) ; 31 | public byte[][] getMappings () { 32 | KeyCodec codec = DefaultKeyCodec.provider(); 33 | byte[][] mappings = new byte[map.size()*2][]; 34 | int i = 0; 35 | for (Entry e : map.entrySet()){ 36 | mappings[i++] = codec.encode(e.getKey()); 37 | mappings[i++] = toBytes(e.getValue()); 38 | } 39 | return mappings; 40 | } 41 | public KeyValueSet add (K key, T value) { 42 | map.put(key, value); 43 | return this; 44 | } 45 | // 46 | public static KeyValueSet.ByteArrays newByteArrayKVSet() { return new BulkSetMapping.Bytes(); } 47 | final static class Bytes extends BulkSetMapping implements KeyValueSet.ByteArrays { 48 | byte[] toBytes(byte[] value) { return value;} 49 | } 50 | public static KeyValueSet.Strings newStringKVSet() { return new BulkSetMapping.Strings(); } 51 | final static class Strings extends BulkSetMapping implements KeyValueSet.Strings { 52 | byte[] toBytes(String value) { return DefaultKeyCodec.provider().encode(value);} 53 | } 54 | public static KeyValueSet.Numbers newNumberKVSet() { return new BulkSetMapping.Numbers(); } 55 | final static class Numbers extends BulkSetMapping implements KeyValueSet.Numbers { 56 | byte[] toBytes(Number value) { return String.valueOf(value).getBytes();} 57 | } 58 | public static KeyValueSet.Objects newObjectKVSet() { return new BulkSetMapping.Objects(); } 59 | final static class Objects extends BulkSetMapping implements KeyValueSet.Objects { 60 | byte[] toBytes(T value) { return DefaultCodec.encode(value);} 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/alphazero/JRedisClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import static org.testng.Assert.fail; 20 | import org.jredis.ClientRuntimeException; 21 | import org.jredis.JRedis; 22 | import org.jredis.connector.ConnectionSpec; 23 | import org.jredis.ri.alphazero.support.Log; 24 | import org.testng.annotations.AfterTest; 25 | import org.testng.annotations.Test; 26 | 27 | /** 28 | * For testing the JRedis test suite for {@link JRedisClient} implementation. 29 | * TODO: should also do a minimal test using {@link ConnectionSpec}. 30 | * @author Joubin Houshyar (alphazero@sensesay.net) 31 | * @version alpha.0, Apr 17, 2009 32 | * @since alpha.0 33 | * 34 | */ 35 | 36 | //TODO: get rid of NG in class name 37 | 38 | @Test(singleThreaded = true, suiteName="JRedisClient-tests") 39 | public class JRedisClientTest extends JRedisProviderTestsBase { 40 | 41 | // ------------------------------------------------------------------------ 42 | // TEST SETUP 43 | // ------------------------------------------------------------------------ 44 | 45 | /* (non-Javadoc) 46 | * @see org.jredis.ri.alphazero.JRedisProviderTestNGBase#newJRedisProviderInstance() 47 | */ 48 | protected JRedis newProviderInstance () { 49 | JRedis provider = null; 50 | try { 51 | provider = new JRedisClient (this.host, this.port, this.password, this.db1); 52 | } 53 | catch (ClientRuntimeException e) { 54 | Log.error(e.getLocalizedMessage()); 55 | } 56 | return provider; 57 | } 58 | 59 | // ------------------------------------------------------------------------ 60 | // The Tests 61 | // ========================================================= JRedisClient 62 | /** 63 | * We define and run any additional, provider specific tests here. The 64 | * basic generally applicable JRedis interface method test are defined 65 | * in the super class. 66 | * 67 | * Here we test Quit in a post test method to insure all tests have been 68 | * completed. 69 | */ 70 | // ------------------------------------------------------------------------ 71 | /** 72 | * Test method for {@link org.jredis.ri.alphazero.JRedisSupport#auth(java.lang.String)}. 73 | */ 74 | @AfterTest 75 | public void testQuit() { 76 | Log.log("TEST: QUIT command"); 77 | try { 78 | JRedis provider = getProviderInstance(); 79 | provider.quit (); 80 | } 81 | catch (Exception e) { 82 | fail("QUIT" + e); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/connector/FaultedConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.connector; 18 | 19 | import java.util.concurrent.Future; 20 | import org.jredis.ClientRuntimeException; 21 | import org.jredis.NotSupportedException; 22 | import org.jredis.ProviderException; 23 | import org.jredis.RedisException; 24 | import org.jredis.protocol.Command; 25 | import org.jredis.protocol.Response; 26 | 27 | /** 28 | * {@link FaultedConnection} is a support class for implementors of JRedis API. 29 | * 30 | * @optional 31 | * @author Joubin Houshyar (alphazero@sensesay.net) 32 | * @version alpha.0, Apr 11, 2009 33 | * @since alpha.0 34 | * 35 | */ 36 | public class FaultedConnection implements Connection { 37 | 38 | /** */ 39 | final private String errorMsg; 40 | /** */ 41 | final private ConnectionSpec connSpec; 42 | 43 | /** 44 | * instantiates a faulted connection for the given {@link ConnectionSpec} 45 | * @param connSpec 46 | * @param errMsg 47 | */ 48 | public FaultedConnection (ConnectionSpec connSpec, String errMsg) { 49 | this.errorMsg = errMsg; 50 | this.connSpec = connSpec; 51 | } 52 | 53 | /* (non-Javadoc) @see org.jredis.connector.Connection#getSpec() */ 54 | @Override 55 | public ConnectionSpec getSpec() { 56 | return connSpec; 57 | } 58 | 59 | /* (non-Javadoc) @see org.jredis.connector.Connection#serviceRequest(org.jredis.protocol.Command, byte[][]) */ 60 | @Override 61 | public Response serviceRequest(Command cmd, byte[]... args) throws RedisException, ClientRuntimeException, 62 | ProviderException 63 | { 64 | throw new ClientRuntimeException (errorMsg); 65 | } 66 | 67 | /* (non-Javadoc) @see org.jredis.connector.Connection#queueRequest(org.jredis.protocol.Command, byte[][]) */ 68 | @Override 69 | public Future queueRequest(Command cmd, byte[]... args) 70 | throws ClientRuntimeException, ProviderException 71 | { 72 | throw new ClientRuntimeException (errorMsg); 73 | } 74 | /* (non-Javadoc) @see org.jredis.connector.Connection#addListener(org.jredis.connector.Connection.Listener) */ 75 | @Override 76 | final public boolean addListener (Listener connListener) { 77 | throw new NotSupportedException("Events not supported"); 78 | } 79 | /* (non-Javadoc) @see org.jredis.connector.Connection#removeListener(org.jredis.connector.Connection.Listener) */ 80 | @Override 81 | final public boolean removeListener (Listener connListener) { 82 | throw new NotSupportedException("Events not supported"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /core/ri/src/main/java/org/jredis/ri/alphazero/connection/DefaultConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero.connection; 18 | 19 | import java.security.ProviderException; 20 | 21 | import org.jredis.ClientRuntimeException; 22 | import org.jredis.NotSupportedException; 23 | import org.jredis.connector.Connection; 24 | import org.jredis.connector.Connection.Flag; 25 | import org.jredis.connector.ConnectionSpec; 26 | import org.jredis.ri.alphazero.support.Log; 27 | 28 | /** 29 | * [TODO: document me!] 30 | * 31 | * @author joubin (alphazero@sensesay.net) 32 | * @date Sep 15, 2010 33 | * 34 | */ 35 | 36 | public class DefaultConnectionFactory implements Connection.Factory { 37 | 38 | /* (non-Javadoc) @see org.jredis.connector.Connection.Factory#newConnection(org.jredis.connector.ConnectionSpec) */ 39 | public Connection newConnection (ConnectionSpec spec) 40 | throws ClientRuntimeException, NotSupportedException 41 | { 42 | Connection conn = null; 43 | switch (spec.getModality()){ 44 | case Monitor: 45 | throw new ProviderException("NOT IMPLEMENTED!"); 46 | case PubSub: 47 | throw new ProviderException("NOT IMPLEMENTED!"); 48 | case Asynchronous: 49 | conn = newAsyncConnection(spec); 50 | break; 51 | case Synchronous: 52 | conn = new SyncConnection(spec); 53 | break; 54 | } 55 | // TODO: factories create completed products -- 56 | // this class needs to set conn settings for ALL connection types 57 | // 58 | // if(spec.getConnectionFlag(Flag.CONNECT_IMMEDIATELY)) { 59 | // ((ConnectionBase)conn).initialize (); 60 | // } 61 | 62 | Log.debug("Created new %s", conn); 63 | return conn; 64 | } 65 | 66 | /** 67 | * Creates a new {@link Connection.Modality#Asynchronous} {@link Connection} 68 | * per {@link ConnectionSpec} settings. 69 | * @param spec 70 | */ 71 | private Connection newAsyncConnection (ConnectionSpec spec) { 72 | 73 | Connection conn = null; 74 | if(spec.getConnectionFlag(Flag.PIPELINE)){ 75 | conn = new AsyncPipelineConnection(spec); // why not for all asyncs? 76 | } 77 | else { 78 | if(spec.getConnectionFlag(Flag.SHARED)){ 79 | throw new ProviderException("NOT IMPLEMENTED! [Asynch|SHARED|not_PIPELINE]"); 80 | } 81 | else { 82 | conn = new AsyncConnection(spec); 83 | // conn = new AsyncPipelineConnection(spec); // why not for all asyncs? 84 | } 85 | } 86 | return conn; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /extensions/ri/src/main/java/org/jredis/ri/cluster/DefaultClusterSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2010 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.cluster; 18 | 19 | import java.util.Collection; 20 | import org.jredis.cluster.ClusterNodeSpec; 21 | import org.jredis.cluster.ClusterSpec; 22 | import org.jredis.cluster.ClusterType; 23 | import org.jredis.cluster.ClusterSpec.Support; 24 | import org.jredis.connector.ConnectionSpec; 25 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 26 | 27 | /** 28 | * The default ClusterSpec uses the {@link KetamaConsitentHashCluster_reture} as its {@link ClusterModel_deprecated}. 29 | * 30 | * @author joubin (alphazero@sensesay.net) 31 | * @date Mar 25, 2010 32 | * 33 | */ 34 | 35 | public class DefaultClusterSpec extends Support implements ClusterSpec { 36 | 37 | /** Default ClusterSpec.Type is {@link ClusterType#CONSISTENT_HASH} */ 38 | public static final ClusterType DEFAULT_CLUSTER_TYPE = ClusterType.CONSISTENT_HASH; 39 | 40 | // ------------------------------------------------------------------------ 41 | // Constructor 42 | // ------------------------------------------------------------------------ 43 | 44 | public DefaultClusterSpec () { 45 | this(null); 46 | } 47 | 48 | public DefaultClusterSpec (Collection nodeSpecs) { 49 | super(); 50 | this.setType(DEFAULT_CLUSTER_TYPE); 51 | if(null != nodeSpecs){ 52 | addAll(nodeSpecs); 53 | } 54 | } 55 | 56 | // ------------------------------------------------------------------------ 57 | // public interface 58 | // ------------------------------------------------------------------------ 59 | 60 | /** 61 | * @param host 62 | * @param firstPort 63 | * @param lastPort 64 | * @param templateConnSpec 65 | * @return 66 | */ 67 | public static ClusterSpec newSpecForRange (ConnectionSpec templateConnSpec, int firstPort, int lastPort) { 68 | ClusterSpec spec = new DefaultClusterSpec(); 69 | for(int i=firstPort; i<=lastPort; i++){ 70 | ConnectionSpec connSpec = DefaultConnectionSpec.newSpec() 71 | .setAddress(templateConnSpec.getAddress()) 72 | .setPort(i) 73 | .setDatabase(templateConnSpec.getDatabase()) 74 | .setCredentials(templateConnSpec.getCredentials()); 75 | ClusterNodeSpec nodeSpec = new DefaultClusterNodeSpec(connSpec); 76 | spec.addNode(nodeSpec); 77 | } 78 | return spec; 79 | } 80 | // ------------------------------------------------------------------------ 81 | // super overrides 82 | // ------------------------------------------------------------------------ 83 | } 84 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/alphazero/JRedisAsyncClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import static org.testng.Assert.fail; 20 | import org.jredis.ClientRuntimeException; 21 | import org.jredis.JRedisFuture; 22 | import org.jredis.connector.ConnectionSpec; 23 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 24 | import org.jredis.ri.alphazero.support.Log; 25 | import org.testng.annotations.AfterTest; 26 | import org.testng.annotations.Test; 27 | 28 | /** 29 | * [TODO: document me!] 30 | * 31 | * @author Joubin Houshyar (alphazero@sensesay.net) 32 | * @version alpha.0, Nov 6, 2009 33 | * @since alpha.0 34 | * 35 | */ 36 | @Test(sequential = true, suiteName="JRedisAsyncClient-tests") 37 | public class JRedisAsyncClientTest extends JRedisFutureProviderTestsBase { 38 | 39 | // ------------------------------------------------------------------------ 40 | // TEST SETUP 41 | // ------------------------------------------------------------------------ 42 | 43 | /* (non-Javadoc) 44 | * @see org.jredis.ri.ProviderTestBase#newProviderInstance() 45 | */ 46 | @Override 47 | protected JRedisFuture newProviderInstance () { 48 | JRedisFuture provider = null; 49 | try { 50 | ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(this.host, this.port, this.db2, this.password.getBytes()); 51 | provider = new JRedisAsyncClient(connectionSpec); 52 | } 53 | catch (ClientRuntimeException e) { 54 | Log.error(e.getLocalizedMessage()); 55 | } 56 | return provider; 57 | } 58 | // ------------------------------------------------------------------------ 59 | // The Tests 60 | // ========================================================= JRedisClient 61 | /** 62 | * We define and run any additional, provider specific tests here. The 63 | * basic generally applicable JRedis interface method test are defined 64 | * in the super class. 65 | * 66 | * Here we test Quit in a post test method to insure all tests have been 67 | * completed. 68 | */ 69 | // ------------------------------------------------------------------------ 70 | 71 | /** 72 | * Pipeline quit. 73 | * We first ping and await the response to insure pipeline has processed 74 | * all pending responses, and then issue the quit command. 75 | */ 76 | @AfterTest 77 | public void testQuit() { 78 | try { 79 | JRedisFuture pipeline = getProviderInstance(); 80 | pipeline.ping().get(); 81 | pipeline.quit().get(); 82 | } 83 | catch (Exception e) { 84 | fail("QUIT" + e); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /core/ri/src/test/java/org/jredis/ri/alphazero/JRedisChunkedPipelineClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2012 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.ri.alphazero; 18 | 19 | import static org.testng.Assert.fail; 20 | 21 | import org.jredis.ClientRuntimeException; 22 | import org.jredis.JRedisFuture; 23 | import org.jredis.connector.ConnectionSpec; 24 | import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; 25 | import org.jredis.ri.alphazero.support.Log; 26 | import org.testng.annotations.AfterTest; 27 | import org.testng.annotations.Test; 28 | 29 | /** 30 | * 31 | * @author Joubin Houshyar (alphazero@sensesay.net) 32 | * @version alpha.0, Jan 18, 2012 33 | * 34 | */ 35 | //@Test(invocationCount=20, threadPoolSize=5, sequential=false) 36 | @Test(singleThreaded = false, suiteName="JRedisChunkedPipeline-tests", invocationCount=20, threadPoolSize=5) 37 | public class JRedisChunkedPipelineClientTest extends JRedisFutureProviderTestsBase { 38 | 39 | // ------------------------------------------------------------------------ 40 | // TEST SETUP 41 | // ------------------------------------------------------------------------ 42 | 43 | /* (non-Javadoc) 44 | * @see org.jredis.ri.ProviderTestBase#newProviderInstance() 45 | */ 46 | @Override 47 | protected JRedisFuture newProviderInstance () { 48 | JRedisFuture provider = null; 49 | try { 50 | ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(this.host, this.port, this.db2, this.password.getBytes()); 51 | provider = new JRedisChunkedPipeline(connectionSpec); 52 | } 53 | catch (ClientRuntimeException e) { 54 | Log.error(e.getLocalizedMessage()); 55 | } 56 | return provider; 57 | } 58 | // ------------------------------------------------------------------------ 59 | // The Tests 60 | // ========================================================= JRedisClient 61 | /** 62 | * We define and run any additional, provider specific tests here. The 63 | * basic generally applicable JRedis interface method test are defined 64 | * in the super class. 65 | * 66 | * Here we test Quit in a post test method to insure all tests have been 67 | * completed. 68 | */ 69 | // ------------------------------------------------------------------------ 70 | 71 | /** 72 | * Pipeline quit. 73 | * We first ping and await the response to insure pipeline has processed 74 | * all pending responses, and then issue the quit command. 75 | */ 76 | @AfterTest() 77 | public void testQuit() { 78 | try { 79 | JRedisFuture pipeline = getProviderInstance(); 80 | pipeline.quit(); 81 | } 82 | catch (Exception e) { 83 | fail("QUIT" + e); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /core/api/src/main/java/org/jredis/protocol/Protocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Joubin Houshyar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jredis.protocol; 18 | 19 | import org.jredis.ClientRuntimeException; 20 | import org.jredis.NotSupportedException; 21 | import org.jredis.ProviderException; 22 | import org.jredis.connector.ConnectionSpec; 23 | import org.jredis.connector.Message; 24 | 25 | 26 | /** 27 | *

28 | * Protocol is effectively a {@link Message} factory. Implementations of this interface 29 | * provides Message objects that read and write according to a specific Redis protocol 30 | * specification. 31 | * 32 | *

Implementations may use this interface to address issues regarding buffer management. 33 | * [TODO: document me!] 34 | * 35 | * @author Joubin Houshyar (alphazero@sensesay.net) 36 | * @version alpha.0, 04/02/09 37 | * @since alpha.0 38 | * 39 | */ 40 | public interface Protocol { 41 | 42 | /** 43 | * 44 | * @param version 45 | * @return 46 | */ 47 | public boolean isCompatibleWithVersion (String version); 48 | 49 | /** 50 | * 51 | * @param cmd 52 | * @param args 53 | * @return 54 | * @throws ProviderException 55 | * @throws IllegalArgumentException 56 | */ 57 | public Request createRequest (Command cmd, byte[]...args) throws ProviderException, IllegalArgumentException; 58 | 59 | /** 60 | * Creates a response object for the {@link Command} specified. 61 | *

Note that this {@link Response} object has not yet been read. 62 | * @param cmd the {@link Command} that will be responded to. 63 | * 64 | * @return the response object that is ready to be read from the network connection. 65 | * 66 | * @throws ClientRuntimeException if the command is invalid for this version of the protocol 67 | * @throws ProviderException if the command is not implemented 68 | * 69 | * @see Response 70 | * @See {@link Response#read(java.io.InputStream)} 71 | */ 72 | public Response createResponse (Command cmd) throws ProviderException, ClientRuntimeException ; 73 | 74 | /** 75 | * EXPERIMENTAL 76 | * @param cmd 77 | * @param args 78 | * @return 79 | * @throws ProviderException 80 | * @throws IllegalArgumentException 81 | */ 82 | public byte[] createRequestBuffer(Command cmd, byte[]...args) throws ProviderException, IllegalArgumentException; 83 | 84 | public interface Factory { 85 | /** 86 | * Creates a {@link Protocol} instance for a connection per the specified 87 | * {@link ConnectionSpec} 88 | * @param connSpec 89 | * @return the new {@link Protocol} instance. 90 | * @throws NotSupportedException 91 | */ 92 | public Protocol newProtocol(ConnectionSpec connSpec) throws NotSupportedException; 93 | } 94 | 95 | } 96 | --------------------------------------------------------------------------------