README.md 7.97 KB
Newer Older
Diego Koga's avatar
Diego Koga committed
1 2
# redis-com-client

Erik Oosterwaal's avatar
Erik Oosterwaal committed
3
This is a fork of redis-com-client by Diego Koga.
4

Erik Oosterwaal's avatar
Erik Oosterwaal committed
5 6 7 8 9
It allows you to connect to a Redis Server from Classic ASP, other COM+ clients should also be able to connect to Redis using the provided DDLs, but that is untested.

Using this software you can use Redis in Classic ASP for caching, session management, or just storing key-value pairs in an efficient, fast way. 

This fork was made to support more Redis commands, and to continue the development of the ASP COM interface for Redis. Another important change is that with this fork it's possible to provide a _configurationstring_ for connecting to different Redis servers across a network, instead of only to localhost. Examples of these configurationstrings can be found here:[https://stackexchange.github.io/StackExchange.Redis/Configuration.html#basic-configuration-strings](https://stackexchange.github.io/StackExchange.Redis/Configuration.html#basic-configuration-strings)
10

11
### Installation
12

13 14
You can either compile the redis-com-client dll yourself using Visual Studio, or use the precompiled dll and its dependencies, found in the `Precompiled DLLs` folder.

Erik Oosterwaal's avatar
Erik Oosterwaal committed
15
Copy the dll and its dependencies to a directory somewhere the application pool of your classic ASP application has rights. Then register the main redis-com-client.dll. The COM+ dll is 64 bit, so it requires the 64-bit regasm.exe to install.
Diego Koga's avatar
Diego Koga committed
16

17 18
`%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\regasm redis-com-client.dll /tlb:redis-com-client.tlb /codebase`

19
Again, make sure the application pool for your ASP site has rights to the directory that contains the dll, and that the depedencies are next to the redis-com-client.dll.
20

21
### Usage
Diego Koga's avatar
Diego Koga committed
22

23
In ASP the client can be used like this:
Diego Koga's avatar
Diego Koga committed
24

25
```vb
26
Set Redis = Server.CreateObject("RedisComClient")
27
    ' Pass in a configuration to connect to a server
28
    Redis.Open("localhost")
29

30 31
    ' SetPermanent gives a key an indefinite TTL...
    call Redis.SetPermanent("key1", "abcde")
32
    Response.Write("Key1 = " & Redis.Get("key1") & "<br/>")
Diego Koga's avatar
Diego Koga committed
33

34
    ' ...but you can always change the TTL later
35 36 37
    call Redis.Expire("key1", 60)
    Response.Write("Key1 TTL = " & Redis.TTL("key1") & "<br/>")

38
    ' Or delete it alltogether
39 40
    Redis.Del("key1")
    Response.Write("Key1 is now gone... " & Redis("key1") & "<br/>")
Diego Koga's avatar
Diego Koga committed
41

42 43
    ' The key "stringkey" will have a TTL of 10 seconds
    call Redis.Set("stringkey", "abcde", 10)
Diego Koga's avatar
Diego Koga committed
44

45 46 47
    ' We can also put keys and values in hashes...
    call Redis.Hset("testhash", "firstfield", "firstvalue")
    call Redis.Hset("testhash", "secondfield", "secondvalue")
48 49
    Response.Write("Testhash[firstfield] = " & Redis.Hget("testhash", "firstfield") & "<br/>")
    Response.Write("Testhash[secondfield] = " & Redis.Hget("testhash", "secondfield") & "<br/>")
50

51
    ' ...and expire the entire hash
52
    call Redis.Expire("testhash", 60)
53
    Response.Write("Testhash will expire in 60 seconds. The TTL is:" & Redis.TTL("testhash") & "<br/>")
54
    dim result : result = Redis.Hget("testhash", "firstfield")
55
    Response.Write("Here is our Testhash[firstfield] again:" & result & "<br/>")
56

57
    ' Or delete a complete hash in one go
58
    Redis.Del("testhash")
59
    Response.Write("Testhash is now gone...<br/>")
60 61 62 63
Set Redis = Nothing
```

### API
Diego Koga's avatar
Diego Koga committed
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
`Open(string configurationstring)`

Opens the connection to a Redis server using a configuration string. Configuration strings are described here: [https://stackexchange.github.io/StackExchange.Redis/Configuration.html#basic-configuration-strings](https://stackexchange.github.io/StackExchange.Redis/Configuration.html#basic-configuration-strings)

`Del(string key)`

Deletes a key from the server

`bool Exists(string key)`

Checks if a key by that name exists. Returns true or false.

`ExpireAt(string key, DateTime ExpireDatetime)`

Expires a key at a specific date and time

`Expire(string key, int seconds)`

Expires a key in the given amount of seconds

`int TTL(string key)`

Returns the TTL (time to live) of a key in seconds

`object Get(string key)`

Returns the value of a key

`Set(string key, object value, int SecondsToExpire)`

Sets the value of a key and the TTL in seconds

`SetPermanent(string key, object value)`

Sets the value of a key. The TTL will be set to -1, which means the key will be available permanently.

`Persist(string key)`

Sets a key to be permanently available

`string Type(string key)`

Returns the type of a key. For example 'string'.

`double Decr(string key)`
Diego Koga's avatar
Diego Koga committed
110

111
Decrements the value of the given key by 1. This key should hold an integer or a double value. Returns the resulting value.
112

113
`double DecrBy(string key, double decrement)`
Diego Koga's avatar
Diego Koga committed
114

115
Decrements the value of the given key by a given number. This key should hold an integer or a double value.Returns the resulting value.
Diego Koga's avatar
Diego Koga committed
116

117
`double Incr(string key)`
Diego Koga's avatar
Diego Koga committed
118

119
Increments the value of the given key by 1. This key should hold an integer or a double value.Returns the resulting value.
120

121
`double IncrBy(string key, double increment)`
Diego Koga's avatar
Diego Koga committed
122

123
Increments the value of the given key by a given number. This key should hold an integer or a double value.Returns the resulting value.
Diego Koga's avatar
Diego Koga committed
124

125
`Hdel(string key, string field)`
Diego Koga's avatar
Diego Koga committed
126

127
Deletes a specified field in a hash
128

129
`bool Hexists(string key, string field)`
Diego Koga's avatar
Diego Koga committed
130

131
Checks if a specified field in a hash exists. Returns true or false.
132

133
`object Hget(string key, string field)`
Diego Koga's avatar
Diego Koga committed
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
Returns the value of a field in a hash

`long Hlen(string key)`

Returns the number of fields in a hash

`bool Hset(string key, string field, string value)`

Sets the value of a field in a hash.

`RemoveKeysWithPrefix(string prefix)`

If you prefix the name of a set of keys with the same string, for example "CACHE:", you can easily delete all of these keys at once using this command. It wil look for all keys with the given prefix and delete them all.

`object this(string key) `

151
This is a shortcut for _SetPermanent(string key, object value)_ and _Get(string key)_ . For example: Instead of writing: _Redis.SetPermanent("mykey", "myvalue")_, you can write: _Redis("mykey") = "myvalue"_. In the same way _Redis.Get("mykey")_, can be written as _Redis("mykey")_.
152 153 154 155

`SetExpiration(string key, int milliseconds)`

This will allow you to set the expiration of a key in milliseconds instead of seconds
156 157 158

### Common errors

159 160 161 162 163 164 165 166
```
Server object error 'ASP 0177 : 800401f3' 
Server.CreateObject Failed 
/redistest.asp, line 7 
800401f3 
```

This message occurs when the component isn't registered. Register it using regasm like this:
167

168 169 170 171 172 173 174 175
`%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\regasm [PATH_TO_THE_DLL] /tlb:redis-com-client.tlb /codebase`

```
Server object error 'ASP 0177 : 80070002' 
Server.CreateObject Failed 
/redistest.asp, line 7 
80070002 
```
176

177 178 179 180 181 182 183 184 185 186
You probably registered the component, but forgot the `/tlb` and `/codebase` part

```
StackExchange.Redis.StrongName error '80131500' 
It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING 
/redistest.asp, line 8
```

You should have a Redis server running on the specified computer. You can run Redis using Windows Subsystem for Linux, by running it on a Linux computer in your network or by finding the Windows Native Redis server online and running it on a Windows computer. 

Erik Oosterwaal's avatar
Erik Oosterwaal committed
187 188 189 190 191 192
```
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
```

This error occurs when you register the dll, but it can be safely ignored unless you have more applications installed that use the redis-com-client, but in a different version.

193
### License
194

195
Licensed under the EUPL - European Union Public License 1.2.
196

197
**`EUPL-1.2`** Copyright (c) 2019 Erik Oosterwaal
198

199
This wrapper uses the StackExchange.Redis general purpose Redis client, which is licensed under the MIT License (MIT). More information can be found here: [https://github.com/StackExchange/StackExchange.Redis/blob/master/LICENSE](https://github.com/StackExchange/StackExchange.Redis/blob/master/LICENSE)
200 201