Looking for a simple and minimalistic way to store small data packets in the cloud

对着背影说爱祢 提交于 2019-12-05 20:36:34

OpenKeyval is pretty much what I was looking for.

OpenKeyval was what I was looking for but has apparently been shut down.

I think GAE will be nice choice. With your requirements for storage size you will never pass free 500 mb of GAE's store. And it will be easy to port your script across browsers because of REST nature of your service;)

I was asked to share my GAE key/value store solution, so here it comes. Note that this code hasn't run for years, so it might be wrong and/or very outdated GAE code:

app.yaml

application: myapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /
  script: keyvaluestore.py

keyvaluestore.py

from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class KeyValue(db.Model):
    v = db.StringProperty(required=True)

class KeyValueStore(webapp.RequestHandler):
    def _do_auth(self):
        user = users.get_current_user()
        if user:
            return user
        else:
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('login_needed|'+users.create_login_url(self.request.get('uri')))

    def get(self):
        user = self._do_auth()
        callback = self.request.get('jsonp_callback')
        if user:
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write(self._read_value(user.user_id()))

    def post(self):
        user = self._do_auth()
        if user:
            self._store_value(user.user_id(), self.request.body)

    def _read_value(self, key):
        result = db.get(db.Key.from_path("KeyValue", key))
        return result.v if result else 'none'

    def _store_value(self, k, v):
        kv = KeyValue(key_name = k, v = v)
        kv.put()

application = webapp.WSGIApplication([('/', KeyValueStore)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

The closest thing I've seen is Amazon's Simple Queue Service.
http://aws.amazon.com/sqs/

I've not used it myself so I'm not sure how the developer key aspect works, but they give you 100,000 free queries a month.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!