Skip to content

Commit

Permalink
Add Python code sample for Cloud Functions + Memorystore for Re… (#2181)
Browse files Browse the repository at this point in the history
* Add Python code sample for Cloud Functions + Memorystore for Redis
  • Loading branch information
ericschmidtatwork authored and gguuss committed Jul 30, 2019
1 parent c9337cd commit 920b347
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions functions/memorystore/redis/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.

# [START functions_memorystore_redis]

import os
import redis

redis_host = os.environ.get('REDISHOST', 'localhost')
redis_port = int(os.environ.get('REDISPORT', 6379))
redis_client = redis.StrictRedis(host=redis_host, port=redis_port)


def visit_count(request):
value = redis_client.incr('visits', 1)
return 'Visit count: {}'.format(value)

# [END functions_memorystore_redis]
1 change: 1 addition & 0 deletions functions/memorystore/redis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redis==3.0.1

0 comments on commit 920b347

Please sign in to comment.