python3.x操作redis

python3.x操作redis

1、安转redis;pip install redis;

2、redis文档:http://redis-py.readthedocs.io/en/latest/

下面为redis库的接口封装:

import redis
import configparser

CONFIG = configparser.ConfigParser()
CONFIG.read("config/system.ini")
redis_host = CONFIG.get("redis", "REDIS_HOST")
redis_port = CONFIG.get("redis","REDIS_PORT")
redis_db=CONFIG.get("redis","REDIS_DB")
redis_pwd=CONFIG.get("redis","REDIS_PASSWORD")

redisConnect = redis.Redis(redis_host,redis_port,redis_db,redis_pwd)

class RedisTool:


	@staticmethod
	def hexists(name,key):
		return redisConnect.hexists(name,key)

	@staticmethod
	def hget(name, key):
		return redisConnect.hget(name, key)

	@staticmethod
	def getset(name, value):
		return redisConnect.getset(name, value)

	@staticmethod
	def hdel(name, *keys):
		return redisConnect.hdel(name, *keys)

	@staticmethod
	def hgetall(name):
		return redisConnect.hgetall(name)

	@staticmethod
	def hkeys(name):
		return redisConnect.hkeys(name)

	@staticmethod
	def hlen(name):
		return redisConnect.hlen(name)

	#Set key to value within hash name Returns 1 if HSET created a new field, otherwise 0
	@staticmethod
	def hset(name, key, value):
		return redisConnect.hset(name, key, value)

	@staticmethod
	def setex(name, time, value):
		return redisConnect.setex(name, time, value)

	@staticmethod
	def get(name):
		return redisConnect.get(name)

	@staticmethod
	def exists(name):
		return redisConnect.exists(name)
		
	@staticmethod
	def set(name, value):
		return redisConnect.set(name, value)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值