Ejemplo n.º 1
0
def memcache():
    global _mcclient
    if _mcclient is None:
        _mcclient = MemcacheClient(('127.0.0.1', 11211), no_delay=True,
                                   default_noreply=False)
    return _mcclient
Ejemplo n.º 2
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from flask import Flask
from pymemcache.client.base import Client as MemcacheClient

app = Flask(__name__)

# [START client]
memcache_addr = os.environ.get('MEMCACHE_PORT_11211_TCP_ADDR', 'localhost')
memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', 11211)
memcache_client = MemcacheClient((memcache_addr, int(memcache_port)))
# [END client]


# [START example]
@app.route('/')
def index():

    # Set initial value if necessary
    if not memcache_client.get('counter'):
        memcache_client.set('counter', 0)

    value = memcache_client.incr('counter', 1)

    return 'Value is {}'.format(value)
Ejemplo n.º 3
0
from sqlalchemy import and_, text
import urllib.request
import maidenhead
from pymemcache.client.base import Client as MemcacheClient
import re

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://%s:%s@%s:5432/%s' % (
    os.getenv("DB_USER"), os.getenv("DB_PASSWORD"), os.getenv("DB_HOST"),
    os.getenv("DB_NAME"))

# Order matters: Initialize SQLAlchemy before Marshmallow
db = SQLAlchemy(app)
ma = Marshmallow(app)

memcache = MemcacheClient('127.0.0.1', ignore_exc=True, no_delay=True)

#Declare models


class Station(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    code = db.Column(db.String, unique=True)
    longitude = db.Column(db.Text)
    latitude = db.Column(db.Text)
    use_for_essn = db.Column(db.Boolean)
    use_for_maps = db.Column(db.Boolean)
    measurements = db.relationship('Measurement', backref='station')

    def __repr__(self):
Ejemplo n.º 4
0
        pass

    web3_client.personal.unlockAccount(OWNER_ADDRESS, OWNER_PASSPHRASE)
    web3_client.eth.defaultAccount = OWNER_ADDRESS

    trade_class = web3_client.eth.contract(abi=TRADE_ABI)
    trade_contract = trade_class(TRADE_ADDRESS)

    for start in xrange(0, len(sell_list), 5):
        sell_set = []
        for i in xrange(0, 5):
            if start + i < len(sell_list):
                sell_set.append(sell_list[start + i])
            else:
                sell_set.append({
                    'monster_id': 0,
                    'selling_price': 0
                })
        trade_contract.transact().addSellItem(
            sell_set[0]['monster_id'], sell_set[0]['selling_price'],
            sell_set[1]['monster_id'], sell_set[1]['selling_price'],
            sell_set[2]['monster_id'], sell_set[2]['selling_price'],
            sell_set[3]['monster_id'], sell_set[3]['selling_price'],
            sell_set[4]['monster_id'], sell_set[4]['selling_price'],
        )
  

if __name__ == "__main__":
  if memcache_client is None:
    memcache_client = MemcacheClient(('localhost', 11211))
  migrate_trade()
Ejemplo n.º 5
0
def get_memcache_client():
    memcache_addr = os.environ.get('MEMCACHE_PORT_11211_TCP_ADDR', 'localhost')
    memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', 11211)
    return MemcacheClient((memcache_addr, int(memcache_port)),
                          serializer=json_serializer,
                          deserializer=json_deserializer)