Skip to content

Instantly share code, notes, and snippets.

@gistlyn

gistlyn/main.cs

Last active Nov 10, 2020
Embed
What would you like to do?
Redis Todo demo
using System;
using ServiceStack;
using ServiceStack.Text;
using ServiceStack.Redis;
using ServiceStack.DataAnnotations;
var redisManager = new RedisManagerPool("localhost:6379");
var redis = redisManager.GetClient();
public class Todo
{
public long Id { get; set; }
public string Content { get; set; }
public int Order { get; set; }
public bool Done { get; set; }
}
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: {0}".Print(savedTodo.Dump());
savedTodo.Done = true;
redisTodos.Store(savedTodo);
var updatedTodo = redisTodos.GetById(newTodo.Id);
"Updated Todo: {0}".Print(updatedTodo.Dump());
redisTodos.DeleteById(newTodo.Id);
var remainingTodos = redisTodos.GetAll();
"No more Todos:".Print(remainingTodos.Dump());
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Memory" version="4.5.4" targetFramework="net45" />
<package id="ServiceStack.Text" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Client" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Common" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="5.10.0" targetFramework="net45" />
<package id="ServiceStack.Redis" version="5.10.0" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment