Commit 9b5f38a0 authored by Marc Gravell's avatar Marc Gravell

SSDB support

parent 4eb5318a
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackExchange.Redis.Tests
{
[TestFixture]
public class SSDB : TestBase
{
[Test]
public void ConnectToSSDB()
{
var config = new ConfigurationOptions
{
EndPoints = { { "ubuntu", 8888 } },
CommandMap = CommandMap.SSDB
};
RedisKey key = Me();
using (var conn = ConnectionMultiplexer.Connect(config))
{
var db = conn.GetDatabase(0);
db.KeyDelete(key);
Assert.IsTrue(db.StringGet(key).IsNull);
db.StringSet(key, "abc");
Assert.AreEqual("abc", (string)db.StringGet(key));
}
}
}
}
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
<Compile Include="Scripting.cs" /> <Compile Include="Scripting.cs" />
<Compile Include="Secure.cs" /> <Compile Include="Secure.cs" />
<Compile Include="Sets.cs" /> <Compile Include="Sets.cs" />
<Compile Include="SSDB.cs" />
<Compile Include="SSL.cs" /> <Compile Include="SSL.cs" />
<Compile Include="TaskTests.cs" /> <Compile Include="TaskTests.cs" />
<Compile Include="TestBase.cs" /> <Compile Include="TestBase.cs" />
......
...@@ -145,7 +145,8 @@ protected IServer GetServer(ConnectionMultiplexer muxer) ...@@ -145,7 +145,8 @@ protected IServer GetServer(ConnectionMultiplexer muxer)
protected virtual ConnectionMultiplexer Create( protected virtual ConnectionMultiplexer Create(
string clientName = null, int? syncTimeout = null, bool? allowAdmin = null, int? keepAlive = null, string clientName = null, int? syncTimeout = null, bool? allowAdmin = null, int? keepAlive = null,
int? connectTimeout = null, string password = null, string tieBreaker = null, TextWriter log = null, int? connectTimeout = null, string password = null, string tieBreaker = null, TextWriter log = null,
bool fail = true, string[] disabledCommands = null, bool checkConnect = true, bool pause = true, string failMessage = null, bool fail = true, string[] disabledCommands = null, string[] enabledCommands = null,
bool checkConnect = true, bool pause = true, string failMessage = null,
string channelPrefix = null, bool useSharedSocketManager = true, Proxy? proxy = null) string channelPrefix = null, bool useSharedSocketManager = true, Proxy? proxy = null)
{ {
if(pause) Thread.Sleep(500); // get a lot of glitches when hammering new socket creations etc; pace it out a bit if(pause) Thread.Sleep(500); // get a lot of glitches when hammering new socket creations etc; pace it out a bit
...@@ -153,10 +154,10 @@ protected IServer GetServer(ConnectionMultiplexer muxer) ...@@ -153,10 +154,10 @@ protected IServer GetServer(ConnectionMultiplexer muxer)
var config = ConfigurationOptions.Parse(configuration); var config = ConfigurationOptions.Parse(configuration);
if (disabledCommands != null && disabledCommands.Length != 0) if (disabledCommands != null && disabledCommands.Length != 0)
{ {
var map = new Dictionary<string, string>(); config.CommandMap = CommandMap.Create(new HashSet<string>(disabledCommands), false);
foreach (var cmd in disabledCommands) } else if (enabledCommands != null && enabledCommands.Length != 0)
map[cmd] = null; {
config.CommandMap = CommandMap.Create(map); config.CommandMap = CommandMap.Create(new HashSet<string>(enabledCommands), true);
} }
if(Debugger.IsAttached) if(Debugger.IsAttached)
......
...@@ -38,7 +38,13 @@ private static readonly CommandMap ...@@ -38,7 +38,13 @@ private static readonly CommandMap
RedisCommand.BGREWRITEAOF, RedisCommand.BGSAVE, RedisCommand.CLIENT, RedisCommand.CLUSTER, RedisCommand.CONFIG, RedisCommand.DBSIZE, RedisCommand.BGREWRITEAOF, RedisCommand.BGSAVE, RedisCommand.CLIENT, RedisCommand.CLUSTER, RedisCommand.CONFIG, RedisCommand.DBSIZE,
RedisCommand.DEBUG, RedisCommand.FLUSHALL, RedisCommand.FLUSHDB, RedisCommand.INFO, RedisCommand.LASTSAVE, RedisCommand.MONITOR, RedisCommand.SAVE, RedisCommand.DEBUG, RedisCommand.FLUSHALL, RedisCommand.FLUSHDB, RedisCommand.INFO, RedisCommand.LASTSAVE, RedisCommand.MONITOR, RedisCommand.SAVE,
RedisCommand.SHUTDOWN, RedisCommand.SLAVEOF, RedisCommand.SLOWLOG, RedisCommand.SYNC, RedisCommand.TIME RedisCommand.SHUTDOWN, RedisCommand.SLAVEOF, RedisCommand.SLOWLOG, RedisCommand.SYNC, RedisCommand.TIME
}); }), ssdb = Create(new HashSet<string> {
// see http://www.ideawu.com/ssdb/docs/redis-to-ssdb.html
"ping",
"get", "set", "del", "incr", "incrby", "mget", "mset", "keys", "getset", "setnx",
"hget", "hset", "hdel", "hincrby", "hkeys", "hvals", "hmget", "hmset", "hlen",
"zscore", "zadd", "zrem", "zrange", "zrangebyscore", "zincrby", "zdecrby", "zcard",
"llen", "lpush", "rpush", "lpop", "rpop", "lrange", "lindex" }, true);
private readonly byte[][] map; private readonly byte[][] map;
internal CommandMap(byte[][] map) internal CommandMap(byte[][] map)
...@@ -56,6 +62,13 @@ internal CommandMap(byte[][] map) ...@@ -56,6 +62,13 @@ internal CommandMap(byte[][] map)
/// <remarks>https://github.com/twitter/twemproxy/blob/master/notes/redis.md</remarks> /// <remarks>https://github.com/twitter/twemproxy/blob/master/notes/redis.md</remarks>
public static CommandMap Twemproxy { get { return twemproxy; } } public static CommandMap Twemproxy { get { return twemproxy; } }
/// <summary>
/// The commands available to <a href="ssdb">http://www.ideawu.com/ssdb/</a>
/// </summary>
/// <remarks>http://www.ideawu.com/ssdb/docs/redis-to-ssdb.html</remarks>
public static CommandMap SSDB { get { return ssdb; } }
/// <summary> /// <summary>
/// Create a new CommandMap, customizing some commands /// Create a new CommandMap, customizing some commands
/// </summary> /// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment