redis store map within map as value - redis

The map I want to store in Redis is
KEY -> KEY1(string) VALUE1(string)
KEY2(string) VALUE2(map)
In an operation with this structure, I want to add key/value to VALUE2 without first retrieving VALUE2. Is it possible ?

Related

Get keys under specific datatype in Redis

I am new to Redis. Can I get somehow (or using a command)the keys under each data structure?
For example:
KEYS TYPE STRING
keystr1
keystr2
KEYS TYPE SET
keySet1
keySet2

How can I get data from Redis in C#?

I have a problem with getting data from Redis. I want to get the object using not Id column. Can I do this in Redis? Or another case when I want to get the object using Id column, but I want to have my name of this column, not just 'Id', but I have the problem with this too.
Redis is primarily a Name/Value store.
You can set the NAME to anything you want. If you want to call it 'Id' you can. If you want to call it 'x-y-z' you can too and store the VALUE along with it.
Redis also supports Hashes. If you want to get an object "using not Id column" you can store similar object types in a Hash and retrieve the entire HashSet then find the object inside the list on the client side. This is not efficient if storing large objects or if you have many objects in a list.
Ex:
HMSET user:1000 username antirez password P1pp0 age 34
HGETALL user:1000
HSET user:1000 password 12345
HGETALL user:1000
Here is a list of datatypes Redis Supports.
https://redis.io/topics/data-types
The 2 popular libraries for using C# and Redis are:
https://github.com/ServiceStack/ServiceStack.Redis
https://github.com/StackExchange/StackExchange.Redis

how to get the list of redis cache keys in sorted order by creation time

I have the n number of keys in my redis server with some data. Now i want to check what all keys got created in last two months. How to check this. Is there any way to sort all cache keys in redis-cli by creation time or anything?
Redis doesn't store this information. You need to do this explicitly. There are many ways you can achieve this. Some of them are:
SET time or date or datetime string when setting key
ex:
SET key1 data
SET key1:date "12-JULY-2018"
Make data Object type - Add an explicit key of created at and then store it to Redis. Then sort it in your own application.
Create Sets/Lists of each hour/day/month and keep pushing all the keys to those lists. You can then retrieve keys for each hour/day/month. Now get data using these keys.
ex:
SET key1 data // At this point date is "12-JULY-2018"
SADD "JULY-SET" key1
Now you can get all keys of JULY by doing this:
SMEMBERS "JULY-SET"

How to add filter to match the value in a map bin Aerospike

I have a requirement where I have to find the record in an aerospike based on attributeId. The data in aerospike is inthe below format
{
name=ABC,
id=xyz,
ts=1445879080423,
inference={2601=0.6}
}
Now I will be getting the value "2601" programatically and I should find this record based on this value. But the problem is the value is in a Map and the size of this map may be more than 1 like
inference={{2601=0.6},{2830=0.9},{2931=0.8}}
So how can I find this record using attributeId in java. Any suggestions much appreciated
A little know feature of Aerospike is that, in addition to a Bin, you can define an index on:
List values
Map Keys
Map Values
Using in index defined on your map keys in the "inference" bin, you will be able to query (filter) base on the key's name.
I hope this helps

How to add a list of string in Redis?

I want to store a set of strings against a key in a Redis in a single step. Presently, I am using multi-exec mechanism for storing by iterating over the set.
I am using spring-data-redis library for Redis operation.
Is it possible to store a set of strings in a Redis in a single step ?
Yes, the RPUSH/LPUSH commands accept multiple values, beginning with Redis 2.4. Example:
LPUSH key value1 value2 value3
If you're using a set rather than a list, it's the SADD command:
SADD key value1 value2 value3
In Spring Data Redis, StringRedisConnection supports multiple values in the rPush, lPush, and sAdd methods.
Do you want to store a list or a set? (You refer to both.)
In general you can store your list of strings as a single JSON string.
With Spring data API for Redis , you can set a list or object using
eg:-
opsForList.leftPush("key", object);