First,Several data structures:
1, String:key->value(1) Added: Set Key Value/setnx key value (not present when added, already exists return 0)/setex key time value (add and set valid times)/setrange key index value ( Replace the value corresponding to the key from the index position with value)/mset key1 value1 key2 value2 (set multiple values at one time, failure returns 0)/msetnx Key1 value1 key2 value2 (same previous, but not overwrite existing); (2) Get: Get Key/getset Key value (reset value and return old value)/getrange key index1 index2 (return key corresponding to value substring: index1 to Index2)/mget Key1 Key2 Key3 (get multiple values at once), (3) Add and Subtract: incr key (if the value of key is int type, plus one; if the value of key is a non-int type, an error is returned, if key is not present, the value of the key is 1, which is the original value of 0)/incrby key Number (the value of the key is added to, the other same as the previous)/DECR Key/decrby Key # (This is subtraction, the specification is the same as Incr/incrby); (4) String manipulation: Append key Val ( Append Val to the value corresponding to key)/strlen key (returns the length of the value corresponding to key)Note: The left subscript of the string starts at 0 and the right subscript starts at 1.
2, Hash:map, that is, each hash table has one or more key value pairs (1) Added: Hset myhash key value (add key value pair key->value to hash table Myhash)/hsetnx Myhash key value (same as hset, but not overwritten)/hmset Myhash Key1 Value1 key2 value2 (add multiple key-value pairs to the hash table Myhash), (2) Get: Hget Myhash key (Gets the value of key in the hash table Myhash)/hmget Myhash key1 Key2 Key3 ( Gets the value of multiple keys in the hash table Myhash)/hincrby myhash Key number (the value corresponding to key in the hash table Myhash plus number); (3) Other operations: Hexists Myhash Key ( Determine if a key exists in Myhash for key,0, 1 for/hlen Myhash (returns the number of Myhash keys)/hdel myhash key (delete key-value pair with key in Myhash)/hkeys Myhash ( Return all keys in Myhash)/hvals Myhash (return all values in Myhash)/hgetall Myhash (return all keys and values in Myhash)
3. List:
list that is strung by value(1) Added: Lpush mylist value (add value to MyList header)/rpush mylist value (add value to MyList tail)/linsert mylist before value1 value ( Insert value in front of value1 in mylist)/lset MyList index value (resets the value of index position in MyList to value) (2) gets: Lrange mylist index1 Index2 ( Get list index1 to Index2)/lindex MyList index (returns the value of MyList subscript index)/llen mylist (return mylist length) (3) Delete: Lrem mylist count Value (delete the element with value in |count| mylist, count>0: Delete from beginning to end, count<0: Delete from tail, count=0: Remove All)/ltrim mylist index1 Index2 ( Keep only index1 to Index2 range values)/lpop mylist (Delete mylist header and return)/rpop mylist (delete mylist tail and return)/rpoplpush Mylist1 Mylist2 ( Move the tail of the mylist1 to the Mylist2 's head)
4. Set: Set consisting of value(1) Added: Sadd myset value (2) gets: Smembers MySet (return MySet all values)/sdiff Myset1 Myset2 (returns the difference set of two set)/sdiffstore MySet Myset1 Myset2 ( The difference between Myset1 and Myset2 exists in MySet)/sinter Myset1 Myset2 (returns the intersection of two set)/sinterstore MySet Myset1 Myset2 ( The intersection of MYSET1 and Myset2 exists in MySet)/sunion Myset1 Myset2 (returns the two set's set)/sunionstore MySet Myset1 Myset2 ( Myset1 and Myset2 are present in MySet)/scard MySet (the number of elements that return MySet)/sismember MySet Value (tests whether value is an element in MySet, 1 is yes, 0 is no)/ Srandmember MySet (randomly returns an element in the MySet, but does not delete) (3) Delete: Srem MySet value (removes the element with value values)/spop myset (randomly deleting and returning an element in MySet)/smove Myset1 Myset2 Value (remove value from Myset1 and add to Myset2)
5. Sorted set (Zset): Set with sort(1) added: Zadd Myzset score Value (add value to Myzset,score for sorting, if value already exists, update its score) (2) Get: Zrange myzset index1 Index2 Withscores (returns the Myzset of the index1 to index2 elements and their score values, in score from small to large order)/zrank Myzset value (returns the rank of value in Myzset, counting from 0)/ Zrevrank Myzset Value (returns the reverse rank of value in Myzset, counting starting from 0)/zrevrange myzset index1 index2 withscores (Reverse of Zrange)/ Zrangebyscore Myzset a B withscores (returns the value of score in A to B range in Myzset and score)/zcount Myzset a B (returns the number of Myzset in score range of values from A to B)/zcard Myzset (returns the number of elements)/zscore Myzset value (returns the score value corresponding to value in Myzset) (3) Delete: Zrem myzset value (delete element with value in Myzset)/ Zremrangebyrank myzset index1 index2 (delete myzset rank score to index1 Element) Index2/zremrangebyscore a B ( Delete the element with score value between A and B in Myzset (4) plus minus Score:zincrby Myzset number value (score plus number for value)Second,Redis Common commands: 1. Keys pattern: Returns all key,pattern of the given pattern as regular expressions
2. Exists key: Determine if there is a key3. del key: Delete key4, Expire key time: Set the expiration of a key5. Move Key DB: Move a key to database DB6, TTL key: How long to return the key expires (1 means no expiration) 7, peisist key: Remove key Expiration Time 8, Randomkey: Randomly return to a key9, rename Oldkey Newkey: Rename Oldkey to Newkey10, type value: Returns the value of type 11, dbsize: Returns the key number of the current database 12, Flushdb: Deletes all key13 of the current database, Flushall: Delete all key14, info: Get server information and statistics 15, config get: Get server configuration informationthe database number for Ps:redis is 0-15, and the default is database 0.
Redis Learning Notes