Last active
June 8, 2021 01:12
-
-
Save slorello89/5a86af8466d160e6c7cadf4e5133658f to your computer and use it in GitHub Desktop.
very simple redis streams example using Stackexchange.Redis,
This file contains 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; | |
using System.Threading.Tasks; | |
using StackExchange.Redis; | |
namespace StreamsExample | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
const string STREAM_NAME = "FOO"; | |
const string FIELD_NAME = "foo"; | |
const string FIELD_VALUE = "bar"; | |
const string HOST_NAME = "HOST_NAME"; | |
const string PORT_NUMBER = "PORT_NUMBER"; | |
const string PASSWORD = "PASSWORD"; | |
var redis = await ConnectionMultiplexer.ConnectAsync($"{HOST_NAME}:{PORT_NUMBER},password={PASSWORD}"); | |
var db = redis.GetDatabase(); | |
var response = await db.StreamAddAsync(STREAM_NAME, FIELD_NAME, FIELD_VALUE); | |
Console.WriteLine(response); | |
var readResponse = await db.StreamReadAsync(STREAM_NAME,"0"); | |
Console.WriteLine(readResponse[0]["foo"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment