I have a set which contains integer values. And I want to retrieve part of it with sscan.
127.0.0.1:6379[1]> smembers d
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
6) "6"
7) "7"
8) "8"
...
But sscan returns full list of members:
127.0.0.1:6379[1]> sscan d 0
1) "0"
2) 1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
6) "6"
7) "7"
8) "8"
9) "9"
....
Is there any way which brings me members page by page(for eg. 10 items for every scan)
Use the COUNT directive as explained in SCAN's documentation to return a fixed number of results.
Related
I'm trying to only get values in a hash larger than, say 1800, by Lua. I am new to Lua and I am not sure how to get the values from Redis, because the redis.call() method returns 1 only.
Here is my code. Here the keys of my hash is "1""2""3" etc, just to make it simpler.
for i=1,length do
value = tonumber(redis.call("HGET", KEYS[1], i))
if value >= 1800 then
return redis.call("HGET", KEYS[1], i)
end
end
Let's say I have a hash called Data like this:
HGETALL Data
1) "monday"
2) "1802"
3) "tuesday"
4) "1283"
5) "wednesday"
6) "3487"
7) "thursday"
8) "1899"
9) "friday"
10) "1709"
11) "saturday"
12) "1909"
13) "sunday"
14) "1799"
I expect that when I use the HGETALL method, I get this:
1) "monday"
2) "1802"
5) "wednesday"
6) "3487"
7) "thursday"
8) "1899"
11) "saturday"
12) "1909"
for i=1,length do
value = tonumber(redis.call("HGET", KEYS[1], i))
if value >= 1800 then
return redis.call("HGET", KEYS[1], i)
end
end
This code tells your computer: look through all entries and give me the first one that is >= 1802.
If you want to get all values above you have several options.
You get a full list of entries using HGETALL and then filter the returned list of entries or you get single elements and put them into a list when they are >= 1800.
The return statement is used to return values from a function or a
chunk (which is an anonymous function).
That means whatever function you're code is in will end if you return.
So using it inside your loop is not really an option if you want to process multiple entries.
Try something like
-- create an empty table
local greatValues = {}
for i=1,length do
value = tonumber(redis.call("HGET", KEYS[1], i))
if value >= 1800 then
-- insert any value that is >=1800 into the table
table.insert(greatValues, value)
end
end
-- return the list of results
return greatValues
The VB code is used to read in complex barcodes and separate their AIs. This block of code correctly processes the complex barcode 01984000000726283102002046102577855921221505 and makes it through the ElseIf correctly:
ElseIf (ScannedBarcode.Length >= 44 AndAlso (ScannedBarcode.Substring(0, 2) = "01" _
And ScannedBarcode.Substring(16, 4) = "3102" _
And ScannedBarcode.Substring(26, 2) = "10" _
And ScannedBarcode.Substring(36, 2) = "21")) Then
oProduct.ProductCode = ScannedBarcode.Substring(2, 14)
oProduct.ExpiryDate = "" 'Expiry date
oProduct.Qty = ScannedBarcode.Substring(20, 6) / 100
However, when the same approach is used to process a different complex barcode, 0195391509285882108054057171710133102001202, with differently arranged AIs, the substring seems to be returning 1 less than the specified length, e.g. 310 instead of 3102.
ElseIf ScannedBarcode.Length >= 44 AndAlso (ScannedBarcode.Substring(0, 2) = "01" _
And ScannedBarcode.Substring(16, 2) = "10" _
And ScannedBarcode.Substring(26, 2) = "17" _
And ScannedBarcode.Substring(35, 4) = "3102") Then
oProduct.ProductCode = ScannedBarcode.Substring(2, 14)
oProduct.ExpiryDate = ScannedBarcode.Substring(27, 6) 'Expiry date
oProduct.Qty = ScannedBarcode.Substring(38, 6) / 100
Any advice would be appreciated, thanks
First of all, your second barcode is only 43 characters and not 44. And perhaps because of that, one of your SubStrings doesn't match:
ScannedBarcode.Substring(26, 2)
It returns 71 and not the 17 you expected.
So my part of the code that gives me problems is this one. It says:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in WindowsApplication1.exe
Additional information: Index was outside the bounds of the array
for Label1.Text = question(i - 1,0) and I really don't understand.
I am at the start and I am really trying to learn things for programming.
Public Class Test1
Dim question(2, 5) As String
Dim i As Integer = 2
Private Sub Test1_Load()
question(1, 0) = "2+2="
question(1, 1) = "1"
question(1, 2) = "2"
question(1, 3) = "3"
question(1, 4) = "4"
question(2, 0) = "How old are you?"
question(2, 1) = "12"
question(2, 2) = "13"
question(2, 3) = "17"
question(2, 4) = "18"
Label1.Text = question(i - 1, 0)
nr1.Text = question(i - 1, 1)
nr2.Text = question(i - 1, 2)
nr3.Text = question(i - 1, 3)
nr4.Text = question(i - 1, 4)
End Sub
Your code didn't give me any errors on dotnetfiddle.net. So "question" is a 2D array indexed from 0-2 and 0-5. Here's what it kinda looks like:
0 1 2 3 4 5
0 s s s s s s
1 s s s s s s
2 s s s s s s
Where each 's' represents a string. So if you're accessing question(0, 0), then it would be the 's' in the top left. If you're accessing question(0, 1), then it would be the 's' to the right of that one. If you try to access something outside of the bounds of your array, you will get an error, for example, if you try to access question(3, 0).
So to fix your error, you need to figure out what the value of i is. Try putting
MessageBox.Show(i)
right before the line that's giving you the error.
I am working with a system that reports user data into two columns: Column A has the fields (9 total per record) and Column B has the corresponding user data.
Column A looks like this:
Last Name:
First Name:
Middle Name:
Card Number:
Employee Ref:
Personal Details:
Associate Number:
Location Name:
Status:
The formatting on this report has the fields repeated for each record, meaning that row 10 will be blank, and row 11 will be Last Name:, row 12 will be First Name:, etc. This format results in very lengthy reports that are difficult to manage.
Another complication to this report concerns null values. Fields with null values are excluded from the report. For example, a record that does not have a Location Name will exclude the Location Name: field altogether. The result of the missing field is a record that is 8 rows instead of the the normal 9 rows. Some of these records are missing multiple fields, on account of null values.
I am looking for an elegant way to reformat this report. Specifically, I'm looking for...
-The fields in Column A become Column headers (A,B,C,D,E,F,G,H,I).
-The data in Column B is moved onto a single row, aligned with the corresponding field headers.
The report I'm currently looking at has 3730 records. However, the system outputs a file that is 43906 rows (including blank rows). I'd like to get this report to 3731 rows (1 row for field headers + 3730 records).
Any assistance with reformatting this report would be greatly appreciated.
Thank you,
pheidias
Here is some sample data of 3 records:
• Last Name: #1
• First Name: Security
• Middle Name: Badge
• Card Number: 100
• Employee Ref: Security
• Personal Details: none
• Associate Number: N/A
• Location Name: HQ
• Status: Contractor / Temp
•
• Last Name: Doe
• First Name: John
• Middle Name:
• Card Number: 101
• Employee Ref:
•
• Last Name: Deere
• First Name: John
• Middle Name:
• Card Number: 102
• Employee Ref:
• Status: Associate
Try this.
Place the following routine into a standard code module:
Sub pheidias()
Dim c&, i&, t, v, w
With ActiveSheet.[a1]
v = .Resize(.Item(.Parent.Rows.Count).End(xlUp).Row, 2)
End With
ReDim w(1 To UBound(v), 1 To 9)
t = Split(".Last Name.First Name.Middle Name.Card Number.Employee Ref.Personal Details.Associate Number.Location Name.Status.", ".")
For i = 1 To 9
w(1, i) = t(i)
Next
c = 2
For i = 1 To UBound(v)
If Len(v(i, 1)) Then
w(c, (InStr("lafimicaempeaslost", LCase$(Left$(v(i, 1), 2))) - 1) / 2 + 1) = v(i, 2)
Else
c = c + 1
End If
Next
[e1].Resize(UBound(w), UBound(w, 2)) = w
End Sub
Note: this routine assumes that the data start in cell A1 and that only ONE blank row separates each of the source report groups.
Note: the location of the output can be edited in the last line. The upper left-hand corner of the output report currently defaults to cell E1.
UPDATE
Try this also. The two versions are really the same, but the one below is probably easier to read...
Sub pheidias()
Dim c&, i&, v, w
With ActiveSheet.[a1]
v = .Resize(.Item(.Parent.Rows.Count).End(xlUp).Row, 2)
End With
ReDim w(1 To UBound(v), 1 To 9)
w(1, 1) = "Last Name"
w(1, 2) = "First Name"
w(1, 3) = "Middle Name"
w(1, 4) = "Card Number"
w(1, 5) = "Employee Ref"
w(1, 6) = "Personal Details"
w(1, 7) = "Associate Number"
w(1, 8) = "Location Name"
w(1, 9) = "Status"
c = 2
For i = 1 To UBound(v)
If Len(v(i, 1)) Then
Select Case LCase$(Left$(v(i, 1), 2))
Case "la": w(c, 1) = v(i, 2)
Case "fi": w(c, 2) = v(i, 2)
Case "mi": w(c, 3) = v(i, 2)
Case "ca": w(c, 4) = v(i, 2)
Case "em": w(c, 5) = v(i, 2)
Case "pe": w(c, 6) = v(i, 2)
Case "as": w(c, 7) = v(i, 2)
Case "lo": w(c, 8) = v(i, 2)
Case "st": w(c, 9) = v(i, 2)
End Select
Else
c = c + 1
End If
Next
[e1].Resize(UBound(w), UBound(w, 2)) = w
End Sub
I'm working on a script to detect whether or not there is an antivirus solution running on a Windows machine. When running on Windows 8 I'm getting false positives that antivirus is disabled when running a third-party antivirus solution due to Windows Defender always being around, although disabled.
I can see the productState for the third-party antivirus software as valid and reporting correctly, however my script is only pulling Windows Defender entries.
I need to keep the entries for Windows Defender, however I'm only interested in Windows Defender if there isn't any other antivirus software installed. I ran the following command from a command prompt to retrieve the data, which shows two separate entries.
WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get /Format:List
I would like to only grab the third-party antivirus software if it's installed, otherwise keep the Windows Defender information.
How I'm trying to do this is by calling the instanceGUID and compare it against the Windows Defender GUID, however I'm getting a few false positives. Is there a way for me to parse this data correctly and ideally only look at the third-party information?
I'm including the full script to show exactly what I'm looking at, and I can cut it down if needed:
Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colAVItems
strinstanceGuid = (objAntiVirusProduct.instanceGuid)
strWinDefGUID = "{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"
If strinstanceGuid <> strWinDefGUID Then
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "393472" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
End If
Else
If Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11" Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
End If
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
End If
Next
Just to reiterate, this is a Windows 8 issue.
I found a solution to my issue. Basically I ended up putting an If statement before my For statement looking at how many entries where in the Security Center WMI for AntiVirus. If there are 0 then it reports back none, If there is 1 installed then it reads the info, and if there are more than 1 it ignores Windows Defender and reads the rest. I'm including full code for future users.
Dim objWMIServiceSC,objAntiVirusProduct,colAVItems,AvStatus
Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
If colAVItems.count = 0 Then
strdisplayName = "No"
errors("Acceptable AntiVirus software found ") = "NO"
ElseIf colAVItems.count = 1 Then
For Each objAntiVirusProduct In colAVItems
strdisplayName = (objAntiVirusProduct.displayName)
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "266240" _
OR objAntiVirusProduct.ProductState = "331776" _
OR objAntiVirusProduct.ProductState = "397568" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
errors("Antivirus scanning is ") = "DISABLED"
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
errors("AntiVirus Definitions are ") = "OUTDATED"
End If
Next
ElseIf colAVItems.count > 1 Then
For Each objAntiVirusProduct In colAVItems
If (objAntiVirusProduct.displayName) <> "Windows Defender" Then
strdisplayName = (objAntiVirusProduct.displayName)
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "393472" _
OR objAntiVirusProduct.ProductState = "266240" _
OR objAntiVirusProduct.ProductState = "331776" _
OR objAntiVirusProduct.ProductState = "397568" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
errors("Antivirus scanning is ") = "DISABLED"
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
errors("AntiVirus Definitions are ") = "OUTDATED"
End If
End If
Next
End If
Doing all this string stuff looks a little complicated. You could also just do:
int bitmaskUpToDate = 0x000010;
bool upToDate = number & bitmaskUpToDate == bitmaskUpToDate;
int bitmaskEnabled = 0x001000;
bool isEnabled = number & bitmaskEnabled == bitmaskEnabled;
This is just a quick demo for the bitmask stuff. I did not doublecheck if I got the indices correct.