Skip to content

Commit b34da4e

Browse files
author
longbingljw
authored
Revert "feat: Add support for OBKV-Redis (#3)"
This reverts commit 36db8b6.
1 parent 405ccf7 commit b34da4e

File tree

6 files changed

+2
-168
lines changed

6 files changed

+2
-168
lines changed

api/configs/middleware/cache/redis_config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,3 @@ class RedisConfig(BaseSettings):
9898
description="Enable client side cache in redis",
9999
default=False,
100100
)
101-
102-
REDIS_USE_OBKV: bool = Field(
103-
description="Use OBKV instead of Redis",
104-
default=False,
105-
)

api/extensions/ext_redis.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import logging
2-
from typing import Any, Optional, Union
1+
from typing import Any, Union
32

43
import redis
54
from redis.cache import CacheConfig
6-
from redis.client import Pipeline
75
from redis.cluster import ClusterNode, RedisCluster
86
from redis.connection import Connection, SSLConnection
9-
from redis.exceptions import LockNotOwnedError
10-
from redis.lock import Lock
117
from redis.sentinel import Sentinel
128

139
from configs import dify_config
@@ -112,22 +108,6 @@ def init_app(app: DifyApp):
112108
cache_config=clientside_cache_config,
113109
)
114110
)
115-
elif dify_config.REDIS_USE_OBKV:
116-
assert dify_config.REDIS_SERIALIZATION_PROTOCOL < 3, (
117-
"OBKV does not support RESP version 3. "
118-
"Please specify REDIS_SERIALIZATION_PROTOCOL=2 in the configuration file."
119-
)
120-
redis_params.update(
121-
{
122-
"host": dify_config.REDIS_HOST,
123-
"port": dify_config.REDIS_PORT,
124-
"username": dify_config.REDIS_USERNAME,
125-
"password": dify_config.REDIS_PASSWORD,
126-
"connection_class": connection_class,
127-
}
128-
)
129-
pool = redis.ConnectionPool(**redis_params)
130-
redis_client.initialize(OBKVClient(redis.Redis(connection_pool=pool)))
131111
else:
132112
redis_params.update(
133113
{
@@ -142,51 +122,3 @@ def init_app(app: DifyApp):
142122
redis_client.initialize(redis.Redis(connection_pool=pool))
143123

144124
app.extensions["redis"] = redis_client
145-
146-
147-
class OceanBaseRedisLock(Lock):
148-
def do_acquire(self, token: str) -> bool:
149-
try:
150-
result = self.redis.execute_command("SETNX", self.name, token)
151-
except Exception as e:
152-
logging.info(f"Failed to acquire redis lock {self.name}, error: {e}")
153-
result = False
154-
if result == 1:
155-
self.redis.execute_command("EXPIRE", self.name, 60)
156-
return True
157-
else:
158-
return False
159-
160-
def do_release(self, expected_token: str) -> None:
161-
current_value = self.redis.get(self.name)
162-
if current_value == expected_token:
163-
redis_client.delete(self.name)
164-
logging.info(f"Lock released: {self.name}")
165-
else:
166-
raise LockNotOwnedError(
167-
"Cannot release a lock that's no longer owned",
168-
lock_name=self.name,
169-
)
170-
171-
172-
class OceanBasePipeLine(Pipeline):
173-
def execute(self, raise_on_error=True):
174-
"""do nothing, OBKV cannot support redis pipeline"""
175-
logging.info("executing pipeline: do nothing, OBKV cannot support redis pipeline")
176-
177-
178-
class OBKVClient:
179-
def __init__(self, client: redis.Redis):
180-
self._client = client
181-
182-
def lock(self, name: str, timeout: Optional[int] = None, **kwargs):
183-
# Implementation using OceanBaseRedisLock
184-
return self._client.lock(name, timeout=timeout, lock_class=OceanBaseRedisLock, **kwargs)
185-
186-
def pipeline(self, transaction=True, shard_hint=None) -> "Pipeline":
187-
return OceanBasePipeLine(self.connection_pool, self.response_callbacks, transaction, shard_hint)
188-
189-
def __getattr__(self, item):
190-
if self._client is None:
191-
raise RuntimeError("Redis client is not initialized. Call init_app first.")
192-
return getattr(self._client, item)

docker/.env.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ REDIS_USE_CLUSTERS=false
271271
REDIS_CLUSTERS=
272272
REDIS_CLUSTERS_PASSWORD=
273273

274-
# Whether to use OBKV instead of Redis.
275-
REDIS_USE_OBKV=false
276-
277-
278274
# ------------------------------
279275
# Celery Configuration
280276
# ------------------------------

docker/docker-compose.middleware.yaml

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,6 @@ services:
4343
healthcheck:
4444
test: [ "CMD", "redis-cli", "ping" ]
4545

46-
47-
obkv_redis:
48-
image: oceanbase/oceanbase-ce:4.2.5.3-103000022025033117
49-
container_name: oceanbase
50-
restart: always
51-
environment:
52-
OB_MEMORY_LIMIT: ${OCEANBASE_MEMORY_LIMIT:-6G}
53-
OB_SYS_PASSWORD: ${OCEANBASE_VECTOR_PASSWORD:-difyai123456}
54-
OB_TENANT_PASSWORD: ${OCEANBASE_VECTOR_PASSWORD:-difyai123456}
55-
OB_CLUSTER_NAME: ${OCEANBASE_CLUSTER_NAME:-difyai}
56-
MODE: MINI
57-
volumes:
58-
- ./volumes/oceanbase/obkv_redis/healthcheck.sh:/root/healthcheck.sh
59-
ports:
60-
- "${OCEANBASE_VECTOR_PORT:-2881}:2881"
61-
healthcheck:
62-
test: [ "CMD", "/root/healthcheck.sh" ]
63-
interval: 10s
64-
retries: 30
65-
start_period: 30s
66-
timeout: 10s
67-
68-
obproxy:
69-
image: oceanbase/obproxy-ce:4.3.4.0-1
70-
container_name: obproxy
71-
environment:
72-
APP_NAME: dify_obproxy
73-
PROXYRO_PASSWORD: 123456
74-
RS_LIST: ${OCEANBASE_IP}:${OCEANBASE_VECTOR_PORT:-2881}
75-
OB_CLUSTER: ${OCEANBASE_CLUSTER_NAME:-difyai}
76-
ports:
77-
- "${OBPROXY_SQL_PORT:-2883}:2883"
78-
- "${OBPROXY_RPC_PORT:-2885}:2885"
79-
depends_on:
80-
obkv_redis:
81-
condition: service_healthy
82-
8346
# The DifySandbox
8447
sandbox:
8548
image: langgenius/dify-sandbox:0.2.12
@@ -108,7 +71,7 @@ services:
10871

10972
# plugin daemon
11073
plugin_daemon:
111-
image: quay.io/oceanbase-devhub/dify-plugin-daemon:obkv-redis-0.1-local
74+
image: langgenius/dify-plugin-daemon:0.0.10-local
11275
restart: always
11376
env_file:
11477
- ./middleware.env
@@ -157,9 +120,6 @@ services:
157120
- "${EXPOSE_PLUGIN_DEBUGGING_PORT:-5003}:${PLUGIN_DEBUGGING_PORT:-5003}"
158121
volumes:
159122
- ./volumes/plugin_daemon:/app/storage
160-
depends_on:
161-
obkv_redis:
162-
condition: service_healthy
163123

164124
# ssrf_proxy server
165125
# for more information, please refer to

docker/docker-compose.yaml

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ x-shared-env: &shared-api-worker-env
7474
REDIS_SENTINEL_PASSWORD: ${REDIS_SENTINEL_PASSWORD:-}
7575
REDIS_SENTINEL_SOCKET_TIMEOUT: ${REDIS_SENTINEL_SOCKET_TIMEOUT:-0.1}
7676
REDIS_USE_CLUSTERS: ${REDIS_USE_CLUSTERS:-false}
77-
REDIS_USE_OBKV: ${REDIS_USE_OBKV:-false}
7877
REDIS_CLUSTERS: ${REDIS_CLUSTERS:-}
7978
REDIS_CLUSTERS_PASSWORD: ${REDIS_CLUSTERS_PASSWORD:-}
8079
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://:difyai123456@redis:6379/1}
@@ -943,46 +942,6 @@ services:
943942
start_period: 30s
944943
timeout: 10s
945944

946-
obkv_redis:
947-
image: oceanbase/oceanbase-ce:4.2.5.3-103000022025033117
948-
container_name: oceanbase
949-
profiles:
950-
- oceanbase
951-
restart: always
952-
environment:
953-
OB_MEMORY_LIMIT: ${OCEANBASE_MEMORY_LIMIT:-6G}
954-
OB_SYS_PASSWORD: ${OCEANBASE_VECTOR_PASSWORD:-difyai123456}
955-
OB_TENANT_PASSWORD: ${OCEANBASE_VECTOR_PASSWORD:-difyai123456}
956-
OB_CLUSTER_NAME: ${OCEANBASE_CLUSTER_NAME:-difyai}
957-
MODE: MINI
958-
volumes:
959-
- ./volumes/oceanbase/obkv_redis/healthcheck.sh:/root/healthcheck.sh
960-
ports:
961-
- "${OCEANBASE_VECTOR_PORT:-2881}:2881"
962-
healthcheck:
963-
test: [ "CMD", "/root/healthcheck.sh" ]
964-
interval: 10s
965-
retries: 30
966-
start_period: 30s
967-
timeout: 10s
968-
969-
obproxy:
970-
image: oceanbase/obproxy-ce:4.3.4.0-1
971-
container_name: obproxy
972-
profiles:
973-
- oceanbase
974-
environment:
975-
APP_NAME: dify_obproxy
976-
PROXYRO_PASSWORD: 123456
977-
RS_LIST: ${OCEANBASE_IP}:${OCEANBASE_VECTOR_PORT:-2881}
978-
OB_CLUSTER: ${OCEANBASE_CLUSTER_NAME:-difyai}
979-
ports:
980-
- "${OBPROXY_SQL_PORT:-2883}:2883"
981-
- "${OBPROXY_RPC_PORT:-2885}:2885"
982-
depends_on:
983-
obkv_redis:
984-
condition: service_healthy
985-
986945
# Oracle vector database
987946
oracle:
988947
image: container-registry.oracle.com/database/free:latest

docker/volumes/oceanbase/obkv_redis/healthcheck.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)