Redis installation, syntax and Python connections

Source: Internet
Author: User
Tags install redis


Program Download http://down.51cto.com/data/2440789:


Click on the client to test the connection and the test is successful.


Grammar:

Redis's string manipulation set (Key,value,ex=none,px=none,nx=false,xx=false) sets the value in Redis, defaults, does not exist, creates, and then modifies parameters: Ex: Expiration Time (seconds) px:  Expiration time (milliseconds) NX: If set to true, only key does not exist. The current set does not execute XX: If set to true, the current set will execute the SETNX (key,value) setting value only if key is present, and the set Operation Setex (Key,value,time) is performed only if the key does not exist. Set value parameter: Time: Expiration unit is Seconds Psetex (key,value,time) Set value parameter: Time: Expiration unit is milliseconds Mset (*args,**kwargs) bulk set value such as: MSET K1 V1  k2 v2 or Mset (k1= ' v1 ', k2= ' v2 ') Getset (key,value) sets a new value and returns the original value GetRange (key,start,end) gets the subsequence (based on the bytes obtained, Non-character) parameter: Key: redis Keystart: Start position (bytes) end:   End position (bytes) such as: "Zhang San", 0-3 means "Zhang" setrange (Key,offset,value) Modifies the string contents. Replaces backward from the specified string index (when the new value is too long, it is added backwards) parameter:offset:  the index of the string, byte (three bytes of a kanji) value:   the value to set Setbit (Key,offset,value) Operation parameters for bits corresponding to the binary representation of key: Key:  redis Keyoffset: Index of the bit (the value becomes binary and then indexed) value:    The value can only be 0 or 1 cases: if there is a corresponding:n1 =  "foo" in Redis, then the binary representation of the string "foo" is: 01100110 01101111 01101111 if you execute Setbit (' N1 ', 7, 1) then the seventh bit will be set to 1 then the final binary becomes  01100111 01101111 01101111  "goo" Code implementation 127.0.0.1:6379>  set n1&nBsp;foook127.0.0.1:6379> setbit n1 7 1 (integer)  0127.0.0.1:6379> get  N1 "Goo" 127.0.0.1:6379> usefulness: such as QQ statistics online number, and see who online: let 1 Representative online. 0 for no line offset represents the user's ID if the user is online, set the ID to 1 with bitcount statistics How many 1, that is, how many users online with Getbit to see if the user online code implementation:127.0.0.1:6379>  Setbit qq 55 1 (integer)  0127.0.0.1:6379> setbit qq 1000 1 (integer)  0127.0.0.1:6379> BITCOUNT QQ (integer)  2127.0.0.1:6379> getbit qq 55 ( Integer)  1127.0.0.1:6379>  getbit qq 66 (integer)  0127.0.0.1:6379>append ( Key,value) append parameter after Redis,key corresponding value: Key:redis's keyvalue:  string example to append: 127.0.0.1:6379> get zhang "san" 127.0.0.1:6379> append zhang san (integer)  6127.0.0.1:6379> get zhang " SanSan "127.0.0.1:6379>del key Delete Keyhash if you need to save a class name and other information 127.0.0.1:6379> hset info key  duwentao (integer)  1127.0.0.1:6379> hset info age 20 (integer)  1127.0.0.1:6379> hset info id 1 (integer)  1127.0.0.1:6379>  HGETALL INFO1)   "key" 2)   "Duwentao" 3)   "age" 4)   "5"   "ID" 6)   "1" 127.0.0.1:6379 > hget info age "127.0.0.1:6379> hkeys info   #查看有多少key1)  " Key " 2)   "age" 3)   "id" 127.0.0.1:6379> hvals info  #查看有多少value1)   "Duwentao" 2)   "20 "3)  " 1 "HMSET KEY FIELD VALUE [FIELD VALUE  Usage:127.0.0.1:6379> hmset li k1 v1 k2 v2 k3 v3ok127.0.0.1:6379>  HGETALL LI1)   "K1" 2)   "V1" 3)   "K2" 4)   "V2" 5)   "K3" 6)   "V3" Hget key  field in the key corresponding to the hash obtained by key to get valuehmget key field [field  Usage: 127.0.0.1:6379> hmget li k1 k21)   "v1" 2)   "V2" Hlen (key) Get a few Keyhkeys (key) to get the key corresponding to the hash of all key values Hvals (key) Gets the key corresponding to the hash of all value values hexists key Field checks if the hash for key is present in the current incoming keyhincrby key field increment self-increment 127.0.0.1:6379> hincrby  info age 1 (integer)  21127.0.0.1:6379>  hincrby info age 1 ( Integer)  22hscan key cursor [match pattern] [count count] play a role in filtering such as    hscan info 0 match *a* list: Lpush (from the left) and Rpush (right-hand side) 127.0.0.1:6379> lpush  Keys1 zhangsan lisi wanger (integer)  3127.0.0.1:6379>  LRANGE keys1  0 -11)   "Wanger" 2)   "Lisi" 3)   "Zhangsan" 127.0.0.1:6379> rpush keys2  Zhangsan lizi wanger (integer)  3127.0.0.1:6379>  lrange keys2 0 -11)   "Zhangsan" 2)   "Lizi" 3)   "Wanger" 127.0.0.1:6379>lpushx key value add elements to the list of key When a key is already present, the value is added to the leftmost rpushx key value of the list, and the value is added to the right of the list when the key is already present, only to the rightmost llen  The number of Keykey corresponding to the list element linsert key before|After pivot value inserts a new value parameter before or after a value in the corresponding list of key:key:             redis's keybefore| after:    in what or after privot:          the benchmark value, that is, before and after he inserts the data value:            data to insert lset key index  Value is re-assigned to an index position in the list for key: Key:  redis's key value index:list the index position of value: Lrem key count  value delete the specified value parameter in the list of key: Key:redis KeyValue: The value to remove count:count=0:  Remove all the specified values from the list count=2:  from the front to the back, Delete Two count=-2: from back to front, delete two lpop key on the left side of the list of keys, gets the first element and removes it from the list, and the return value is the first element. Lindex key index in the corresponding list in key to get the list element according to the index lrange key start stop in the key corresponding list shard get data parameters: Key:   redis Keystart: The starting position of the index end:   the end of the index ltrim key start  Stop removes the value parameter that is not in the Start stop index for the list in key: Key:redis Keystart: The start of the index stop: the end position of the index rpoplpush source  Destination remove the rightmost element from one table and add it to the leftmost parameter of another list: source:      to remove the list of data keydestination: keybrpoplpush source destination  to add a list of data Timeout removes an element from the right side of a list and adds it to the left argument of another list: source: The keydestination of the list of elements to be inserted: the corresponding keytimeout for the list of elements to insert: when there is no data in the list of source , blocking waits for its data time-out (in seconds), 0 means forever blocked collection: sadd key member [member  Key corresponding to the collection of elements (no duplicates, unordered) such as:127.0.0.1:6379> sadd names3 zhangsan zhangsan lisi  Lisi 3 3 (integer)  3127.0.0.1:6379> SMEMBERS names3  #获取所有值1)   "3" 2)   " Lisi "3)  " Zhangsan "Scard key gets the number of elements in the set corresponding to the key sdiff key [key  Elements in the set corresponding to the first key and not in the corresponding set of other keys sdiffstore destination key [key  The elements in the set corresponding to the first key and not in the corresponding set of other keys, add him to the destination sinter key1 [key2]  returns the intersection of all the sets given sinterstore  destination key1 [key2]  returns the intersection of the given all sets and stores it in  destination  Sismember key member   Determines whether the  member  element is a collection  key  member smembers key  returns all members in the collection SMOVE SOURCe destination member  moves the  member  element from the  source  collection to the  destination  collection Spop  key  removes and returns a random element in the collection srandmember key [count]  returns one or more random numbers in the collection Srem key member1  [member2]  removes one or more members from the collection sunion key1 [key2]  returns the set of all the collections for the given collection sunionstore destination  key1 [key2]  the sscan key cursor [match  of all given collections is stored in the  destination  collection pattern] [count count]  an ordered set of elements in an iteration set:zadd key score1 member1 [score2  member2]  adds one or more members to an ordered collection, or updates the fraction of an existing member zcard key  gets the number of members of an ordered collection zcount key min  Max calculates the number of members that specify interval fractions in an ordered collection zincrby key increment member  the fraction of the specified member in an ordered set plus the increment   INCREMENTZINTERSTORE DESTINATION NUMKEYS KEY [KEY&NBSP, ...]   calculates the intersection of one or more ordered sets given and stores the result set in a new ordered collection  key  in zlexcount key min max  Calculates the number of members in a specified dictionary interval in an ordered set zrange key start stop [withscores]  returns an ordered set by an index intervalTo a member within a specified range zrangebylex key min max [limit offset count]  Returns the members of an ordered set through a dictionary zrangebyscore key min max [withscores] [limit]  Returns the index of the specified member in an ordered collection by returning the member zrank key member  of the ordered collection within the specified interval zrem key member [member  ...]   removes one or more members from an ordered collection zremrangebylex key min max  removes all members of the given dictionary interval in the ordered collection zremrangebyrank  key start stop  removes all members of a given rank range in an ordered collection zremrangebyscore key min max  Removes all members of a given fractional interval in an ordered collection zrevrange key start stop [withscores]  returns the members of the specified interval in an ordered set, by index, The score from the high end zrevrangebyscore key max min [withscores]  returns the members within the specified fractional interval of the ordered set, with fractions from high to low sorted zrevrank  key member  returns the rank of the specified member in an ordered set, with ordered set members descending by fractional value (from large to small) zscore key member  returns an ordered set. The member's score value zunionstore destination numkeys key [key    calculates the set of a given one or more ordered sets and stores them in the new  key  Zscan key cursor [match pattern] [count  count]  elements in an ordered set of iterations (including element members and element scores) 

Installing the Python module

PIP3 Install Redis


Python thread pool connects to Redis

General Connection Redis



Pipelines: Multiple commands can be executed at one time


Import Redispool = Redis. ConnectionPool (host= ' 127.0.0.1 ', port=6379) #连接池 #r = Redis. Redis (host= ' 127.0.0.1 ', port=6379) R = Redis. Redis (connection_pool=pool) pipe = R.pipeline (transaction=true) r.set (' foo ', ' Bar ') r.set (' Zhangsan ', ' Heheheh ') Pipe.execute ()


Public number


Redis installation, syntax and Python connections

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.