Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkong828 committed Dec 26, 2018
1 parent b57e725 commit faffb43
Show file tree
Hide file tree
Showing 65 changed files with 26,853 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/Banana.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banana", "Banana\Banana.csproj", "{EA01AC67-AA6D-40D5-957D-85B1F8057472}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Banana", "Banana\Banana.csproj", "{EA01AC67-AA6D-40D5-957D-85B1F8057472}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 1 addition & 0 deletions src/Banana/Banana.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.0.30" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
<PackageReference Include="MongoDB.Driver" Version="2.7.2" />
Expand Down
14 changes: 8 additions & 6 deletions src/Banana/Core/VideoCommonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public class VideoCommonService
public static Dictionary<string, List<string>> _classifyDic;
static VideoCommonService()
{
_classifyDic = new Dictionary<string, List<string>>();
_classifyDic.Add("电影", new List<string>() { "动作片", "喜剧片", "爱情片", "科幻片", "恐怖片", "剧情片", "战争片", "纪录片" });
_classifyDic.Add("电视剧", new List<string>() { "国产剧", "港剧", "日剧", "欧美剧", "韩剧", "台剧", "泰剧", "越南剧" });
_classifyDic.Add("综艺", new List<string>() { "综艺" });
_classifyDic.Add("动漫", new List<string>() { "动漫" });
_classifyDic.Add("伦理", new List<string>() { "伦理片", "美女写真", "美女视频", "韩国主播VIP视频" });
_classifyDic = new Dictionary<string, List<string>>
{
{ "电影", new List<string>() { "动作片", "喜剧片", "爱情片", "科幻片", "恐怖片", "剧情片", "战争片", "纪录片" } },
{ "电视剧", new List<string>() { "国产剧", "港剧", "日剧", "欧美剧", "韩剧", "台剧", "泰剧", "越南剧" } },
{ "综艺", new List<string>() { "综艺" } },
{ "动漫", new List<string>() { "动漫" } },
{ "伦理", new List<string>() { "伦理片", "美女写真", "美女视频", "韩国主播VIP视频" } }
};
}
public static string GetVideoRealClassify(string classify,out string type)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Banana/Services/Redis/IRedisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public interface IRedisService
T Get<T>(string key);


bool Set(string key, string data, int cacheTime = 0);

bool Set<T>(string key, T data, int cacheTime = 0);

bool Set(string key, object data, int cacheTime = 0);

bool IsExist(string key);

Expand Down
99 changes: 20 additions & 79 deletions src/Banana/Services/Redis/RedisService.cs
Original file line number Diff line number Diff line change
@@ -1,133 +1,74 @@
using Banana.Helper;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using CSRedis;
using System.Collections.Generic;

namespace Banana.Services
{
public class RedisService : IRedisService
{
private readonly IConfiguration _configInfos;
private readonly IDatabase _database;
private readonly CSRedisClient _client;

private readonly string DefaultKey;
public RedisService(IConfiguration config)
public RedisService(CSRedisClient client)
{
_configInfos = config;
_database = RedisHelper.GetDateBase();

DefaultKey = _configInfos["Redis:DefaultKey"];
}

#region Private

private string AddKeyPrefix(string key)
{
return $"{DefaultKey}:{key}";
}

private string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj);
}

private T Deserialize<T>(string json)
{
if (json == null)
return default(T);
return JsonConvert.DeserializeObject<T>(json);
_client = client;
}


#endregion

public string Get(string key)
{
key = AddKeyPrefix(key);
return _database.StringGet(key);
return _client.Get(key);
}

public T Get<T>(string key)
{
key = AddKeyPrefix(key);
var s = _database.StringGet(key);
return Deserialize<T>(s);
return _client.Get<T>(key);
}

public bool IsExist(string key)
{
key = AddKeyPrefix(key);
return _database.KeyExists(key);
}

public bool Set(string key, string data, int cacheTime = 0)
{
key = AddKeyPrefix(key);
TimeSpan? expiry = null;
if (cacheTime > 0)
expiry = TimeSpan.FromMinutes(cacheTime);
return _database.StringSet(key, data, expiry);
return _client.Exists(key);
}

public bool Set<T>(string key, T data, int cacheTime = 0)
public bool Set(string key, object data, int cacheTime = 0)
{
if (data == null)
return false;
key = AddKeyPrefix(key);
TimeSpan? expiry = null;
var expiry = -1;
if (cacheTime > 0)
expiry = TimeSpan.FromMinutes(cacheTime);
var sdata = Serialize(data);
return _database.StringSet(key, sdata, expiry);
expiry = cacheTime * 60;
return _client.Set(key, data, expiry);
}


public bool SortedSetIncrement(string key, string member, double score, int cacheTime = 0)
{
key = AddKeyPrefix(key);
_database.SortedSetIncrement(key, member, score);
_client.ZIncrBy(key, member, score);
if (cacheTime > 0)
{
TimeSpan expiry = TimeSpan.FromMinutes(cacheTime);
return _database.KeyExpire(key, expiry);
var expiry = cacheTime * 60;
return _client.Expire(key, expiry);
}
return true;
}

public double? SortedSetScore(string key, string member)
{
key = AddKeyPrefix(key);
return _database.SortedSetScore(key, member);
return _client.ZScore(key, member);
}


public List<KeyValuePair<string, double>> SortedSetRangeByRankWithScores(string key, int pageindex, int pagesize)
{
var range = _client.ZRevRangeWithScores(key, (pageindex - 1) * pagesize, pageindex * pagesize - 1);
var result = new List<KeyValuePair<string, double>>();
key = AddKeyPrefix(key);
var range = _database.SortedSetRangeByRankWithScores(key, (pageindex - 1) * pagesize, pageindex * pagesize - 1, Order.Descending);
foreach (var item in range)
{
result.Add(new KeyValuePair<string, double>(item.Element, item.Score));
result.Add(new KeyValuePair<string, double>(item.member, item.score));
}
return result;
}

public long SortedSetCombineAndStore(string destinationKey, List<string> keys, int cacheTime = 0)
{
destinationKey = AddKeyPrefix(destinationKey);
var combineKeys = new List<RedisKey>();
keys.ForEach(key =>
{
combineKeys.Add(AddKeyPrefix(key));
});
var num = _database.SortedSetCombineAndStore(SetOperation.Union, destinationKey, combineKeys.ToArray());
var num = _client.ZUnionStore(destinationKey, null, RedisAggregate.Sum, keys.ToArray());
if (cacheTime > 0)
{
TimeSpan expiry = TimeSpan.FromMinutes(cacheTime);
_database.KeyExpire(destinationKey, expiry);
var expiry = cacheTime * 60;
_client.Expire(destinationKey, expiry);
}
return num;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Banana/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Banana.Filters;
using Banana.Services;
using CSRedis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -41,6 +42,11 @@ public void ConfigureServices(IServiceCollection services)

services.AddOptions();

#region Redis
var RedisClient = new CSRedisClient(Configuration["Redis:CSRedisConnection"]);
services.AddSingleton(_ => RedisClient);
#endregion

#region MongoDB
var MongoConnectionString = Configuration["MongoDB:connectionString"];
var mClient = new MongoClient(MongoConnectionString);
Expand Down
3 changes: 2 additions & 1 deletion src/Banana/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"Redis": {
"Connection": "60.205.223.179:6379",
"Password": "oppzk",
"DefaultKey": "tv"
"DefaultKey": "tv",
"CSRedisConnection": "60.205.223.179:6379,password=oppzk,poolsize=500,prefix=tv:"
},
"ElasticSearch": {
"Url": "http://60.205.223.179:9200"
Expand Down
Loading

0 comments on commit faffb43

Please sign in to comment.