Redis is developed by the Italians a memory cache database, is a high-performance key-value pair (key-value) stored in the database.
Redis full name: Remote Dictionary Server (Remote Data Service), written in C, and to the memory as a data storage medium, it is very efficient read.
Redis supports not only simple key-value data types, while also providing value into list, set, zset, hash and other data storage structure.
Since Redis fast exchange of data, so the server used to store some of the data retrieved frequently improve efficiency.
1.Redis basic use:
01. connection Redis: redis-cli
02. Exit: exit
03. but change the database: select n (n is the number but change the default library database, the database has no name, the default is 16, 0-15, is the first to enter the default database)
04. Operation server: service redis start / stop / restart /
redis five data types: list, set, Zset, hash, string.
string type: string is redis basic type, a key corresponding to a value.
set key value setting data
get key View data
append key value added data
del key to delete data
key-value: mset key1 value1 key2 value2 .... plurality of data
Global key: At the command redis five data types are applicable.
key * View all the key
Delete key-value pairs: del key
exists key to see if the key exists.
改名:rename key new_name
Set expiration time: expire key seconds (codes used in this regard are many)
Ttl viewing time set, persist key to delete the expiration time
Type list: list type is a list of strings, may be added to the list header or tail / delete data, when inserting data, if the key does not exist, that creates a Redis key.
1. Add data: rpush key value
lpush key value [value .....] ------- adding header data (left and right left and right)
2. View data: lrange key stare stop
lindex key index -------- view certain data
3. Modify the data: lset key index value
4. Delete Data: rpop key
lpop key ----------- head delete data
Hash type: a key (key => value) pairs. Type string field value and a mapping table
user { name:juhao, age:18 }
user - "key (key) name, age -" field (field) juhao, 18 --- "value (Value)
Adding Data: hset key field value { 'key': { 'field': 'value'}}
View threshold: hget key field
hgetall key --- "to see all the field and value
See all value: hvals key
See all the field: hkeys key
type is set unordered set of characters, unique elements will not be repeated.
Adding data: sadd key member [member ...]
View data: smembers key
Random Delete: spop key
Specifies to delete: srem key member [member ...]
Z set type: each member will have associated with it a score (score). Members only, but the score is repeatable.
Adding data: zadd key score member [score2 member2 ...]
View data: zrange key start stop
zrangebyscore key min max - "Show value by scores
To delete data: zrem key member [member ...]
Index by deleting a plurality of data: zremrangebyrank key min max
zremrangebyscore key min max --- "Delete value by scores