Python link Codis Error Resolution command ' EXEC ' is not allowed

Source: Internet
Author: User

Tag: Command ' EXEC ' is not allowed   python   redis   codis    

[[email protected] ceph]# python .. /pkg/redisbase.pytraceback  (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 responseResponseError: handle request, command  ' EXEC '  is  NOT ALLOWEDM6[[EMAIL PROTECTED] CEPH]# PYTHON&NBSP, .... /pkg/redisbase.pytraceback  (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 responseresponseerror: handle request, command  ' EXEC '  is not allowed


Workaround:

Self.pipe = Self.conn.pipeline (transaction=false)


Paste the entire line of code

#!/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,jsonsys.path.append ("/data/cheetah/") reload (SYS) sys.setdefaultencoding ("UTF8") from  pkg import logfrom pkg import configlog = log.get_logger (__name__) cfg  = configredisconf = 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:          &nbsP;  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 '     &nbsP;   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 =&nbsp []            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


This article from "Welcome comments, Welcome to like" blog, please be sure to keep this source http://swq499809608.blog.51cto.com/797714/1934394

Python link Codis Error Resolution command ' EXEC ' is not allowed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.