Ii. redis hash operations, redishash

Source: Internet
Author: User
Tags map data structure

Ii. redis hash operations, redishash
================================== Two types: hash type ============================
Description: redis-> hash is a string type field and value ing table.
Hash is especially suitable for storing objects. It stores each field of an object as a single string type.
Storing an object in the hash type consumes less memory and can easily access the entire object.


0: hset * If the key (that is, the hash table) does not exist, a new hash table is created and HSET is performed.
Set hash field to the specified value. If the key does not exist, create
Example: hset user: 001 name leyangjun creates a table

0.2: hsetnx
Set hash field to the specified value. If the value does not exist, create the value. If the value exists, 0 is returned.
Example: hsetnx user: 002 name leyangjun
1: hmset: Set the Field Values of multiple hash tables
Set multiple hash fields at the same time
Example: hmset user003 name leyangjun age 23 sex 1 --> hash table 003 value set successfully
Hget get: hget user: 003 name --> get the 003 name value of the hash table
2: hget
Obtains the specified hash field value.
Example: hget user003 name --> indicates the field
3: hmet
Obtains all specified hash fields.
Example: hmet user: 003 name age sex
4: hincrby)
Add a specified value to the specified hash field
Example: hincrby user: 003 age 5 --> Add 5 20 + 5 to the original age value
5: hexists
Test whether the specified field exists.
Example: hexists user: 003 sex --> judge whether the hash table field exists
6: hlen
Returns the number of all fields in the specified hash table.
Example: hlen user003
7: hdel
Deletes the field value in the specified hash table.
Example: hdel user003 age --> Delete the age field in user003
8: hkeys
Returns all fields in the hash table.
Example: hkeys user003
9: hvals
Returns all values of the hash table.
Example: hvals user003 --> values of keys in all tables
10: * Common hgetall
Obtains all fields and values in a hash.
Example: hgetall user003
========================================================== = END ============================================== =
Java Development 2.0: Redis in the Real World: how does Redis beat memcached in applications that contain a large number of read operations? In addition, I also discussed the advantages and disadvantages of server-based data storage compared with MongoDB and CouchDB, each data storage has its own advantages and disadvantages, especially when used in in specific fields, Java Development 2.0 focuses on Redis lightweight key-value pairs. Most NoSQL implementations of data storage are essentially key-value pairs. Redis supports a wide range of value sets, including strings, lists, sets, and hashes. therefore, Redis is usually called a Data Structure server. Redis is also very fast and well-known. It can be used as a special type of use case. It can be helpful when we want to know something new. we started the Redis exploration journey by comparing Redis with memcached. Next we introduced some of Redis's main features to make some of its application scenarios Better Than memcached. I will show you what Redis uses as a traditional data storage for Model objects. redis and memcach Ed Memcached is well known that the memory object cache system imports the target key and value into the memory cache for running. Therefore, Memcached can avoid the I/O cost issue when reading the disk. When memcached is pasted between the Web application and the database, it will produce better read results. therefore, for some applications that require fast data query, Memcached misselects its example. The stock query service needs to access the database to obtain the relative static data stock name or price information. MemcacheDB Redis and memcached are compared fairly with MemcacheDB. compared with MemcacheDB, which has many Distributed Key-value pairs for dedicated data persistence in the storage system, MemcacheDB is designed to be similar to Redis. Its new advantages make it easy to communicate with memcached to implement client-side communication. memcached also has its limitations. all values are simple strings. Redis is used as a memcached replacement. More functions are supported to set some benchmarks (benchmarks) it also indicates that the Redis speed is high. Redis is much faster than memcached. It provides a wide range of data types to make its memory more complex to store data. Using memcached, Redis cannot achieve persistence of its data like memcached. Redis solves major cache problems, and its rich feature set is I found its purpose. Because Redis can store data on disks and replicate data across nodes, it is used as a data warehouse in traditional data mode (that is, you use Redis like RDBMS) redis is also often used as a queue system. This Use Case Redis backup and work queue persistent storage (using the Redis list type) basis GitHub This method uses the Redis large-scale infrastructure example to prepare Redis for immediate start! To start using Redis, you need to access through local installation or hosting vendor. You can use MAC to install Windows in a simple way ?? You need to install Cygwin first. You are looking for a hosting vendor Redis4You. You have a free plan to manage your access methods. You can perform operations according to the following examples in this article. I need to point out that using a hosting vendor for caching can solve the problem well. the scheme can offset any performance advantage due to network latency. You need to use commands to interact with Redis. In other words, no SQL query language. Using Redis works very similar to using a traditional map data structure, that is, all switches have each key and value has multiple associated data types. Each data type has its own command set. For example, you plan to use a simple data type. the command line shell interacts with the Reids instance, and the multi-client programming mode interacts with Redis. List 1 shows the shell interaction using the basic command simple command line: listing 1. run Redis 127.0.0.1: 6379> set page registration OK redis 127.0.0.1: 6379> keys * 1) "foo" 2) "page" redis 127.0.0.1: 6379> in get page "registration", I used the set command key "page" to connect with the value "registration". I issued the keys command (the fix * indicates that I want to see all the keys with the instance key. the command displays page values and foo. I use the get command to retrieve key-related values. Please remember that only string key-value lists can be retrieved using the get command. You must use a specific LIST command to retrieve list elements. query value type commands) java and Jedis integration for some Redis programmers who want Redis to integrate Java applications, the Redis team recommends using the Jedis project Jedis lightweight library local Redis command ing Java method example Jedis to get and set the simple Value List 2, as shown in: list 2. java code basic Redis command JedisPool pool = new JedisPool (new JedisPoolConfig (), "localhost"); Jedis jedis = pool. getResource (); jedis. set ("foo", "bar"); String foobar = jedis. get ("foo"); assert foobar. equals ("bar"); pool. returnResource (jedis); pool. destroy (); Listing 2 I configured the connection pool and captured the connection (very similar to the operations in your typical JDBC scenario) at the bottom of my list, I set the return operation connection pool logic. I set the value "bar" and the key "foo". I use the get command to retrieve Redis similar to memcached that allows you to expire (expiration) therefore, I set a sample value for the time correlation value (compared to the temporary stock transaction price) finally, clear the cache from apsaradb for Redis. I want to set the expiration time in Jedis. I need to issue a set call. Its associated with the expiration time is shown in listing 3: Listing 3. set the Redis value to terminate jedis. set ("gone", "daddy, gone"); jedis. expire ("gone", 10); String there = jedis. get ("gone"); assert there. equals ("daddy, gone"); Thread. sleep (4500); String notThere = jedis. get ("gone"); assert notThere = null; Listing 3 I used expire to call the "gone" value and set it to terminate the call Thread within 10 seconds. sleep's "gone" get call will return nullRedis data type. Using Redis data type Comparison List and hash requires dedicated command usage. For example, I create a list using key value-added
What is redis rediskey-value storage system? similar to Memcached, redis supports storing more value types, including string, list, and set), zset (sorted set -- ordered set) and hash (hash type) some data types support push/pop, add/remove, Intersection Set, difference set, and richer operations, and some operations are atomic. On this basis, redis supports various same-way sorting and memcached samples. guaranteed efficiency data cache memory difference redis will periodically write the updated data to the disk or write the modification operation to the append record file. On this basis, the master-slave (master-slave) is implemented) synchronization
Redis's high-performance key-value database redis greatly compensates for memcached-type key/value storage. It plays a complementary role in relational databases in different scenarios and provides the PythonRubyErlangPHP client for ease of use.
Redis provides five data types: stringhashlistset and zset (sorted set)
Redis uses two file formats: full data and incremental requests.

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.