├── .gitignore ├── README.md ├── vRedis.Tests ├── AppendTests.vb ├── DelTests.vb ├── DumpTests.vb ├── EchoTests.vb ├── ExistsTests.vb ├── ExpireAtTests.vb ├── ExpireTests.vb ├── GetTests.vb ├── My Project │ ├── Application.Designer.vb │ ├── Application.myapp │ ├── AssemblyInfo.vb │ ├── Resources.Designer.vb │ ├── Resources.resx │ ├── Settings.Designer.vb │ └── Settings.settings ├── PExpireAtTests.vb ├── PExpireTests.vb ├── PingTests.vb ├── SetTests.vb ├── TimeTests.vb └── vRedis.Tests.vbproj ├── vRedis.sln └── vRedis ├── Commands ├── AppendCommand.vb ├── DelCommand.vb ├── DumpCommand.vb ├── EchoCommand.vb ├── ExistsCommand.vb ├── ExpireAtCommand.vb ├── ExpireCommand.vb ├── GetCommand.vb ├── PExpireAtCommand.vb ├── PExpireCommand.vb ├── PingCommand.vb ├── SetCommand.vb └── TimeCommand.vb ├── IRedisCommand.vb ├── My Project ├── Application.Designer.vb ├── Application.myapp ├── AssemblyInfo.vb ├── Resources.Designer.vb ├── Resources.resx ├── Settings.Designer.vb └── Settings.settings ├── RESPType.vb ├── RedisClient.vb ├── RedisException.vb ├── RedisReply.vb └── vRedis.vbproj /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.suo 4 | *.user 5 | _ReSharper.* 6 | *.DS_Store 7 | *.userprefs 8 | *.pidb 9 | *.vspx 10 | *.psess 11 | packages 12 | target 13 | artifacts 14 | StyleCop.Cache 15 | node_modules 16 | *.snk 17 | .nuget/NuGet.exe 18 | project.lock.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vRedis 2 | Redis client using VB.NET 3 | 4 | ## Supported Commands: 5 | 6 | * ```APPEND``` append a value to a key 7 | * ```DEL``` delete a key 8 | * ```DUMP``` get a serialized version of the value of a key 9 | * ```ECHO``` echo the given string 10 | * ```EXISTS``` determine if a key exists 11 | * ```EXPIRE``` sets a key's time to live in seconds 12 | * ```EXPIREAT``` sets a key's time to live in UNIX timestamp 13 | * ```GET``` get the value of a key 14 | * ```PEXPIRE``` sets the expiration of the key in milliseconds 15 | * ```PEXPIREAT``` sets the expiration of the key in UNIX timestamp 16 | * ```PING``` ping the server 17 | * ```SET``` set the string value of a key 18 | * ```TIME``` return the current server time 19 | -------------------------------------------------------------------------------- /vRedis.Tests/AppendTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class AppendTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub Append() 12 | client.Append("name", "athan") 13 | Assert.AreEqual(8, client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/DelTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class DelTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub DeleteKey() 12 | client.Del("name") 13 | Assert.AreEqual(1, client.Return) 14 | End Sub 15 | 16 | 17 | Public Sub DeleteMultipleKeys() 18 | client.Del("name", "age") 19 | Assert.AreEqual(2, client.Return) 20 | End Sub 21 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/DumpTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class DumpTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub Dump() 12 | client.Dump("name") 13 | Assert.IsNotNull(client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/EchoTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class EchoTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub Echo() 12 | client.Echo("Redis") 13 | Assert.AreEqual("Redis", client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/ExistsTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class ExistsTests 3 | Private client As RedisClient 4 | Private reply As Boolean 5 | 6 | 7 | Public Sub Setup() 8 | client = New RedisClient() 9 | End Sub 10 | 11 | 12 | Public Sub CheckExistentKey() 13 | reply = client.Exists("name") 14 | Assert.IsTrue(reply) 15 | End Sub 16 | 17 | 18 | Public Sub CheckNonExistentKey() 19 | reply = client.Exists("position") 20 | Assert.IsFalse(reply) 21 | End Sub 22 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/ExpireAtTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class ExpireAtTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub ExpireAt() 12 | client.ExpireAt("name", DateTime.Now) 13 | Assert.AreEqual(1, client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/ExpireTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class ExpireTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub Expire() 12 | client.Expire("name", 10) 13 | Assert.AreEqual(1, client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/GetTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class GetTests 3 | Private client As RedisClient 4 | Private reply As String 5 | 6 | 7 | Public Sub Setup() 8 | client = New RedisClient() 9 | End Sub 10 | 11 | 12 | Public Sub GetValue() 13 | reply = client.Get("name") 14 | Assert.AreEqual("scott", reply) 15 | End Sub 16 | 17 | 18 | Public Sub GetValueForNonExistKey() 19 | reply = client.Get("level") 20 | Assert.IsNull(reply) 21 | End Sub 22 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 1 9 | true 10 | 11 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Resources.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My.Resources 16 | 17 | 'This class was auto-generated by the StronglyTypedResourceBuilder 18 | 'class via a tool like ResGen or Visual Studio. 19 | 'To add or remove a member, edit your .ResX file then rerun ResGen 20 | 'with the /str option, or rebuild your VS project. 21 | ''' 22 | ''' A strongly-typed resource class, for looking up localized strings, etc. 23 | ''' 24 | _ 28 | Friend Module Resources 29 | 30 | Private resourceMan As Global.System.Resources.ResourceManager 31 | 32 | Private resourceCulture As Global.System.Globalization.CultureInfo 33 | 34 | ''' 35 | ''' Returns the cached ResourceManager instance used by this class. 36 | ''' 37 | _ 38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 39 | Get 40 | If Object.ReferenceEquals(resourceMan, Nothing) Then 41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("vRedis.Tests.Resources", GetType(Resources).Assembly) 42 | resourceMan = temp 43 | End If 44 | Return resourceMan 45 | End Get 46 | End Property 47 | 48 | ''' 49 | ''' Overrides the current thread's CurrentUICulture property for all 50 | ''' resource lookups using this strongly typed resource class. 51 | ''' 52 | _ 53 | Friend Property Culture() As Global.System.Globalization.CultureInfo 54 | Get 55 | Return resourceCulture 56 | End Get 57 | Set(ByVal value As Global.System.Globalization.CultureInfo) 58 | resourceCulture = value 59 | End Set 60 | End Property 61 | End Module 62 | End Namespace 63 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Settings.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.vRedis.Tests.My.MySettings 68 | Get 69 | Return Global.vRedis.Tests.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /vRedis.Tests/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /vRedis.Tests/PExpireAtTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class PExpireAtTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub ExpireAt() 12 | client.PExpireAt("name", DateTime.Now) 13 | Assert.AreEqual(1, client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/PExpireTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class PExpireTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub PExpire() 12 | client.PExpire("name", 10) 13 | Assert.AreEqual(1, client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/PingTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class PingTests 3 | Private client As RedisClient 4 | 5 | 6 | Public Sub Setup() 7 | client = New RedisClient() 8 | End Sub 9 | 10 | 11 | Public Sub Ping() 12 | client.Ping() 13 | Assert.AreEqual("PONG", client.Return) 14 | End Sub 15 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/SetTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class SetTests 3 | 4 | Private client As RedisClient 5 | 6 | 7 | Public Sub Setup() 8 | client = New RedisClient() 9 | End Sub 10 | 11 | 12 | Public Sub SetKeyValue() 13 | client.Set("name", "John") 14 | Assert.AreEqual("OK", client.Return) 15 | End Sub 16 | 17 | 18 | Public Sub SetKeyWithExpirationTime() 19 | client.Set("age", "21", TimeSpan.FromSeconds(5)) 20 | Assert.AreEqual("OK", client.Return) 21 | End Sub 22 | 23 | 24 | Public Sub SetExistentKey() 25 | client.Set("name", "John", override:=True) 26 | Assert.AreEqual("OK", client.Return) 27 | End Sub 28 | 29 | 30 | Public Sub SetNonExistentKey() 31 | client.Set("gender", "male", override:=False) 32 | Assert.IsNull(client.Return) 33 | End Sub 34 | 35 | 36 | Public Sub SetExistentKeyWithExpirationTime() 37 | client.Set("name", "Scott", TimeSpan.FromMilliseconds(3000), True) 38 | Assert.AreEqual("OK", client.Return) 39 | End Sub 40 | 41 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/TimeTests.vb: -------------------------------------------------------------------------------- 1 |  2 | Public Class TimeTests 3 | Private client As RedisClient 4 | Private reply As Date 5 | 6 | 7 | Public Sub Setup() 8 | client = New RedisClient() 9 | End Sub 10 | 11 | 12 | Public Sub GetTime() 13 | reply = client.Time() 14 | Assert.AreEqual(Date.Now.ToShortTimeString(), reply.ToShortTimeString()) 15 | End Sub 16 | End Class -------------------------------------------------------------------------------- /vRedis.Tests/vRedis.Tests.vbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {F9D6EA1B-1307-4099-B772-C4837C1B200D} 7 | Library 8 | vRedis.Tests 9 | vRedis.Tests 10 | 512 11 | Windows 12 | v4.5 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | true 24 | true 25 | bin\Debug\ 26 | vRedis.Tests.xml 27 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 28 | 29 | 30 | pdbonly 31 | false 32 | true 33 | true 34 | bin\Release\ 35 | vRedis.Tests.xml 36 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 37 | 38 | 39 | On 40 | 41 | 42 | Binary 43 | 44 | 45 | Off 46 | 47 | 48 | On 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 | True 95 | Application.myapp 96 | 97 | 98 | True 99 | True 100 | Resources.resx 101 | 102 | 103 | True 104 | Settings.settings 105 | True 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | VbMyResourcesResXFileCodeGenerator 115 | Resources.Designer.vb 116 | My.Resources 117 | Designer 118 | 119 | 120 | 121 | 122 | MyApplicationCodeGenerator 123 | Application.Designer.vb 124 | 125 | 126 | SettingsSingleFileGenerator 127 | My 128 | Settings.Designer.vb 129 | 130 | 131 | 132 | 133 | {10909452-7e9f-4d88-9244-5669f4b980c3} 134 | vRedis 135 | 136 | 137 | 138 | 139 | 140 | 141 | False 142 | 143 | 144 | False 145 | 146 | 147 | False 148 | 149 | 150 | False 151 | 152 | 153 | 154 | 155 | 156 | 157 | 164 | -------------------------------------------------------------------------------- /vRedis.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22609.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vRedis", "vRedis\vRedis.vbproj", "{10909452-7E9F-4D88-9244-5669F4B980C3}" 7 | EndProject 8 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vRedis.Tests", "vRedis.Tests\vRedis.Tests.vbproj", "{F9D6EA1B-1307-4099-B772-C4837C1B200D}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {10909452-7E9F-4D88-9244-5669F4B980C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {10909452-7E9F-4D88-9244-5669F4B980C3}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {10909452-7E9F-4D88-9244-5669F4B980C3}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {10909452-7E9F-4D88-9244-5669F4B980C3}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {F9D6EA1B-1307-4099-B772-C4837C1B200D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F9D6EA1B-1307-4099-B772-C4837C1B200D}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F9D6EA1B-1307-4099-B772-C4837C1B200D}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F9D6EA1B-1307-4099-B772-C4837C1B200D}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /vRedis/Commands/AppendCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class AppendCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "APPEND" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property Value As String 14 | 15 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 16 | Return $"APPEND {Key} {Value}" 17 | End Function 18 | End Class 19 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/DelCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class DelCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "DEL" 8 | End Get 9 | End Property 10 | 11 | Public Property Keys As String() 12 | 13 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 14 | Return $"DEL {String.Join(" ", Keys)}" 15 | End Function 16 | End Class 17 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/DumpCommand.vb: -------------------------------------------------------------------------------- 1 | Imports vRedis 2 | 3 | Public Class DumpCommand 4 | Implements IRedisCommand 5 | 6 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 7 | Get 8 | Return "DUMP" 9 | End Get 10 | End Property 11 | 12 | Public Property Key As String 13 | 14 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 15 | Return $"DUMP {Key}" 16 | End Function 17 | End Class 18 | -------------------------------------------------------------------------------- /vRedis/Commands/EchoCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class EchoCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "ECHO" 8 | End Get 9 | End Property 10 | 11 | Public Property Message As String 12 | 13 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 14 | Return $"ECHO {Message}" 15 | End Function 16 | End Class 17 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/ExistsCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class ExistsCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "EXISTS" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 14 | Return $"EXISTS {Key}" 15 | End Function 16 | End Class 17 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/ExpireAtCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class ExpireAtCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "EXPIREAT" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property TTL As Long 14 | 15 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 16 | Return $"EXPIREAT {Key} {TTL}" 17 | End Function 18 | End Class 19 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/ExpireCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class ExpireCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "EXPIRE" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property Timeout As Integer 14 | 15 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 16 | Return $"EXPIRE {Key} {Timeout}" 17 | End Function 18 | End Class 19 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/GetCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class GetCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "GET" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Private Function GetCommand() As String Implements IRedisCommand.GetCommand 14 | Return $"GET {Key}" 15 | End Function 16 | End Class 17 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/PExpireAtCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class PExpireAtCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "PEXPIREAT" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property TTL As Long 14 | 15 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 16 | Return $"PEXPIREAT {Key} {TTL}" 17 | End Function 18 | End Class 19 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/PExpireCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class PExpireCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "PEXPIRE" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property Timeout As Integer 14 | 15 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 16 | Return $"PEXPIRE {Key} {Timeout}" 17 | End Function 18 | End Class 19 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/PingCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class PingCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "PING" 8 | End Get 9 | End Property 10 | 11 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 12 | Return "PING" 13 | End Function 14 | End Class 15 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/SetCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class SetCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "SET" 8 | End Get 9 | End Property 10 | 11 | Public Property Key As String 12 | 13 | Public Property Value As String 14 | 15 | Public Property ExpireTime As TimeSpan? 16 | 17 | Public Property Override As Boolean? 18 | 19 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 20 | If ExpireTime.HasValue Then 21 | If Override.HasValue Then 22 | Return $"SET {Key} {Value} EX {ExpireTime.Value.TotalSeconds} {IIf(Override, "XX", "NX")}" 23 | Else 24 | Return $"SET {Key} {Value} EX {ExpireTime.Value.TotalSeconds}" 25 | End If 26 | Else 27 | If Override.HasValue Then 28 | Return $"SET {Key} {Value} {IIf(Override, "XX", "NX")}" 29 | Else 30 | Return $"SET {Key} {Value}" 31 | End If 32 | End If 33 | End Function 34 | End Class 35 | End Namespace -------------------------------------------------------------------------------- /vRedis/Commands/TimeCommand.vb: -------------------------------------------------------------------------------- 1 | Namespace Commands 2 | Public Class TimeCommand 3 | Implements IRedisCommand 4 | 5 | Public ReadOnly Property Name As String Implements IRedisCommand.Name 6 | Get 7 | Return "TIME" 8 | End Get 9 | End Property 10 | 11 | Public Function GetCommand() As String Implements IRedisCommand.GetCommand 12 | Return "TIME" 13 | End Function 14 | End Class 15 | End Namespace -------------------------------------------------------------------------------- /vRedis/IRedisCommand.vb: -------------------------------------------------------------------------------- 1 | Public Interface IRedisCommand 2 | ReadOnly Property Name As String 3 | 4 | Function GetCommand() As String 5 | End Interface -------------------------------------------------------------------------------- /vRedis/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /vRedis/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 1 9 | true 10 | 11 | -------------------------------------------------------------------------------- /vRedis/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /vRedis/My Project/Resources.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My.Resources 16 | 17 | 'This class was auto-generated by the StronglyTypedResourceBuilder 18 | 'class via a tool like ResGen or Visual Studio. 19 | 'To add or remove a member, edit your .ResX file then rerun ResGen 20 | 'with the /str option, or rebuild your VS project. 21 | ''' 22 | ''' A strongly-typed resource class, for looking up localized strings, etc. 23 | ''' 24 | _ 28 | Friend Module Resources 29 | 30 | Private resourceMan As Global.System.Resources.ResourceManager 31 | 32 | Private resourceCulture As Global.System.Globalization.CultureInfo 33 | 34 | ''' 35 | ''' Returns the cached ResourceManager instance used by this class. 36 | ''' 37 | _ 38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 39 | Get 40 | If Object.ReferenceEquals(resourceMan, Nothing) Then 41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("vRedis.Resources", GetType(Resources).Assembly) 42 | resourceMan = temp 43 | End If 44 | Return resourceMan 45 | End Get 46 | End Property 47 | 48 | ''' 49 | ''' Overrides the current thread's CurrentUICulture property for all 50 | ''' resource lookups using this strongly typed resource class. 51 | ''' 52 | _ 53 | Friend Property Culture() As Global.System.Globalization.CultureInfo 54 | Get 55 | Return resourceCulture 56 | End Get 57 | Set(ByVal value As Global.System.Globalization.CultureInfo) 58 | resourceCulture = value 59 | End Set 60 | End Property 61 | End Module 62 | End Namespace 63 | -------------------------------------------------------------------------------- /vRedis/My Project/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /vRedis/My Project/Settings.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.0 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.vRedis.My.MySettings 68 | Get 69 | Return Global.vRedis.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /vRedis/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /vRedis/RESPType.vb: -------------------------------------------------------------------------------- 1 | Friend Enum RESPType 2 | Array 3 | BulkString 4 | [Error] 5 | [Integer] 6 | SimpleString 7 | End Enum -------------------------------------------------------------------------------- /vRedis/RedisClient.vb: -------------------------------------------------------------------------------- 1 | Imports System.Net.Sockets 2 | Imports System.Text 3 | Imports vRedis.Commands 4 | 5 | Public Class RedisClient 6 | Private client As TcpClient 7 | Private stream As NetworkStream 8 | Private reply As RedisReply 9 | Private command As IRedisCommand 10 | 11 | Public ReadOnly Property Host As String 12 | 13 | Public ReadOnly Property Port As Integer 14 | 15 | Public ReadOnly Property [Return] As Object 16 | Get 17 | Return reply.Value 18 | End Get 19 | End Property 20 | 21 | Public Sub New(Optional host As String = "127.0.0.1", Optional port As Integer = 6379) 22 | If IsNothing(host) Then 23 | Throw New ArgumentNullException(NameOf(host)) 24 | End If 25 | Me.Host = host 26 | Me.Port = port 27 | client = New TcpClient() 28 | Try 29 | client.Connect(host, port) 30 | stream = client.GetStream() 31 | Catch ex As Exception 32 | Throw New RedisException("An existing connection was forcibly closed by remote host.") 33 | End Try 34 | End Sub 35 | 36 | Public Sub Append(key As String, value As String) 37 | command = New AppendCommand() With {.Key = key, .Value = value} 38 | Execute(command) 39 | End Sub 40 | 41 | Public Sub Del(ParamArray keys() As String) 42 | command = New DelCommand() With {.Keys = keys} 43 | Execute(command) 44 | End Sub 45 | 46 | Public Function Dump(key As String) As Byte() 47 | command = New DumpCommand() With {.Key = key} 48 | Execute(command) 49 | If IsNothing(reply.Value) Then 50 | Return Nothing 51 | Else 52 | Return Encoding.UTF8.GetBytes(reply.Value) 53 | End If 54 | End Function 55 | 56 | Public Sub Echo(message As String) 57 | command = New EchoCommand() With {.Message = message} 58 | Execute(command) 59 | End Sub 60 | 61 | Public Function Exists(key As String) As Boolean 62 | command = New ExistsCommand() With {.Key = key} 63 | Execute(command) 64 | Return reply.Value 65 | End Function 66 | 67 | Public Sub Expire(key As String, timeout As Integer) 68 | command = New ExpireCommand() With {.Key = key, .Timeout = timeout} 69 | Execute(command) 70 | End Sub 71 | 72 | Public Sub ExpireAt(key As String, ttl As DateTime) 73 | command = New ExpireAtCommand() With {.Key = key, .TTL = (ttl - #1/1/1970#).TotalSeconds} 74 | Execute(command) 75 | End Sub 76 | 77 | Public Function [Get](key As String) As String 78 | command = New GetCommand() With {.Key = key} 79 | Execute(command) 80 | Return reply.Value 81 | End Function 82 | 83 | Public Sub PExpire(key As String, timeout As Integer) 84 | command = New PExpireCommand() With {.Key = key, .Timeout = timeout} 85 | Execute(command) 86 | End Sub 87 | 88 | Public Sub PExpireAt(key As String, ttl As DateTime) 89 | command = New PExpireAtCommand() With {.Key = key, .TTL = (ttl - #1/1/1970#).TotalMilliseconds} 90 | Execute(command) 91 | End Sub 92 | 93 | Public Sub Ping() 94 | command = New PingCommand() 95 | Execute(command) 96 | End Sub 97 | 98 | Public Sub [Set](key As String, value As Object, Optional expireTime As TimeSpan? = Nothing, Optional override As Boolean? = Nothing) 99 | command = New SetCommand() With {.Key = key, .Value = value, .ExpireTime = expireTime, .Override = override} 100 | Execute(command) 101 | End Sub 102 | 103 | Public Function Time() As Date 104 | command = New TimeCommand() 105 | Execute(command) 106 | Return #1/1/1970#.AddSeconds(reply.Value(0)).ToLocalTime() 107 | End Function 108 | 109 | Private Sub Execute(command As IRedisCommand) 110 | Dim bytes() As Byte = Encoding.UTF8.GetBytes(command.GetCommand() & vbCrLf) 111 | Try 112 | stream.Write(bytes, 0, bytes.Length) 113 | stream.Flush() 114 | ReDim bytes(client.ReceiveBufferSize) 115 | stream.Read(bytes, 0, bytes.Length) 116 | Dim result = Encoding.UTF8.GetString(bytes) 117 | Select Case result(0) 118 | Case "$" 119 | Dim length = Convert.ToInt32(result.Substring(1, result.IndexOf(vbCrLf) - 1)) 120 | If length = -1 Then 121 | reply = New RedisReply(RESPType.BulkString, Nothing) 122 | Else 123 | reply = New RedisReply(RESPType.BulkString, result.Substring(result.IndexOf(vbCrLf) + 2, length)) 124 | End If 125 | Case "+" 126 | reply = New RedisReply(RESPType.SimpleString, result.Substring(1, result.IndexOf(vbCrLf) - 1)) 127 | Case ":" 128 | reply = New RedisReply(RESPType.Integer, Convert.ToInt32(result.Substring(1, result.IndexOf(vbCrLf) - 1))) 129 | Case "-" 130 | reply = New RedisReply(RESPType.Error, result.Substring(1, result.IndexOf(vbCrLf) - 1)) 131 | Throw New RedisException(reply.Value) 132 | Case "*" 133 | Dim count = Convert.ToInt32(result.Substring(1, result.IndexOf(vbCrLf) - 1)) 134 | Dim items = result.Split(New Char() {vbCrLf, vbLf}, StringSplitOptions.RemoveEmptyEntries).ToList() 135 | items.RemoveAt(0) 136 | items.RemoveAll(Function(i) i.StartsWith("$")) 137 | items.RemoveAt(items.Count - 1) 138 | reply = New RedisReply(RESPType.Array, items) 139 | End Select 140 | Catch ex As Exception 141 | Throw New RedisException($"There is an internal error during executing '{command.GetCommand()}'.") 142 | End Try 143 | End Sub 144 | End Class -------------------------------------------------------------------------------- /vRedis/RedisException.vb: -------------------------------------------------------------------------------- 1 | Public Class RedisException 2 | Inherits ApplicationException 3 | 4 | Public Sub New(message As String) 5 | MyBase.New(message) 6 | End Sub 7 | End Class 8 | -------------------------------------------------------------------------------- /vRedis/RedisReply.vb: -------------------------------------------------------------------------------- 1 | Friend Structure RedisReply 2 | Friend Property Type As RESPType 3 | 4 | Friend Property Value As Object 5 | 6 | Friend Sub New(type As RESPType, value As Object) 7 | Me.Type = type 8 | Me.Value = value 9 | End Sub 10 | End Structure -------------------------------------------------------------------------------- /vRedis/vRedis.vbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {10909452-7E9F-4D88-9244-5669F4B980C3} 8 | Library 9 | vRedis 10 | vRedis 11 | 512 12 | Windows 13 | v4.5 14 | 15 | 16 | true 17 | full 18 | true 19 | true 20 | bin\Debug\ 21 | vRedis.xml 22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 23 | 24 | 25 | pdbonly 26 | false 27 | true 28 | true 29 | bin\Release\ 30 | vRedis.xml 31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 32 | 33 | 34 | On 35 | 36 | 37 | Binary 38 | 39 | 40 | Off 41 | 42 | 43 | On 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 | True 81 | Application.myapp 82 | 83 | 84 | True 85 | True 86 | Resources.resx 87 | 88 | 89 | True 90 | Settings.settings 91 | True 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | VbMyResourcesResXFileCodeGenerator 102 | Resources.Designer.vb 103 | My.Resources 104 | Designer 105 | 106 | 107 | 108 | 109 | MyApplicationCodeGenerator 110 | Application.Designer.vb 111 | 112 | 113 | SettingsSingleFileGenerator 114 | My 115 | Settings.Designer.vb 116 | 117 | 118 | 119 | 126 | --------------------------------------------------------------------------------