程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Introduction to redis and using redis in Python

編輯:Python

( One )Redis Use

(1) Sign in redis:win+r,cmd, Input redis-cli( The following content indicates that the link is successful )(2) Locate the database :select Data can be numbered ,eg. select 1 ( Switch to db 1 This database )

( Two )Redis Basic knowledge explanation

(1) data type String numbers are special strings (String); Hash Dictionary (Hash); An ordered list is equivalent to Python Medium List(List); unordered set (Set); Ordered set (Zset)(2)Redis Common commands String The object operation ------ lookup :key[pattern]; Delete :del[key]; Check for presence :exists[key]; View key type :type[key]; Set the value :set key value; Value :get keyHash The object operation ------ Set the value :hset key field( key ) value( value ); Value :hget key fieldList The object operation ------ Insert... On the left :Ipush key value; Insert on the right :rpush key value; Set according to the index :Iset key index value; Left stack :Ipop key; Right out of the stack :Rpop keyset The object operation ( disorder , Can't repeat ): add to :sadd key member; Delete specified member:srem key member; see key All of the member:smembers key; Stack randomly count individual member:spop key count; Random check count individual member:srandmember key count; see key in member The number of :scard key;Zset The object operation :( Ordered set ; One key There will not be two identical member; Every member Corresponds to a unique score The weight , Do not put the high weight ahead of the low weight ; With the same weight member, Press the first insert on the left , The rear insert is on the right ; Default to heavy ) add to member and score:zadd key [score member]; Delete member:zrem key [member]; Delete by sort :zremrangebyrank key start stop; according to score Scope delete :zremrangebyscore key min max;

( 3、 ... and ) adopt python operation Redis database

(1) install redis modular :pip install redis;(2) Guide pack :import redis(3) establish Redis link :conn = redis.StrictRedis(host = "localhost",port = 6379,password = "",decode_response = True,)(4) perform Redis sentence :ret = conn.execyte_command("Redis sentence ")
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved