title: Hello World example using the JRedis client
body: <p>I want to use Redis with Java so I started with <a href="https://github.com/alphazero/jredis/blob/1.2.n/examples/src/main/java/org/jredis/examples/HelloAgain.java" rel="nofollow">this</a> simple example (see the code below).</p>
  
  <p>The first run inserts a key,value pair to the database and the second run should get the value and print it to screen. There are two problems that I don't understand:</p>
  
  <ol>
  <li><p>When I insert the key it prints out an error that the value is not a command: "Error response for PING => ERR unknown command "Hello Again!". This does not make sense to me -- why does it think that the String value is a command?</p></li>
  <li><p>When I run it a second time to print the value for the key, it only prints the length of the value but I expected to see "Hello Again!" printed.</p></li>
  </ol>
  
  <p>Thanks for the help!</p>
  
  <p>Here's the code:</p>
  
  <pre><code>import org.jredis.ClientRuntimeException;
  import org.jredis.JRedis;
  import org.jredis.ProviderException;
  import org.jredis.RedisException;
  import org.jredis.protocol.Command;
  import org.jredis.ri.alphazero.JRedisClient;
  import static org.jredis.ri.alphazero.support.DefaultCodec.*;
  
  /**
   * [TODO: document me!]
   *
   * @author  Joubin Houshyar (alphazero@sensesay.net)
   * @version alpha.0, Apr 15, 2009
   * @since   alpha.0
   * 
   */
  
  public class HelloAgain {
      public static final String key = "jredis::examples::HelloAgain::message";
      public static void main(String[] args) {
          String password = "";
          if(args.length &gt; 0) password  = args[0];
          new HelloAgain().run(password);
      }
  
      private void run(String password) {
          try {
              JRedis  jredis = new JRedisClient("localhost", 6379, "jredis", 0);
              jredis.ping();
  
              if(!jredis.exists(key)) {
                  jredis.set(key, "Hello Again!");
                  System.out.format("Hello!  You should run me again!\n");
              }
              else {
                  String msg = toStr ( jredis.get(key) );
                  System.out.format("%s\n", msg);
              }
              jredis.quit();
          }
          catch (RedisException e){
              if (e.getCommand()==Command.PING){
                  System.out.format("I'll need that password!  Try again with password as command line arg for this program.\n");
              }
          }
          catch (ProviderException e){
              System.out.format("Oh no, an 'un-documented feature':  %s\nKindly report it.", e.getMessage());
          }
          catch (ClientRuntimeException e){
              System.out.format("%s\n", e.getMessage());
          }
      }
  }
  </code></pre>