首页 > 代码库 > python 链接codis 报错解决办法 command 'EXEC' is not allowed

python 链接codis 报错解决办法 command 'EXEC' is not allowed

[root@fast-node-652 ceph]# python ../pkg/redisbase.py
Traceback (most recent call last):
  File "../pkg/redisbase.py", line 85, in redis_hget
    values = self.pipe.execute()
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2578, in execute
    return execute(conn, stack, raise_on_error)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2470, in _execute_transaction
    response = self.parse_response(connection, ‘_‘)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2536, in parse_response
    self, connection, command_name, **options)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 577, in parse_response
    response = connection.read_response()
  File "/usr/lib/python2.7/site-packages/redis/connection.py", line 574, in read_response
    raise response
ResponseError: handle request, command ‘EXEC‘ is not allowed

m6
[root@fast-node-652 ceph]# python ../pkg/redisbase.py
Traceback (most recent call last):
  File "../pkg/redisbase.py", line 85, in redis_hget
    values = self.pipe.execute()
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2578, in execute
    return execute(conn, stack, raise_on_error)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2470, in _execute_transaction
    response = self.parse_response(connection, ‘_‘)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 2536, in parse_response
    self, connection, command_name, **options)
  File "/usr/lib/python2.7/site-packages/redis/client.py", line 577, in parse_response
    response = connection.read_response()
  File "/usr/lib/python2.7/site-packages/redis/connection.py", line 574, in read_response
    raise response
ResponseError: handle request, command ‘EXEC‘ is not allowed


解决办法:

self.pipe = self.conn.pipeline(transaction=False)


整行代码上贴

#!/usr/bin/env python
#-*-coding:UTF-8-*-
"""
@Item   :  cheetah v1.0
@Author :  william
@Group  :  XXX XXX
@Date   :  2017-03-15
@E-mail :  
@Funtion:
        redis_set : Redis in the form of pipe insert data, json hash as a string print
        redis_get : Redis inprintion, and json string into the original print
"""


import sys,os,time,redis,traceback,json
sys.path.append("/data/cheetah/")
reload(sys)
sys.setdefaultencoding("utf8")

from pkg import log
from pkg import config
LOG = log.get_logger(__name__)
cfg = config
RedisCONF = cfg.load_cfg()["redis"]

 
class RedisBase(object):
    ‘‘‘ Establish redis session connection pool ‘‘‘
    def __init__ (self):
        self.host = RedisCONF[‘host‘]
        self.port = RedisCONF[‘port‘]
        self.db = RedisCONF[‘db‘]
        try:
            pool = redis.ConnectionPool(host = self.host, port = self.port, db = self.db)
            self.conn  = redis.Redis(connection_pool=pool)
            self.pipe = self.conn.pipeline(transaction=False)
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()

    def redis_set(self,keys=None ,values=None):
        ‘‘‘ Insert redis databases,keys = key ,values = value‘‘‘
        try:
            self.pipe.set(keys,json.dumps(values))
            self.pipe.execute()
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()

    #add by william, for hash set
    def redis_hset(self,field, key,values ):
        ‘‘‘insert redis key, field ,values‘‘‘
        try:
            self.pipe.hset(field,key, json.dumps(values))
            self.pipe.execute()
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()

    #add by william, for hash set and add expire
    def redis_set_expire(self, key,values ):
        ‘‘‘insert redis key, field ,values‘‘‘
        try:
            self.pipe.set(key,json.dumps(values))
            self.pipe.expire(key,604800)
            self.pipe.execute()
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()


    #add by william, get from hash
    def redis_hget(self, key, field = None):
        ‘‘‘get by key, return the dict‘‘‘
        try:
            fields = []
            if field:
                fields.append(field)
            else:
                fields = self.conn.hkeys(key)
            for f in fields:
                self.pipe.hget(key, f)
            values = self.pipe.execute()
            values = [json.loads(i) for i in values]
            return dict(zip(fields, values))
        except:
            print traceback.format_exc()
            return key

    def redis_get(self,argv):
        ‘‘‘ Getting single KYES values ,argv : is keys‘‘‘
        try:
            self.pipe.get(argv)
            return json.loads( self.pipe.execute()[0])
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()

    def redis_getkeys(self):
        ‘‘‘ Getting all keys ‘‘‘
        try:
            self.pipe.keys(‘*‘)
            return self.pipe.execute()[0]
        except:
            LOG.error(traceback.print_exc())
            return traceback.print_exc()

    def redis_delete(self,keys):
        try:
            self.pipe.delete(keys)
            self.pipe.execute()
            return ‘Delete True‘
        except:
            LOG.error(traceback.print_exc())
            return ‘Delete False‘


if __name__ == "__main__":
    sc = RedisBase()
    bs = sc.redis_hget(‘m6‘)


    for x,y in bs.items():
        for a,b in y.items():
            if a == ‘ceph_df‘:
                print b


本文出自 “欢迎评论,欢迎点赞” 博客,请务必保留此出处http://swq499809608.blog.51cto.com/797714/1934394

python 链接codis 报错解决办法 command 'EXEC' is not allowed