Jedis Call the Redis list

Source: Internet
Author: User
Tags array length redis sort
Package Com.alex.xiyoubang;

Import java.util.List;
Import Redis.clients.jedis.BinaryClient.LIST_POSITION;

Import Redis.clients.jedis.Jedis;

    public class Jedislist {static Jedis Jedis = new Jedis ("192.168.1.171", 6379);
        public static void Main (string[] args) {System.out.println ("==list==");
        Emptying Data System.out.println (JEDIS.FLUSHDB ());
        Add Data Jedis.rpush ("names", "Tang Priest");
        Jedis.rpush ("Names", "Goku");
        Jedis.rpush ("Names", "eight Commandments");
        Jedis.rpush ("Names", "Wu Jing"); Then take out all the data jedis.lrange is out by range,//The first is key, the second is the starting position, the third is the end position, Jedis.llen gets the length-1 means get all list<string> Valu
        ES = Jedis.lrange ("Names", 0,-1);


        System.out.println (values);
        Emptying Data System.out.println (JEDIS.FLUSHDB ());
        Add Data Jedis.lpush ("scores", "100");
        Jedis.lpush ("Scores", "99");
        Jedis.lpush ("scores", "55");
        Array length System.out.println (Jedis.llen ("scores")); //Sort System.out.println (Jedis.sort ("scores"));
        String System.out.println (Jedis.lrange ("scores", 0, 3));
        Modifies a single value in the list Jedis.lset ("scores", 0, "66");
        Gets a list that specifies the value of the System.out.println (Jedis.lindex ("scores", 1));
        The Delete list specifies the underlying value System.out.println (Jedis.lrem ("scores", 1, "99"));
        Delete data outside the interval System.out.println (Jedis.ltrim ("scores", 0, 1));
        List out Stack System.out.println (Jedis.lpop ("scores"));
        The entire list value System.out.println (Jedis.lrange ("scores", 0,-1)); Before 100, add the data data Jedis.linsert ("scores", list_position.
        Before, "100", "22"); After 100, add the data data Jedis.linsert ("scores", list_position.
        After, "100", "77");
        The entire list value System.out.println (Jedis.lrange ("scores", 0,-1));
        Change the second data of key scores in list to Jedis.lset ("scores", 1, "88");
        The entire list value System.out.println (Jedis.lrange ("scores", 0,-1));
      Intercept elements within a list interval  Jedis.ltrim ("Scores", 1, 2);
        The entire list value System.out.println (Jedis.lrange ("scores", 0,-1)); Inserts the value values into the footer of the list key when and only if key exists and is a list.
        When key does not exist, the RPUSHX command does nothing.
        Jedis.rpushx ("name", "Alex");
    System.out.println (Jedis.lrange ("name", 0,-1)); }

}

List command detailed description see: http://blog.csdn.net/qq_32347977/article/details/50510231

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.