zoukankan      html  css  js  c++  java
  • JAVA中使用Redis

      上节讲解了如何在centos上安装redis,点击查看。本节我们学习在java中使用redis。需要将jedis-*.jar添加到classpath(点击下载),如果使用连接池还需要commons-pool-*.jar(点击下载)添加到classpath,文章的附件中可供大家下载。

    public class Test {
    
        public static void main(String[] args) {
            try {
                //连接本地的 Redis 服务
                Jedis jedis = new Jedis("你的redis服务id");
                System.out.println("Connection to server sucessfully");
                //存储key为blog的数据至redis
                jedis.set("blog", "http://www.cnblogs.com/myzhijie");
                //读取出来,执行结果:http://www.cnblogs.com/myzhijie
                System.out.println(jedis.get("blog"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    如果连接不上,请查看redis服务器端口是否打开,可以在本地使用telnet命令检查。

  • 相关阅读:
    Car HDU
    Defeat the Enemy UVALive
    Alice and Bob HDU
    Gone Fishing POJ
    Radar Installation POJ
    Supermarket POJ
    Moo Volume POJ
    Text Document Analysis CodeForces
    checkbox全选与反选

  • 原文地址:https://www.cnblogs.com/myzhijie/p/4803262.html
Copyright © 2011-2022 走看看