forked from ServiceStack/ServiceStack.Redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisClient_Admin.cs
More file actions
120 lines (103 loc) · 3.47 KB
/
RedisClient_Admin.cs
File metadata and controls
120 lines (103 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// https://github.com/ServiceStack/ServiceStack.Redis
// ServiceStack.Redis: ECMA CLI Binding to the Redis key-value storage system
//
// Authors:
// Demis Bellot (demis.bellot@gmail.com)
//
// Copyright 2013 Service Stack LLC. All Rights Reserved.
//
// Licensed under the same terms of ServiceStack.
//
using System;
using System.Collections.Generic;
using System.Text;
using ServiceStack.Text;
namespace ServiceStack.Redis
{
public partial class RedisClient
: IRedisClient
{
public void SetConfig(string configItem, string value)
{
base.ConfigSet(configItem, value.ToUtf8Bytes());
}
public RedisText GetServerRoleInfo()
{
return base.Role();
}
public string GetConfig(string configItem)
{
var sb = StringBuilderCache.Allocate();
var byteArray = base.ConfigGet(configItem);
const int startAt = 1; //skip repeating config name
for (var i = startAt; i < byteArray.Length; i++)
{
var bytes = byteArray[i];
if (sb.Length > 0)
sb.Append(" ");
sb.Append(bytes.FromUtf8Bytes());
}
return StringBuilderCache.ReturnAndFree(sb);
}
public void SaveConfig()
{
base.ConfigRewrite();
}
public void ResetInfoStats()
{
base.ConfigResetStat();
}
public string GetClient()
{
return base.ClientGetName();
}
public void SetClient(string name)
{
base.ClientSetName(name);
}
public void KillClient(string address)
{
base.ClientKill(address);
}
public long KillClients(string fromAddress = null, string withId = null, RedisClientType? ofType = null, bool? skipMe = null)
{
var typeString = ofType != null ? ofType.ToString().ToLower() : null;
var skipMeString = skipMe != null ? (skipMe.Value ? "yes" : "no") : null;
return base.ClientKill(addr: fromAddress, id: withId, type: typeString, skipMe: skipMeString);
}
public List<Dictionary<string, string>> GetClientsInfo()
{
var clientList = base.ClientList().FromUtf8Bytes();
var results = new List<Dictionary<string, string>>();
var lines = clientList.Split('\n');
foreach (var line in lines)
{
if (String.IsNullOrEmpty(line)) continue;
var map = new Dictionary<string, string>();
var parts = line.Split(' ');
foreach (var part in parts)
{
var keyValue = part.SplitOnFirst('=');
map[keyValue[0]] = keyValue[1];
}
results.Add(map);
}
return results;
}
public void PauseAllClients(TimeSpan duration)
{
base.ClientPause((int)duration.TotalMilliseconds);
}
public DateTime GetServerTime()
{
var parts = base.Time();
var unixTime = long.Parse(parts[0].FromUtf8Bytes());
var microSecs = long.Parse(parts[1].FromUtf8Bytes());
var ticks = microSecs / 1000 * TimeSpan.TicksPerMillisecond;
var date = unixTime.FromUnixTime();
var timeSpan = TimeSpan.FromTicks(ticks);
return date + timeSpan;
}
}
}