Two types: hash type Introduction: redis
================================== Two types: hash type ========================== introduction: redis-hash is a string-type field-value ing table. hash is especially suitable for storing o
Introduction
Redis hash dictionary uses the key value to find the corresponding value. Note how the redis dictionary performs rehash.Source code dict. h dict. c Data Structure
As shown in, the hash dictionary is represented by a dict struct, which contains two hash tables f
1. Hash type key-value structureThe hash type is also a key-value structure, and key is a string type whose value is divided into two parts: field and ValueWhere the field section represents the property, and value represents the property corresponding to theIn the above figure, user:1:info for key, name,age,Date some properties of the user key, value is the value of the property.In the
Follow the Redis Getting Started Guide to learn
Chapter III 5 Types of data----hash type
3.3 (hash type)
Redis uses several structures to store data in the form of a health-value pair, while the health value of a hash type (hash)
Redis operations on string and hash data
Set name xiaohongyang //Get nameSetnx name xiaohyGet nameSetex name 10 jackxiaoSet email xiaohy@yahoo.comGet emailSetrange email 7 qq.comGet emailMset name xhy sex man age 30 // set multiple key values in batchesGet nameGet sexGet ageMsetnx name xhy1 setx man age 28 city suzhouMsetnx name1 xhy1 setx man age1 28 city suzhouGetset name xhy_new // get the current value
"Redis hash Operation "1.hset key field value Sets in the field hash stored on key to value . If key does not exist, a new key holding a hash is created. If field already exists in the hash, it's overwritten.Return valueInteger reply, specifically:
1If is field
The question may not be very good at the beginning. At least the meaning should be clear. Hope you can give me some guidance. Due to business needs, you need to add all the feed data tables to redis for data storage, which brings a series of questions and puzzles. The feed table contains the following data: {code...} If you write f... in the first place, the question may not be very good. At least the meaning should be clear.
Due to business needs, y
Written in the first, may ask not very good, at least the meaning should be expressed clearly, hope you guide.
As a result of business needs, the feed data table needs to be poured into Redis, to do the data storage function, which brings a series of doubts and puzzled.
The following data is available in the Feed table:
$data = array( array("feed_id"=>1,"uid"=>1,"content"=>"xiaoxijilu"), array("feed_id"=>2,"uid"=>2,"content"=>"xiaoxijil
Python's common operations on redis (list, string, and hash structure operations) and pythonredis
All the discussions here are based on the python redis-py library.
Installation and use:
pip install redis
Then obtain a redis client:
redis_conn = redis.Redis(host=REDIS_HOST,
This is a creation in
Article, where the information may have evolved or changed.
1: Install Redigo
go get github.com/garyburd/redigo/redis
2:import Redigo
import ( "github.com/garyburd/redigo/redis")
3: Connect Redis
c, err := redis.Dial("tcp", "192.168.2.225:6379")if err != nil { fmt.Println("connect to redis
: Similar to DECR, minus the specified value.
Append: Appends value to the string of the specified key, returning the length of the new string value
Strlen: Takes the length of the value of the specified key
2) Hash type
Hash type and operation
The Redis
================================== 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
A Redis hash value is a mapping between a string field and a string valueIt provides many convenient domain operations compared to data types such as String, so it is a very good data type when it comes to representing objects.The hash value storage capacity in Redis is very large and can store more than 4 billion key
Use zookeeper to implement consistent hash.
When the redis service starts, it writes its route information to ZK through a temporary node, and the client reads available route information through ZK client.
Server
Daemon written with Python script: https://github.com/LittlePeng/redis-manager
The script is deployed on the
In Redis, the hash data type stores data in a very similar way to storing a record in a MySQL database, a string-type field and value mapping table, which is particularly well-suited for storing objects, but the field values can only be strings and no other types are supported.
In the hash type, a key can correspond to more than one field, and a field correspo
Python processes the chunks of json and redis hash, jsonredis
1. The data read using MySQLdb is a unicode string. If you want to write data to the redis hash, it will become
"{u'eth0_outFlow': 2.5, u'eth1_inFlow': 3.44}"
Json. loads cannot be used. unicode must be converted to str in advance:
str(eth0_outFlow)
2. Keys
Introduction
Common commands: Hget;hset;hgetall, etc.
We can consider the hashes type in Redis as a map container with string key and string value. Therefore, this type is ideal for storing information about value objects. such as username, password, and age. If a hash contains very few fields, the data of that type will take up only a small amount of disk space. Each
I always thought that he could store multiple rows of a KEY like MYSQL, but actually he could not. For example, he could only store one KEY for one HASH, but now there is a requirement, I want to know whether a field in this KEY is equal to a value. If it is equal to a value, I will retrieve it directly, just like MYSQL... I always thought that he could store multiple rows of a KEY like MYSQL, but actually he could not. For example, he could only stor
Hashtable
Hmset--------------------------------------------------------- field-value Set multiple (domain-value) pairs into a hash table at the same time key
Hset-----------------------------------------------------------to set the value of the key field in the hash table field tovalue
Hsetnx--------------------------------------------------------Sets the key value of the field in the Hashtable field
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.