convert SQL data (with OR relationship) to redis data structure - redis

The data in SQL DB is:
We want to store this data in redis. But, the application will have "keys" and "values" data, and it want to fetch the corresponding "Id" from redis.
The "values" against any "key" are in OR relationship, but there is AND relationship between keys for any "Id" .
So, the application query to redis will be based on keys and values, and it wants to get the Id.
e.g. query from app : (K1 == V0 OR K1 == V1) AND (K2 == V2) ; then return c1 .
But, same key can be used by other Id .
e.g. (K1 == V2 OR K1 == V8) AND (K5 == V7) AND (K6 == V9 OR K1 == V8) ; should return c2 .
How do we store such data in Redis, to support these operations (without exponential growth)?

Related

MVC update the database based on a non primary key value

I have a database table that looks like this:
My goal is to update my "unavail" table based on the ID of either the component, part, or item depending on which one is relevant in my situation.
For example, if the partID = 43 I want to add to the 'unavail' column
I first started working on this by trying this
db.OffSiteItemDetails.Find(sod.PartID).unavail += sod.comp_returned;
(Where sod.PartId = 43)
But I quickly realized it was just checking for where the "ID" was equal to 43 which isn't what I want. After some investigation I saw people suggesting using
db.Where(x => x.non-pk == value)
So I created this
db.OffSiteItemDetails.Where(x => x.componentID == sod.ComponentID);
But from here I don't know how to change my unavail table values.
This was a tough question to type so if you need more clarity just ask
foreach(var item in db.OffSiteItemDetails.Where(x => x.componentID == sod.ComponentID))
{
// item.unavail = [new value]
// db.Update(item);
// ...I don't know how you update the data in your database
}
Something like that?

How to flatten Fuzz ( Fuzz ( Fuzz A))) without having andThen in the fuzz test module?

I have "a parent" A type which contains "a child" B type.
This is a simplified version of the main data structures i have in my app.
A and B and A_id and B_id are all separate elm modules.
If i can make this simplification work, then maybe is easier to solve my actual problem.
Basically my problem is how to create a fuzzer for A.
with the condition that both A_id and B_id .. need to share the same A_id.
type A
= A { id : A_id
, b : B -- A contains B.
}
type A_id
= A_id String
type B
= B { id : B_id } -- B contains B_id
type B_id
= B_id ( A_id, String ) -- B_id contains A_id. The exact same A_id as its parent A
a_idFuzzer : Fuzzer A_id
a_idFuzzer =
Fuzz.string
|> Fuzz.map A_id
aFuzzer : Fuzzer A
aFuzzer =
a_idFuzzer
|> Fuzz.map
(\a_id ->
bFuzzer a_id
|> Fuzz.map
(\b ->
-- here i just need the b,
-- but in reality i need more children
-- for assembling the A data structure.
-- i need a C and D with a cFuzzer and a dFuzzer...
-- and both C and D depend on having the same A_id value.
-- like B does.
A
{ id = a_id
, b = b
}
)
)
-- im passing A_id as an argument since is generated only once on the parent ( A )
-- and is shared with this B child.
bFuzzer : A_id -> Fuzzer B
bFuzzer a_id =
Fuzz.string
|> Fuzz.map (\s -> B_id ( a_id, s ))
|> Fuzz.map (\id -> B { id = id })
So how to create this Fuzzer A?
For the code above i get the Fuzzer (Fuzzer A) error as opposed to Fuzzer A.
In my actual app i get the more complicated error:
Fuzzer ( Fuzzer ( Fuzzer ( Fuzzer Exchange ))) vs Fuzzer Exchange.
I basically need to flatten it with andThen - but no such function exists in the fuzz elm test package - for some not so obvious reason.
What i tried:
I'm battling this problem for 3 days - somebody in slack suggested that andthen was removed on purpose and i'm supposed to use the custom fuzzer - i learned deeper how shrinkers work (i didn't knew them before) and how to use Fuzz.custom just to test if they are right.
Fuzz.custom needs a generator and a shrinker.
I can build the generator and generate everything i need, but i can't build shrinkers - since the B and A and C and D.. so on are all opaque data structures - in their own module - so i need to get all their properties with getters - in order to shrink them.
So for the example above - to shrink B i need to extract the b_id and run it trough a shrinker.. and then put that back into B by creating a new B - using the public api for B.. and I don't have public getter api for all the properties I keep on B, C , D etc.. and it just seems wrong to do it this way ( to add getters that i don't need in the app - just for testing purposes.. )
All this mess because andThen on the fuzz module was removed... but maybe there is a way, maybe they were right - and i'm not seeing the solution.
Link to the fuzzer module: here
So how to build a fuzzer for A datatype?
Any ideas how to deal with this nested fuzzers? How to flatten them back to one level?
Or to phrase it differently, How to build fuzzes that depend on each other like above? (an example i have on my mind would be - like running an http request that depends on another http request completing before it can start - since it needs the data form the previous request .. this model is seen thought functional programming and is usually done with andThen or bind or stuff.)
Any insight is appreciated. Thanks :)
I can build the generator and generate everything i need, but i can't build shrinkers
Then don't bother. Pass Shrink.noShrink to Fuzz.custom. The only disadvantage will come when you have a test that fails, and you will be given several large values of type A rather than (ideally) one small one.
As you work with your complex type, you'll get a better sense for how to shrink its values that cause test failures into "smaller" values that still cause test failures. For that matter, you'll get better at generating "interesting" values that find test failures.
In the next major release of elm-test (timeline not set), there will considerable improvements to Shrinkers, including better docs, the removal of lazy lists in favor of regular Elm lists, and renaming to "Simplifier".

Cypher Query does not work

I represent SMS text messages sent by persons. In order to simplify the problem I have only 2 nodes (one Person, one Phone) and 3 relationship (the person has a phone and sent to himself two text messages). The graph was created as follows:
try ( Transaction tx = graphDb.beginTx() )
{
Node aNode1 = graphDb.createNode();
aNode1.addLabel(DynamicLabel.label("Person"));
aNode1.setProperty("Name", "Juana");
tx.success();
Node aNode2 = graphDb.createNode();
aNode2.addLabel(DynamicLabel.label("Phone"));
aNode2.setProperty("Number", "1111-1111");
tx.success();
// (:Person) -[:has]->(:Phone)
aNode1.createRelationshipTo(aNode2, RelationshipType.withName("has"));
tx.success();
// finally SMS text sent at different moments
// (:Phone) -[:sms]-> (:Phone)
Relationship rel1 = aNode2.createRelationshipTo(aNode2, RelationshipType.withName("sms"));
rel1.setProperty("Length", 100);
tx.success();
Relationship rel2 = aNode2.createRelationshipTo(aNode2, RelationshipType.withName("sms"));
rel2.setProperty("Length", 50);
tx.success();
}
When I execute the following Cypher query:
MATCH (p1 :Person)-[:has]-> (n1 :Phone) -[r :sms]-(n2: Phone)<-[:has]-(p2 :Person)
RETURN p1, p2
I obtain zero tuples. I do not understand the resultset because I have to sms text between p1 and p2 (in this case the same person).
Surprisingly, if I eliminates the node p2 in the query:
MATCH (p1 :Person)-[:has]-> (n1 :Phone) -[r :sms]-(n2: Phone)
RETURN p1
I obtain Juana, as expected.
I can not understand the resultset (zero tuples) of my first query.
Cypher will only traverse a particular relationship once when trying to traverse a path, to avoid infinite loops. You already traverse the (p1:Person) - [:HAS] - > (n1:Phone) relationship once in your query, so you can't get back to Juana from her phone. This doesn't apply to nodes, however, which is why you can get her phone twice from the looped [:sms] relationship.

Getting null Records while reading multiple records in Aerospike

I have a namespace: test and set: user in Aerospike database. I add four records in users through the following command on console:
ascli put test users barberakey '{"username":"Barbera","password":"barbera","gender":"f","region":"west","company":"Audi"}'
Through aql command, I can view these four records.
aql> select * from test.users.
I know the method to get records one by one and it runs fine at my side, but it is very expensive operation for my task.I want to read multiple records(batch read) and to perform multiple algorithms on them. I took guidance from https://www.aerospike.com/docs/client/java/usage/kvs/batch.html and write code as followed:
Key[] keys = new Key[4];
for (int i = 0; i < 4; i++) {
keys[i] = new Key("test", "users", (i + 1));
System.out.println("Keys: "+keys[i]);
}
Record[] records = client.get(batchPolicy, keys);
System.out.println("Length of Records : "+records.length);
for(int a=0;a<records.length;a++){
System.out.println("RECORDS IN ARRAY: "+records[a]);
}
But, the problem is that it reads keys but giving Array records null.
Output:
Reading records from Aerospike DB
Keys: test:users:1:3921e84015258aed3b93d7ef5770cd27b9bb4167
Keys: test:users:2:1effb3ce25b23f92c5371dee0ac8e6b34f5703c6
Keys: test:users:3:d17519d72e22beab2c3fa1552910ea3380c262bd
Keys: test:users:4:3f09a505c913db8ad1118e20b78c5bb8495fb0f9
Length of Records : 4
RECORDS IN ARRAY: null
RECORDS IN ARRAY: null
RECORDS IN ARRAY: null
RECORDS IN ARRAY: null
Please guide me for the case.
......
Appears you wrote the records using the key "barberakey". Then read the records by an integer key "i+1". Thus, the records are not found.

ways to select values by keys list?

For example I have key structure entity:product:[id] where id - is an integer [0-n]
So I can use this keys entity:product:* but I don't how much load does this query to the redis server.
Another solution is
Create one list key that will store Ids of the entity:products.
RPUSH entity:products:ids 1
RPUSH entity:products:ids 2
RPUSH entity:products:ids 3
RPUSH entity:products:ids 4
And then (pseudo-code)
entityProducts = redis.LRANGE('entityLproducts:ids, 0, -1)
foreach (entityProducts as id)
{
redis.GET('entity:product:' + id)
}
What is the better way? What will be faster and what will do less load to the redis server?