Skip to content

Commit e5a1c15

Browse files
authored
Disable pipelinening for key scanning and value getting (#7)
* feat: add no pipeline redis client * fix: don't use pipeline for key scanning and getting key values
1 parent 50b59f7 commit e5a1c15

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

src/components/databrowser/hooks/use-fetch-keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const FETCH_COUNTS = [100, 200, 400, 800]
1010
export type RedisKey = [string, DataType]
1111

1212
export const useFetchKeys = (search: SearchFilter) => {
13-
const { redis } = useDatabrowser()
13+
const { redisNoPipeline: redis } = useDatabrowser()
1414

1515
const cache = useRef<PaginationCache | undefined>()
1616
const lastKey = useRef<string | undefined>()

src/components/databrowser/hooks/use-fetch-list-items.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const LIST_DISPLAY_PAGE_SIZE = 50
77
export const FETCH_LIST_ITEMS_QUERY_KEY = "use-fetch-list-items"
88

99
export const useFetchListItems = ({ dataKey, type }: { dataKey: string; type: ListDataType }) => {
10-
const { redis } = useDatabrowser()
10+
const { redisNoPipeline: redis } = useDatabrowser()
1111

1212
const setQuery = useInfiniteQuery({
1313
enabled: type === "set",

src/components/databrowser/hooks/use-fetch-simple-key.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const FETCH_SIMPLE_KEY_QUERY_KEY = "fetch-simple-key"
88

99
/** Simple key standing for string or json */
1010
export const useFetchSimpleKey = (dataKey: string, type: DataType) => {
11-
const { redis } = useDatabrowser()
11+
const { redisNoPipeline: redis } = useDatabrowser()
1212
const { deleteKeyCache } = useDeleteKeyCache()
1313

1414
return useQuery({

src/lib/clients.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import { Redis } from "@upstash/redis"
44

55
import { toast } from "@/components/ui/use-toast"
66

7-
export const redisClient = (databrowser?: RedisCredentials) => {
8-
const token = databrowser?.token || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN
9-
const url = databrowser?.url || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_URL
7+
export const redisClient = ({
8+
credentials,
9+
pipelining,
10+
}: {
11+
credentials?: RedisCredentials
12+
pipelining: boolean
13+
}) => {
14+
const token = credentials?.token || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN
15+
const url = credentials?.url || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_URL
1016

1117
if (!url) {
1218
throw new Error("Redis URL is missing!")
@@ -18,7 +24,7 @@ export const redisClient = (databrowser?: RedisCredentials) => {
1824
const redis = new Redis({
1925
url,
2026
token,
21-
enableAutoPipelining: true,
27+
enableAutoPipelining: pipelining,
2228
automaticDeserialization: false,
2329
keepAlive: false,
2430
})

src/store.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type RedisCredentials = {
1212

1313
type DatabrowserContextProps = {
1414
redis: Redis
15+
redisNoPipeline: Redis
1516
store: ReturnType<typeof createDatabrowserStore>
1617
}
1718

@@ -25,14 +26,15 @@ export const DatabrowserProvider = ({
2526
children,
2627
redisCredentials,
2728
}: PropsWithChildren<DatabrowserProviderProps>) => {
28-
const redisInstance = useMemo(() => redisClient(redisCredentials), [redisCredentials])
29+
const redisInstance = useMemo(() => redisClient({credentials: redisCredentials, pipelining: true}), [redisCredentials])
30+
const redisInstanceNoPipeline = useMemo(() => redisClient({credentials: redisCredentials, pipelining: false}), [redisCredentials])
2931

3032
const [store] = useState(() => {
3133
return createDatabrowserStore()
3234
})
3335

3436
return (
35-
<DatabrowserContext.Provider value={{ redis: redisInstance, store }}>
37+
<DatabrowserContext.Provider value={{ redis: redisInstance, redisNoPipeline: redisInstanceNoPipeline, store }}>
3638
{children}
3739
</DatabrowserContext.Provider>
3840
)

0 commit comments

Comments
 (0)