zoukankan      html  css  js  c++  java
  • 五:利用java使用redis

    一:下载驱动包

      http://static.runoob.com/download/jedis-2.9.0.jar

    二:连接测试使用

    string:

     1 package string;
     2 
     3 import redis.clients.jedis.Jedis;
     4 
     5 public class StringTest {
     6     public static void main(String[] args) {
     7         Jedis redis=new Jedis("localhost");//连接本都库
     8         System.out.println("ping:"+redis.ping());//ping一下看看是不是已连接
     9         redis.set("stringone", "helloword");//set
    10         System.out.println(redis.get("stringone"));//get
    11     }
    12 }

    list:

     1 package list;
     2 
     3 import java.util.List;
     4 
     5 import redis.clients.jedis.Jedis;
     6 
     7 public class ListTest {
     8 public static void main(String[] args) {
     9     Jedis redis=new Jedis("localhost");
    10     System.out.println("ping:"+redis.ping());
    11     redis.lpush("listone", "aa");
    12     redis.lpush("listone", "bb");
    13     redis.lpush("listone", "cc");
    14     redis.lpush("listone", "dd");
    15     List<String> list1=redis.lrange("listone", 0, redis.llen("listone"));
    16     for (String string : list1) {
    17         System.out.println(string);
    18     }
    19 }
    20 }
  • 相关阅读:
    navicat for mysql (本人亲测,真实有效)
    python 8 days
    python 19 days
    python 20 days
    python 21 days
    python 10 days
    python 9 days
    python 14 days
    python 15 days
    python 16 days
  • 原文地址:https://www.cnblogs.com/GH0522/p/9242776.html
Copyright © 2011-2022 走看看