Skip to content

Commit

Permalink
feat: db/string commands (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Jan 10, 2025
1 parent ac90adf commit b5f5f64
Show file tree
Hide file tree
Showing 55 changed files with 1,772 additions and 263 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netease.nim.camellia.redis.base.resource;

import com.netease.nim.camellia.core.model.Resource;

/**
* Created by caojiajun on 2025/1/10
*/
public class RedisLocalStorageResource extends Resource {

private final String dir;

public RedisLocalStorageResource(String dir) {
this.dir = dir;
setUrl(RedisType.LocalStorage.getPrefix() + dir);
}

public String getDir() {
return dir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ public static Resource parseResourceByUrl(Resource resource) {
} else if (redisType == RedisType.RedisKV) {
String namespace = url.substring(redisType.getPrefix().length());
return new RedisKvResource(namespace);
} else if (redisType == RedisType.LocalStorage) {
String dir = url.substring(redisType.getPrefix().length());
return new RedisLocalStorageResource(dir);
}
throw new CamelliaRedisException("not redis resource");
} catch (CamelliaRedisException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public enum RedisType {
//仅camellia-redis-proxy支持
RedisKV("redis-kv://", false),

//格式:embedded-storage:/home/data
//格式:redis-local-storage:/home/data
//仅camellia-redis-proxy支持
EmbeddedStorage("embedded-storage:", false),
LocalStorage("redis-local-storage:", false),

;
private final String prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ camellia-redis-proxy:
local:
type: simple #simple、complex
resource: redis://@127.0.0.1:6379
# resource: redis-local-storage:/Users/caojiajun/temp/local_storage
# resource: redis-uds://@/Users/caojiajun/temp/redis.sock
# resource: rediss://@127.0.0.1:6379
# resource: redis-cluster://@10.189.31.13:6601,10.189.31.14:6603,10.189.31.15:6605
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum RedisCommand {
TIME(CommandSupportType.FULL_SUPPORT, Type.READ, CommandType.DB, Blocking.FALSE, CommandKeyType.None),
PROXY(CommandSupportType.FULL_SUPPORT, Type.WRITE, CommandType.DB, Blocking.FALSE, CommandKeyType.None),//for proxy self
KV(CommandSupportType.FULL_SUPPORT, Type.WRITE, CommandType.DB, Blocking.FALSE, CommandKeyType.SIMPLE_SINGLE),//for proxy self in kv
MEMFLUSH(CommandSupportType.FULL_SUPPORT, Type.WRITE, CommandType.DB, Blocking.FALSE, CommandKeyType.None),//for proxy self in local storage
SENTINEL(CommandSupportType.FULL_SUPPORT, Type.READ, CommandType.DB, Blocking.FALSE, CommandKeyType.None),
READONLY(CommandSupportType.FULL_SUPPORT, Type.READ, CommandType.DB, Blocking.FALSE, CommandKeyType.None),
AUTH(CommandSupportType.FULL_SUPPORT, Type.READ, CommandType.DB, Blocking.FALSE, CommandKeyType.None),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.netease.nim.camellia.redis.proxy.conf.Constants;
import com.netease.nim.camellia.redis.proxy.upstream.cluster.RedisClusterClient;
import com.netease.nim.camellia.redis.proxy.upstream.kv.RedisKvClient;
import com.netease.nim.camellia.redis.proxy.upstream.local.storage.RedisLocalStorageClient;
import com.netease.nim.camellia.redis.proxy.upstream.proxies.RedisProxiesClient;
import com.netease.nim.camellia.redis.proxy.upstream.proxies.RedisProxiesDiscoveryClient;
import com.netease.nim.camellia.redis.proxy.upstream.sentinel.RedisSentinelClient;
Expand Down Expand Up @@ -204,6 +205,16 @@ public IUpstreamClient get(RedisKvResource resource) {
return client;
}

public IUpstreamClient get(RedisLocalStorageResource resource) {
IUpstreamClient client = map.get(resource.getUrl());
if (client == null) {
client = new RedisLocalStorageClient(resource);
client.start();
map.put(resource.getUrl(), client);
}
return client;
}

@Override
public IUpstreamClient get(String url) {
IUpstreamClient client = map.get(url);
Expand Down Expand Up @@ -244,6 +255,8 @@ public IUpstreamClient get(String url) {
client = get((RedisUnixDomainSocketResource) resource);
} else if (resource instanceof RedisKvResource) {
client = get((RedisKvResource) resource);
} else if (resource instanceof RedisLocalStorageResource) {
client = get((RedisLocalStorageResource) resource);
} else {
throw new CamelliaRedisException("not support resource");
}
Expand Down

This file was deleted.

Loading

0 comments on commit b5f5f64

Please sign in to comment.