Redis Learning Note (3)-hash

Source: Internet
Author: User

Package Cn.com;import Java.util.hashmap;import Java.util.list;import java.util.map;import java.util.Set;import Redis.clients.jedis.jedis;public class Redis_hash {public static Jedis Redis = new Jedis ("localhost", 6379);//Connection Redispub Lic static void Main (String [] args) {Hkeys ();} /** * Hset Sets the value of the field field in the hash table key to values. * Hget Returns the value of the given field field in the hash table key. * Hgetall returns the hash table key, all fields and values. * * */public static void Hset_hget_hgetall () {redis.flushdb ();//Clear Data Redis.hset ("user", "id", "1"), Redis.hset ("User", " Name "," Liliang "); Redis.hset (" User "," age "," 18 "); System.out.println ("==========hget============"); System.out.println (Redis.hget ("User", "id")); System.out.println (Redis.hget ("User", "name"); System.out.println (Redis.hget ("User", "age"); System.out.println ("=========hgetall==========="); Map<string,string> map=redis.hgetall ("user"); SYSTEM.OUT.PRINTLN ("ID:" +map.get ("id")); System.out.println ("Name:" +map.get ("name")); System.out.println ("Age:" +map.get ("Age")); /** * hmset key field value [field Value ...] * Multiple Field-value (domain-value) pairs are also set to the hash table key. * This command overwrites fields that already exist in the hash table. * If key does not exist, an empty hash table is created and the Hmset operation is performed. * */public static void Hmset_hmget () {redis.flushdb ();//Clear Data map<string,string> map=new hashmap<string,string > ("id", "1"), Map.put ("name", "Liliang"), Map.put ("Age", "Map.put"), Redis.hmset ("user", map); System.out.println ("======hmget=========="); List<string> list=redis.hmget ("user", "id", "name", "Age"), and for (String s:list) {System.out.println ("s:" +s);}} /** * Hlen Key * Returns the number of fields in the hash table key. * */public static void Hlen () {redis.flushdb ();//Clear Data map<string,string> map=new hashmap<string,string> (); Map.put ("id", "1"), Map.put ("name", "Liliang"), Map.put ("Age", "all"), Redis.hmset ("user", map); Long Length=redis.hlen ("user"); System.out.println ("Length:" +length);} /** * Hkeys Key * Returns all fields in the hash table key. * */public static void Hkeys () {redis.flushdb ();//Clear Data map<string,string> map=new hashmap<string,string> () ; Map.put ("id", "1"); Map.put ("Name", "Liliang"); Map.put ("Age", "all"); RediS.hmset ("user", map); Set<string> Set=redis.hkeys ("user"); for (String S:set) {System.out.println ("s:" +s);}}}

  

Redis Learning Note (3)-hash

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.