redis鍩烘湰鎿嶄綔

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis鍩烘湰鎿嶄綔相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/pre' title='pre'>pre   www.   timeout   rabbit   class   value   鏂规硶   als   turn   

鈥樷€樷€?
pip install redis

redis 鍙互鐪嬫垚鍐呭瓨涓殑澶у瓧鍏?

redis浜斿ぇ鏁版嵁绫诲瀷 --> 鎸囩殑鏄涓€灞傜殑value鍊肩殑绫诲瀷
    - 瀛楃涓?      "k1"
    - 鍒楄〃        [11,22,33锛?1]
    - 闆嗗悎        {11,22,33}
    - 瀛楀吀        {
                    鈥榢k1鈥?vv1,
                    鈥榢k2鈥?vv2,
                    鈥榢k3鈥?{}  杩欎釜value涓嶈兘鏄瓧鍏革紝濡傛灉鏈夐渶瑕侊紝鍒欓渶瑕佽浆鎹㈡垚瀛楃涓茬殑褰㈠紡銆?
                }
    - 鏈夊簭闆嗗悎      {(鈥榓lex鈥?4),(鈥榮tandby鈥?3),(鈥榚gon鈥?9)}
鈥樷€樷€?


import redis

conn = redis.Redis(host=鈥?0.0.0.2鈥?port=6379)

# 瀛楃涓?
conn.set(鈥榢1鈥?鈥榲1鈥?ex=10)
conn.get(鈥榢1鈥?


# 鍒楄〃
# 鍙互褰撴秷鎭槦鍒楁潵浣跨敤
conn.lpush(鈥榰sers鈥?鈥榓lex鈥?
conn.rpush(鈥榰sers鈥?鈥榚ric鈥?
conn.lpop(鈥榰sers鈥?
conn.rpop(鈥榰sers鈥?

# 鍙屽悜闃熷垪锛屽彲浠ang浣忥紝鍙互妯℃嫙鏍堝拰闃熷垪锛? 鐖櫕锛岀埇缃戦〉-骞垮害浼樺厛鍜屾繁搴︿紭鍏?
conn.blpop(鈥榰sers鈥?timeout=10)
conn.brpop(鈥榰sers鈥?timeout=10)

conn.expire(鈥榢ey鈥?鈥樿秴鏃舵椂闂粹€?


count = conn.llen(鈥榰sers鈥?
print(count)

vals = conn.lrange(鈥榰sers鈥?0,10)
print(vals)


# redis閽堝鍒楄〃绫诲瀷锛屾病鏈夋彁渚?iter 鏂规硶锛岄渶瑕佽嚜宸卞疄鐜?
def list_scan_iter(key):
    # count = conn.llen(key)
    start = 0
    step = 3
    while True:
        vals = conn.lrange(key,start,start+step)
        start = start + step + 1
        if not vals:
            return
        for val in vals:
            yield val

result = list_scan_iter(鈥榰sers鈥?
for item in result:
    print(item)



# 闆嗗悎


# 鍝堝笇


# 鏈夊簭缁撳悎

銆€銆€

鍙傝€冿細Python鎿嶄綔 RabbitMQ銆丷edis銆丮emcache銆丼QLAlchemy

 

以上是关于redis鍩烘湰鎿嶄綔的主要内容,如果未能解决你的问题,请参考以下文章

鍗曢摼琛ㄧ殑鍩烘湰鎿嶄綔

openpyxl鎿嶄綔excel琛ㄦ牸

DBHelper连接数据库

缁忓吀鎺掑簭绠楁硶鈥斺€旈€夋嫨鎺掑簭

odl v2