title: How to delete a particular key(for current session) from Flask-KVSession?
body: <p>I am using Flask kvsession to avoid replay attacks, as the client side cookie based session used by Flask-login are prone to it.
  Eg: If on /index page your cookie in the header is set for your app header like 
  myapp_session : 'value1'
  and if you navigate to /important page you will get a new header like 
  myapp_session : 'value2' so if a hacker gets 'value1' he can perform replay attacks and misuse it, as it is never invalidated.</p>
  
  <p>To solve this I am using flask-kvsession which stores the session cookie header value in a cache or some backend. SO basically only one myapp_session is generated and invalidated when you logout. But the problem is :-</p>
  
  <pre><code>__init__.py 
  
  from simplekv.memory.redisstore import RedisStore
  import redis
  
  store = RedisStore(redis.StrictRedis())
  #store = memcache.Client(['127.0.0.1:11211'], debug =0)
  store.ttl_support = True
  app = create_app(__name__)
  current_kvsession = KVSessionExtension(store, app)
  </code></pre>
  
  <p>If you look at the cleanup_session part of the code for kv-session
  <a href="http://pythonhosted.org/Flask-KVSession/#flask_kvsession.KVSessionExtension.cleanup_sessions" rel="nofollow">http://pythonhosted.org/Flask-KVSession/#flask_kvsession.KVSessionExtension.cleanup_sessions</a></p>
  
  <p>It only deletes the expired sessions. But If I want to explicitly delete the value for the current myapp_session for a particular user on logout, how do I do that?</p>
  
  <pre><code>@app.before_request
  def redirect_if_logout():
    if request.path == url_for('logout'):
        for key in app.kvsession_store.keys():
          logger.debug(key)
          m = current_kvsession.key_regex.match(key)
          logger.debug('found %s', m)
          app.kvsession_store.delete(key)
  </code></pre>
  
  <p>But this deletes all the keys as I don`t know what the unique key for the current session is. </p>
  
  <p>Q2. Also, how to use memcache instead of redis as it doesn`t have the  app.kvsession_store.keys() function and gives i/o error.</p>