def setKey(keyName, keyValue): # get existing key apiKey = ApiKeys.query(ApiKeys.keyName == keyName).get() # update existing keyName if apiKey: apiKey.keyName = keyName apiKey.keyValue = keyValue # create new key else: apiKey = ApiKeys( keyName=keyName, keyValue=keyValue ) apiKey.put() # save to memcache if not memcache.add(keyName, keyValue): # update memcache memcache.set(key=keyName, value=keyValue) return 'keyName=%s keyValue=%s' % (keyName, keyValue)
def set_key(name, value): # get existing key apiKey = ApiKeys.query(ApiKeys.name == name).get() # update existing name if apiKey: apiKey.name = name apiKey.value = value # create new key else: apiKey = ApiKeys( name=name, value=value ) apiKey.put() # save to memcache if not memcache.add(name, value): # update memcache memcache.set(key=name, value=value) return 'name=%s value=%s' % (name, value)
def getKey(keyName): # find key in memcache apiKey = memcache.get(keyName) # key not found in memcache if not apiKey: # fetch from ApiKeys table apiKeyRecord = ApiKeys.query(ApiKeys.keyName == keyName).get() if apiKeyRecord: # save to memcache if not memcache.add(apiKeyRecord.keyName, apiKeyRecord.keyValue): logging.error('memcache set failed') apiKey = apiKeyRecord.keyValue return str(apiKey)
def get_key(name): # find key in memcache apiKey = memcache.get(name) # key not found in memcache if not apiKey: # fetch from ApiKeys table apiKeyRecord = ApiKeys.query(ApiKeys.name == name).get() if apiKeyRecord: # save to memcache if not memcache.add(apiKeyRecord.name, apiKeyRecord.value): logging.error('memcache set failed') apiKey = apiKeyRecord.value return str(apiKey)
def set_key(name, value): # get existing key apiKey = ApiKeys.query(ApiKeys.name == name).get() # update existing name if apiKey: apiKey.name = name apiKey.value = value # create new key else: apiKey = ApiKeys(name=name, value=value) apiKey.put() # save to memcache if not memcache.add(name, value): # update memcache memcache.set(key=name, value=value) return 'name=%s value=%s' % (name, value)