I'm playing around with redis and wanted to recreate a table I have in mysql. Here's the mysql command I use to create it:
CREATE TABLE data_table(
key1 INT SIGNED NOT NULL,
value1 INT SIGNED NOT NULL,
PRIMARY KEY (key1,value1)
);
My data is basically two columns with numbers that are unique to each other, such as:
3:1
3:2
3:3
4:1
When I play around redis, and try to create the above data, the '3' key just keeps getting replaced by the last value I enter. Is there a way to make this work in redis?
A better model with Redis to represent your data would be to use simple sets of value1 objects (one per key1 object). Following the example, you can store in Redis:
with the following commands:
You can get all the values for key1=3 by using:
You can check if keys1=3,value1=2 exists by using:
Redis is not a relational database system, so you should not try to map a relational model with Redis. Instead, you need to think about how to structure and access your data like if you were using in-memory data structures from a programming language.