VB.NET memcache增加麻烦

时间:2011-11-17 00:04:56

标签: vb.net memcached increment

尝试在VB.NET中使用memcache的递增函数。当尝试使用increment函数时,它不会增加一个darn并返回-1作为结果。始终说消息计数器从1开始递增。值现在为1

这是我的潜艇。首先运行它添加,然后后续运行它应该使用增量并将值打印到屏幕。

    Dim msgCounter As String
    Dim cacheKey As String = "testkey01"
    msgCounter = DistCache.Get(cacheKey)
    If String.IsNullOrEmpty(msgCounter) Then
        DistCache.Add(cacheKey, 1, TimeSpan.FromMinutes(5))
        msgCounter = "message counter was 0"
    Else
        Label2.Text = DistCache.Increment(cacheKey, 1)
        msgCounter = "message counter incremented from " & msgCounter & ". Value is now " & DistCache.Get(cacheKey)
    End If
    lab1.Text = msgCounter

1 个答案:

答案 0 :(得分:1)

增量对象的数据类型必须是字符串。

正确的行:DistCache.Add(cacheKey, "1", TimeSpan.FromMinutes(5))