Created
May 1, 2017 07:49
-
-
Save bcnzer/6530b7b31500b3727c8003cb73c332d9 to your computer and use it in GitHub Desktop.
Sample Azure Function calling the Redis cache we configured
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
using StackExchange.Redis; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
// **** REDIS CODE STARTS HERE | |
var connString = System.Configuration.ConfigurationManager.ConnectionStrings["mycats"].ConnectionString; | |
var redis = ConnectionMultiplexer.Connect(connString); | |
// TODO - insert your code here to manipulate data in your Redis cache | |
// parse query parameter | |
string name = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0) | |
.Value; | |
// Get request body | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
// Set name to query string or body data | |
name = name ?? data?.name; | |
return name == null | |
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body") | |
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In VS2017 with the functional app, it's throwing exception:
Error Message: No connection is available to service this operation: SADD 1b4490c0-55f4-400c-b4f6-869ddb2664eb; Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.; IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=2,Free=1021,Min=8,Max=1023), Local-CPU: n/a
Stack: No connection is available to service this operation: SADD 1b4490c0-55f4-400c-b4f6-869ddb2664eb; Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.; IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=2,Free=1021,Min=8,Max=1023), Local-CPU: n/a
Inner Exception level 1
Message: SocketFailure on timetrialdev.redis.cache.windows.net:6379/Subscription, Initializing, last: NONE, origin: ConnectedAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, unanswered-write: 892907s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.505.18761
Stack:
Inner Exception level 2
Message: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Stack:
at System.IO.Pipelines.PipeCompletion.AddCallback(Action
2 callback, Object state) at System.IO.Pipelines.Pipe.OnReaderCompleted(Action
2 callback, Object state)at System.IO.Pipelines.Pipe.DefaultPipeWriter.OnReaderCompleted(Action`2 callback, Object state)
at Pipelines.Sockets.Unofficial.SocketConnection..ctor(Socket socket, PipeOptions sendPipeOptions, PipeOptions receivePipeOptions, SocketConnectionOptions socketConnectionOptions, String name)
at StackExchange.Redis.PhysicalConnection.d__98.MoveNext()