Redis is an open source API that is written in ANSI C, supports the web, can be persisted in memory, key-value databases, and provides multiple languages.
Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis. Redis is a high-performance Key-value database. The emergence of Redis, to a large extent, compensates for the lack of memcached such key/value storage, in some cases can be a good complement to the relational database. It provides clients such as Java,c/c++,c#,php,javascript,perl,object-c,python,ruby,erlang, which is convenient to use. Redis supports master-slave synchronization. Data can be synchronized from the primary server to any number of slave servers, from the server to the primary server that is associated with other slave servers. This enables Redis to perform single-layer tree replication. You can write to the data intentionally or unintentionally. Because of the full implementation of the publish/subscribe mechanism, you can subscribe to a channel and receive a complete message release record from the master server when the tree is synchronized anywhere from the database. Synchronization is helpful for the scalability and data redundancy of read operations. 1.Redis Installation
$ wget http://download.redis.io/releases/redis-3.0.3.tar.gz
$ tar xzf redis-3.0.3.tar.gz
$ cd redis-3.0.3
$ make
$ src/redis-server
# Open service, default port number: 6379
2.Package Installation
$ sudo pip install Redis
or
$ sudo easy_install redis
or from source
$ sudo python setup.py install
3. Use
>>> Import Redis
>>> r = Redis. Strictredis (host= ' localhost ', port=6379, db=0)
>>> r.set (' foo ', ' Bar ')
True
>>> R.get (' foo ')
' bar '
A pipeline (pipeline) is a subclass of a base class in which Redis buffers multiple server commands in a single request. It greatly improves the ability to perform bulk commands by reducing the repeated TCP database packets between servers-clients.
>>> p.set (' Hello ', ' Redis '). P.sadd (' Faz ', ' Baz '). INCR (' num '). Execute ()
When there are many types of document objects, the contents of the document are different, (that is, "table" does not have a fixed column), you can use hash to express.
>>> r.hset (' Users:jdoe ', ' name '," John Doe ") 1L >>> r.hset (' Users: JDoe ', ' email ', ' John@test.com ') 1L >>> r.hset (' Users:jdoe ', ' phone ', ' 1555313940 ') 1L >>> R.hincrby (' Users:jdoe ', ' visits ', 1) 1L >>> r.hgetall (' Users:jdoe ') {' phone ': ' 1555313940 ', ' name ': ' John Doe ', ' visits ': ' 1 ' Email ': ' John@test.com ' >>> r.hkeys (' Users:jdoe ') [' name ', ' email ', ' phone ', ' visits ']