首页 > 编程语言 > 详细

pythonr操作redis-hash

时间:2016-04-18 09:53:10      阅读:145      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/python
#!coding: utf-8

import redis



if __name__=="__main__":
    try:
        conn=redis.StrictRedis(host=192.168.80.128,port=6379,db=0)
        print(conn.ping())

        conn.hset(persons:001,name,jiangle)
            #让hash表persons:001的name关键字(key)关联到一个值‘jiangle’

        name=conn.hget(persons:001,name)
        print(name)
            #取出hash表persons:001的name关键字所关联的值

        print(conn.hgetall(persons:001))
            #取得hash表persons:001中所有的键值

        print(conn.hexists(persons:001,name))
            #判断hash表persons:001是否存在name这个键

        print(conn.hget(persons:001,age))
        conn.hincrby(persons:001,age,2)
        print(conn.hget(persons:001,age))
            #自增

        conn.hdel(persons:001,age)
        print(conn.hkeys(persons:001))
            #删除键
    except Exception as err:
        print(err)

 

pythonr操作redis-hash

原文:http://www.cnblogs.com/JiangLe/p/5403276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!