Last active
May 16, 2021 16:55
-
-
Save gistlyn/c2e4ac0ba376df9175df28895537d4dd to your computer and use it in GitHub Desktop.
ServiceStack.Redis TODOs
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
<NoWarn>1591</NoWarn> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="ServiceStack.Redis" Version="5.*" /> | |
</ItemGroup> | |
</Project> |
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 ServiceStack.Text; | |
using ServiceStack.Redis; | |
var redisManager = new RedisManagerPool("localhost:6379"); | |
var redis = redisManager.GetClient(); | |
var redisTodos = redis.As<Todo>(); | |
var newTodo = new Todo | |
{ | |
Id = redisTodos.GetNextSequence(), | |
Content = "Learn Redis", | |
Order = 1, | |
}; | |
redisTodos.Store(newTodo); | |
Todo savedTodo = redisTodos.GetById(newTodo.Id); | |
$"Saved Todo: {savedTodo.Dump()}".Print(); | |
savedTodo.Done = true; | |
redisTodos.Store(savedTodo); | |
var updatedTodo = redisTodos.GetById(newTodo.Id); | |
$"Updated Todo: {updatedTodo.Dump()}".Print(); | |
redisTodos.DeleteById(newTodo.Id); | |
var remainingTodos = redisTodos.GetAll(); | |
$"No more Todos: {remainingTodos.Dump()}".Print(); | |
public class Todo | |
{ | |
public long Id { get; set; } | |
public string Content { get; set; } | |
public int Order { get; set; } | |
public bool Done { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment