Skip to content

Disable pipelinening for key scanning and value getting #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/databrowser/hooks/use-fetch-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const FETCH_COUNTS = [100, 200, 400, 800]
export type RedisKey = [string, DataType]

export const useFetchKeys = (search: SearchFilter) => {
const { redis } = useDatabrowser()
const { redisNoPipeline: redis } = useDatabrowser()

const cache = useRef<PaginationCache | undefined>()
const lastKey = useRef<string | undefined>()
Expand Down
2 changes: 1 addition & 1 deletion src/components/databrowser/hooks/use-fetch-list-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const LIST_DISPLAY_PAGE_SIZE = 50
export const FETCH_LIST_ITEMS_QUERY_KEY = "use-fetch-list-items"

export const useFetchListItems = ({ dataKey, type }: { dataKey: string; type: ListDataType }) => {
const { redis } = useDatabrowser()
const { redisNoPipeline: redis } = useDatabrowser()

const setQuery = useInfiniteQuery({
enabled: type === "set",
Expand Down
2 changes: 1 addition & 1 deletion src/components/databrowser/hooks/use-fetch-simple-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const FETCH_SIMPLE_KEY_QUERY_KEY = "fetch-simple-key"

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

return useQuery({
Expand Down
14 changes: 10 additions & 4 deletions src/lib/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { Redis } from "@upstash/redis"

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

export const redisClient = (databrowser?: RedisCredentials) => {
const token = databrowser?.token || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN
const url = databrowser?.url || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_URL
export const redisClient = ({
credentials,
pipelining,
}: {
credentials?: RedisCredentials
pipelining: boolean
}) => {
const token = credentials?.token || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN
const url = credentials?.url || process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_URL

if (!url) {
throw new Error("Redis URL is missing!")
Expand All @@ -18,7 +24,7 @@ export const redisClient = (databrowser?: RedisCredentials) => {
const redis = new Redis({
url,
token,
enableAutoPipelining: true,
enableAutoPipelining: pipelining,
automaticDeserialization: false,
keepAlive: false,
})
Expand Down
6 changes: 4 additions & 2 deletions src/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type RedisCredentials = {

type DatabrowserContextProps = {
redis: Redis
redisNoPipeline: Redis
store: ReturnType<typeof createDatabrowserStore>
}

Expand All @@ -25,14 +26,15 @@ export const DatabrowserProvider = ({
children,
redisCredentials,
}: PropsWithChildren<DatabrowserProviderProps>) => {
const redisInstance = useMemo(() => redisClient(redisCredentials), [redisCredentials])
const redisInstance = useMemo(() => redisClient({credentials: redisCredentials, pipelining: true}), [redisCredentials])
const redisInstanceNoPipeline = useMemo(() => redisClient({credentials: redisCredentials, pipelining: false}), [redisCredentials])

const [store] = useState(() => {
return createDatabrowserStore()
})

return (
<DatabrowserContext.Provider value={{ redis: redisInstance, store }}>
<DatabrowserContext.Provider value={{ redis: redisInstance, redisNoPipeline: redisInstanceNoPipeline, store }}>
{children}
</DatabrowserContext.Provider>
)
Expand Down