Package org.jredis.connector

Examples of org.jredis.connector.ConnectionSpec


public class UsingJRedisPipeline extends UsingJRedisFuture {

  public static void main (String[] args) {
    final int database = 13;
    ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes());
   
      exampleUseofSyncInPipeline(connectionSpec);
    }
View Full Code Here


          String password = "jredis";
          InetAddress address = InetAddress.getLocalHost();
         
          // 1 - get the default connection spec
          //
          ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec();
         
          // 2 - customize it
          // here we're demonstrating the full set of parameters -- obviously you can just set what you need
          // but DO NOTE that the SO_PREF_XXX properties of TCP sockets must be defined as a set.  See
          // ConnectionSpec for javadoc details.
          //
          // Here we are spec'ing a connection that is NOT kept alive, and obviously is really keen on making sure
          // we connect as fast as possible.  This is a good connectionspec for disposable JRedisClients that are used
          // to issue a few commands and then discarded.  We're minimizing the connection overhead cost.
         
          connectionSpec
            // to be or not to be -- you decide
            //
            .setSocketFlag(Connection.Socket.Flag.SO_KEEP_ALIVE, Boolean.FALSE)        // DO NOT keep socket allive

            // connect retries on connection breaks
View Full Code Here

      // 1st example: using defaults
      // if your server expects a AUTH password, this will fail so see next block
      {
        // Note that if your localhost:6379 redis server expects a password
        // this will fail
        ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec();
        JRedisClient jredis = new JRedisClient(connectionSpec);
        try {
            jredis.ping();
            Log.log("Sweet success -- we're connected using all default values.");
          }
          catch (RedisException e) {
            Log.error("Failed to connect to Redis using JRedisClient default ConnectionSpec -- password perhaps? => " + e.getLocalizedMessage());
          }
      }
     
      // 2nd example: using defaults but setting the password and the database. 
      // also demonstrated using the method chaining on the ConnectionSpec property setters.
      {
        // Note that if your localhost:6379 redis server expects a password
        // this will fail
        String password = "jredis";
        int database = 11;
        ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec();
        connectionSpec
          .setCredentials(password.getBytes())
          .setDatabase(database);
       
        JRedisClient jredis = new JRedisClient(connectionSpec);
        try {
            jredis.ping();
            Log.log("Sweet success -- we're connected using %s as password to %d database.", password, database);
          }
          catch (RedisException e) {
            Log.error("Failed to connect to Redis using JRedisClient default ConnectionSpec -- password perhaps? => " + e.getLocalizedMessage());
          }
      }
     
      // final example: using defaults but setting the full set of basic settings 
      {
        // Note that if your localhost:6379 redis server expects a password
        // this will fail
        try {
          String password = "jredis";
          int     port = 6379;
          int     database = 11;
          InetAddress address = InetAddress.getLocalHost();
         
          // 1 - get the default connection spec for the basic settings
          //
          ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(address, port, database, password.getBytes());
         
          // finally - use it to create the JRedisClient instance
          //
          JRedisClient jredis = new JRedisClient(connectionSpec);
            jredis.ping();
View Full Code Here

*/

public class PipelineInAction {
  @SuppressWarnings("boxing")
  public static void main (String[] args) {
      final ConnectionSpec spec = DefaultConnectionSpec.newSpec();
      spec.setCredentials("jredis".getBytes());
      spec.setDatabase(13);
      spec.setSocketProperty(SO_RCVBUF, 1024 * 24);
      spec.setSocketProperty(SO_SNDBUF, 1024 * 24);
     
      usingSynchSemantics(spec);
      final boolean forever = true;
     
      runJRedisPipelineSET (spec, 100000, 3, forever);
View Full Code Here

public class UsingJRedisPipelineService {

  final JRedis jredis;
  private UsingJRedisPipelineService() {
    // same as usual.
    ConnectionSpec spec = DefaultConnectionSpec.newSpec();
    spec.setDatabase(11).setCredentials("jredis".getBytes());
   
    // only need to use the specific class.
    jredis = new JRedisPipelineService(spec);
  }
View Full Code Here

 
  /**
   * Using the synchronous interface
   */
  public static void usingSyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedis jredis = new JRedisClient(spec);

View Full Code Here

 
  /**
   * Using the asynchronous interface
   */
  public static void usingAsyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedisFuture jredis = new JRedisAsyncClient(spec);

View Full Code Here

 
  /**
   * Using the synchronous interface
   */
  public static void usingSyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedis jredis = new JRedisClient(spec);

View Full Code Here

  /**
   * Using the asynchronous interface
   */
  public static void usingAsyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedisFuture jredis = new JRedisAsyncClient(spec);

View Full Code Here

      byte[]       credentials
    )
    throws ClientRuntimeException
  {
//    return new DefaultConnectionSpec(address, port, database, credentials);
    ConnectionSpec spec = new DefaultConnectionSpec();
    return spec.setAddress(address).setPort(port).setDatabase(database).setCredentials(credentials);
   
  }
View Full Code Here

TOP

Related Classes of org.jredis.connector.ConnectionSpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.