zoukankan      html  css  js  c++  java
  • Jedis测试redis

    首先:Jedis是redis的java版本的客户端。

    public class JedisTest {
    //单机版测试Jedis,不使用连接池
    @Test
    public void testJedis(){
    //创建Jedis对象
    Jedis jedis=new Jedis("192.168.146.128", 6379);

    //设置对象
    jedis.set("key1", "jedis test");
    String string=jedis.get("key1");
    System.out.println(string);
    //关闭jedis
    jedis.close();
    }
    //单机版测试Jedis,这是使用连接池的方式来获取redis的资源
    @Test
    public void testJedispool(){
    JedisPool pool=new JedisPool("192.168.146.128", 6379);
    Jedis resource=pool.getResource();
    String string=resource.get("key1");
    System.out.println(string);
    //不要忘记关闭连接池了
    pool.close();
    resource.close();

    }
    //集群版,测试redis集群环境
    @Test
    public void testJiQun(){
    HashSet<HostAndPort> nodes=new HashSet<HostAndPort>();
    //这里的ip和后面的端口是,在linux系统的ip和配置的不同的redis的端口
    nodes.add(new HostAndPort("192.168.146.128",7001));
    nodes.add(new HostAndPort("192.168.146.128",7002));
    nodes.add(new HostAndPort("192.168.146.128",7003));
    nodes.add(new HostAndPort("192.168.146.128",7004));
    nodes.add(new HostAndPort("192.168.146.128",7005));
    nodes.add(new HostAndPort("192.168.146.128",7006));

    JedisCluster cluster=new JedisCluster(nodes);
    cluster.set("key4", "hello world");
    String string=cluster.get("key4");
    System.out.println(string);
    cluster.close();

    }

  • 相关阅读:
    快速收录方法
    .NET学习网址大全,不得不上,国内外经典网站
    首篇文章测试。
    DropDownList的用法
    SqlServer初级学习笔记
    GDI编程开发
    C#继承细谈
    web开发的一些小零碎知识点(一)
    Js实现全选和批量删除
    IEnumberable和IEnumberator理解
  • 原文地址:https://www.cnblogs.com/fengli9998/p/6200480.html
Copyright © 2011-2022 走看看