-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using local redis instead of centralized redis (#1979)
Earlier we were using local caffine cache and syncing the changes to centralized redis. Now we are using local redis only Assumption is now that we get all the data for particular user key on one machine. This will be handled by producer
- Loading branch information
Showing
5 changed files
with
72 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 0 additions & 126 deletions
126
...reat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisCounterCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.akto.threat.detection.cache; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
|
||
public class RedisCounterCache implements CounterCache { | ||
|
||
static class Op { | ||
private final String key; | ||
private final long value; | ||
|
||
public Op(String key, long value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public long getValue() { | ||
return value; | ||
} | ||
} | ||
|
||
private final StatefulRedisConnection<String, Long> redis; | ||
|
||
private final String prefix; | ||
|
||
public RedisCounterCache(RedisClient redisClient, String prefix) { | ||
this.prefix = prefix; | ||
this.redis = redisClient.connect(new LongValueCodec()); | ||
} | ||
|
||
private String addPrefixToKey(String key) { | ||
return new StringBuilder().append(prefix).append("|").append(key).toString(); | ||
} | ||
|
||
@Override | ||
public void increment(String key) { | ||
incrementBy(key, 1); | ||
} | ||
|
||
@Override | ||
public void incrementBy(String key, long val) { | ||
redis.async().incrby(addPrefixToKey(key), val); | ||
} | ||
|
||
@Override | ||
public long get(String key) { | ||
return redis.sync().get(addPrefixToKey(key)); | ||
} | ||
|
||
@Override | ||
public boolean exists(String key) { | ||
return redis.sync().exists(addPrefixToKey(key)) > 0; | ||
} | ||
|
||
@Override | ||
public void clear(String key) { | ||
redis.async().del(addPrefixToKey(key)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters