Пример #1
0
 def __call__(self, *key):
     mk = self.mc_key % '_'.join(map(str, key))
     num = mc.get(mk)
     if num is None:
         #print "self.get_num", key, self.get_num(*key)
         num = self.get_num(*key) or 0
         mc.set(mk, num, self.timeout)
     return num
Пример #2
0
 def get_dict(self, keys):
     mc_key = self.mc_key
     mc_key_list = dict([(key, mc_key%key) for key in keys])
     result = mc.get_dict(mc_key_list.itervalues())
     r = {}
     for k, mck in mc_key_list.iteritems():
         v = result.get(mck)
         if v is None:
             v = self.get_num(k) or 0
             mc.set(mck, v)
         r[k] = v
     return r
Пример #3
0
 def set(self, id, value):
     r = self.get(id)
     if r != value:
         mc_key = self.__mc_id__ % id
         cursor = self.cursor
         table = self.__table__
         cursor.execute(
             'insert into %s (id,value) values (%%s,%%s) on duplicate key update value=values(value)'
             % table, (id, value))
         cursor.connection.commit()
         if value is None:
             value = False
         mc.set(mc_key, value)
Пример #4
0
 def set(self, id, value):
     r = self.get(id)
     if r != value:
         mc_key = self.__mc_id__ % id
         cursor = self.cursor
         table = self.__table__
         cursor.execute(
             'insert into %s (id,value) values (%%s,%%s) on duplicate key update value=values(value)' % table,
             (id, value)
         )
         cursor.connection.commit()
         if value is None:
             value = False
         mc.set(mc_key, value)
Пример #5
0
 def get(self, id):
     mc_key = self.__mc_id__ % id
     r = mc.get(mc_key)
     if r is None:
         cursor = self.cursor
         cursor.execute(
             'select value from %s where id=%%s' % self.__table__, id)
         r = cursor.fetchone()
         if r:
             r = r[0]
         if r is None:
             r = self.NULL
         mc.set(mc_key, r)
     return r
Пример #6
0
 def get(self, id):
     mc_key = self.__mc_id__ % id
     r = mc.get(mc_key)
     if r is None:
         cursor = self.cursor
         cursor.execute(
             'select value from %s where id=%%s' % self.__table__, id)
         r = cursor.fetchone()
         if r:
             r = r[0]
         if r is None:
             r = self.NULL
         mc.set(mc_key, r)
     return r
Пример #7
0
 def set(self, key, value, expire=0):
     key = self.key_pattern%key
     if type(value) is not array:
         value = pack(self.type*len(value), *value)
     else:
         value = value.tostring()
     return mc.set(key, value, expire)
Пример #8
0
 def set(self, key, value):
     mk = self.mc_key % key
     mc.set(mk, value)
Пример #9
0
 def set(self, key, value, expire=0):
     return mc.set(self.key_pattern%key, value, expire)