See everyone needs redis, and I work but not how to contact, special to learn, now first familiar with instructions, I through the Redis Chinese Interactive tutorial (interactive tutorial) to learn.
1.redis is a data structure storage system that key-value stored, placed in memory, and persisted on disk, which can be used as a database, cache, and message middleware.
Stored by Set key value, get value by Get key
Set Key value: Sets the value of key, overwriting if it exists
Setnx key Value:set If not eXists, if present, does not operate. MSET key1 value1 key2 value2 ... keyN valuen: Sets the value of these keys, overwriting get key if present : Gets the value corresponding to key Mget key1 ... Key2: get These keys correspond to values msetnx key1 value1 key2 value2 ... keyN valuen: Same as Mset, but if one of the keys already exists, it is not set. All of these operations are atomic.
EXISTS key: See if the element exists.
Getset key value: Gets the value of the element and sets a new value for the element. (usually used with the incr, such as a mycount has been incr, and then to achieve certain conditions need to clear, clear 0 before you need to know the value of Mycount).
Del key: Delete element
RENAME oldkey Newkey: Renaming
The 2.redis provides atomic self-increment operation INCR to prevent multiple-threaded concurrency from data errors.
INCR key: Atom's +1; DECR key: Atom -1;
Decrby key integer: The-integer of the atom;
Incrby key integer: The +integer of the Atom
3. Delete operation: Del. return (NIL) if data does not exist
4.redis can be stored on a timed basis, which is set to delete the variable after a few seconds
expire key How many seconds : Set the number of seconds after expiration, ttl key:time to live, see how long it can survive,-2 means that key does not exist;-1 means that the scheduled task disappears and is permanently stored.
EXPIRE key seconds: How many seconds after setting the element expires Pexpire key milliseconds: Set the element after how many milliseconds to expire TTL key: See how many seconds can also survive,2 means that key does not exist, 1 means permanent storage
Setex Key seconds value: is equivalent to setting the variable before the timeout, that is, used in the cache: stored at the same time set the time-out, the operation is atomic
->->->
5. Store ordered queues: List
rpushkeylist value: add element to Keylist, backward, R for right
Lpush keylist Value: Adds an element to the left of Keylist, Lpush puts the new value at the start of the list.
lrangekeylist beginindex endIndex: Gets the elements of the keylist, takes a subset with the index at both ends, and EndIndex=-1 means to remove all
Here it is necessary to understand the storage types of REDIS data structures, strings (strings), hashes (hashes), lists (lists), collections (sets), ordered collections (sorted sets) and range queries, bitmaps, Hyperloglogs, and Geo-spatial (geospatial) Index RADIUS query. Redis has built-in replication (replication), LUA scripting (LUA scripting), LRU driver events (LRU eviction), transactions (transactions), and different levels of disk persistence (persistence), and Redis Sentinel (Sentinel) and automatic partitioning (Cluster) provide high availability (HI availability).
Now learn list:
->->->
llen keylist : Gets the length of the keylist lpop keylist: Remove and remove the keylist first element, the left element rpop keylist: Remove and remove the last element of Keylist, the element on the right
LINDEX Key index: Gets the element under the index.
Lrem Key Count Value: Removes count of value. (Count is positive, start from scratch, delete count value elements, count is negative, |count| value element is removed from tail to head, count is 0, all elements are deleted for value)
LSET Key Index value: Sets the index to the element below index as value. Out of index range error.
LTRIM Key start end: Empties the index from the start and end elements, the index starts at 0, the ends are reserved, and the ends are emptied.
Rpoplpush srckey dstkey: Source queue Srckey, destination queue Dstkey, remove the last Srckey, and place the first one in Dstkey.
-》-》
6. Unordered and unique set set
And the list in Java is the same as set. The set here is unordered and the value is unique.
The next data structure that we'll look at is a set. A set is the similar to a list, except it does not has a specific order and each element could only appear once. Some of the important commands in working with sets are sadd, srem, sismember, smembers and& nbsp Sunion.
sadd Key value : add element to set Srem key value : remove element from set smembers key : Remove all set elements Sismember key Val UE: To see if value exists in set sunion key1 key2 ... keyN: Merge all keys and take them out, same value only once
SCard key: Gets the number of elements in set
Sdiff key1 key2 ... KeyN: Gets the element in the first set that does not exist in the following set.
Sdiffstore dstkey key1 key2 ... KeyN: Same as Sdiff, gets the element in the key1 that does not exist in the other key, but is stored in Dstkey.
SINTER key1 Key2 ... KeyN: Take out the intersection of these set
Sinterstore dstkey key1 Key2 ... KeyN: Takes out the intersection of these keys and stores them in Dstkey
Smove Srckey Dstkey Member: Transfer element member from Srckey to Dstkey, this operation is atomic.
-》-》-》
7. Ordered set sorted set
Same as set, unique. But Z has a score to sort. So the command is like list:
Zadd Key Score member: Adds the element member to the ordered set, where score is the fractional, default ascending;
zrange key start end [Withscores]: gets the elements from low to high index range by score, the index can be negative, 1 means the last, 2 means the penultimate, that is, from the back forward. Withscores Optional, which means to get included fractions.
zrevrange key start End [Withscores]: ditto, but score from high to low.
ZcountKey min Max: Gets the number of elements score in the Min and Max ranges
zcard key: Gets the number of elements in the collection.
Zincrby Key increment member: Score atoms add increment according to the element.
zremrangebyscore Key min Max: empties the element in the collection between Min and Max score.
Zrank Key member: Gets the index of the element (according to score from low to high).
Zrem Key member: Removes the element from the collection
Zscore Key member: Gets the score of the element
8. Object storage Hashes
Can store objects, such as people, numbers, names, ages, etc.
in the hash stored at key. Gets the number of attributes.
->->
Redis Basic Command Learning