BuildFeed/Tools/RedisMongoMigration/Redis/MetaItem.cs

51 lines
1.1 KiB
C#
Raw Normal View History

2015-08-05 19:28:16 +08:00
using NServiceKit.DataAnnotations;
using NServiceKit.DesignPatterns.Model;
2015-10-14 03:24:39 +08:00
using NServiceKit.Redis;
2015-08-05 19:28:16 +08:00
using System;
2015-10-14 03:24:39 +08:00
using System.Collections.Generic;
2015-08-05 19:28:16 +08:00
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace RedisMongoMigration.Redis
{
2015-10-14 03:24:39 +08:00
[DataObject]
public class MetaItem : IHasId<MetaItemKey>
{
[Key]
[Index]
public MetaItemKey Id { get; set; }
public string PageContent { get; set; }
public string MetaDescription { get; set; }
public static IEnumerable<MetaItem> Select()
{
using (RedisClient rClient = new RedisClient("localhost", 6379, db: 1))
{
var client = rClient.As<MetaItem>();
return client.GetAll();
}
}
}
public struct MetaItemKey
{
public string Value { get; set; }
public MetaType Type { get; set; }
public MetaItemKey(string id)
{
var items = id.Split(':');
Type = (MetaType)Enum.Parse(typeof(MetaType), items[0]);
Value = items[1];
}
public override string ToString()
{
return $"{Type}:{Value}";
}
}
2015-08-05 19:28:16 +08:00
}