码迷,mamicode.com
首页 > 编程语言 > 详细

pythonr操作redis-hash

时间:2016-04-18 09:53:27      阅读:174      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!